r358877 - [analyzer][www] Moving MoveChecker out of alpha is no longer an open project.

2019-04-22 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Mon Apr 22 02:20:23 2019
New Revision: 358877

URL: http://llvm.org/viewvc/llvm-project?rev=358877&view=rev
Log:
[analyzer][www] Moving MoveChecker out of alpha is no longer an open project.

Modified:
cfe/trunk/www/analyzer/open_projects.html

Modified: cfe/trunk/www/analyzer/open_projects.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/www/analyzer/open_projects.html?rev=358877&r1=358876&r2=358877&view=diff
==
--- cfe/trunk/www/analyzer/open_projects.html (original)
+++ cfe/trunk/www/analyzer/open_projects.html Mon Apr 22 02:20:23 2019
@@ -48,16 +48,6 @@ mailing list to notify other members
   (Difficulty: Medium)
   
 
-  alpha.cplusplus.MisusedMovedObject
-The checker emits a warning on objects which were used after
-https://en.cppreference.com/w/cpp/utility/move";>move.
-Currently it has an overly high false positive rate due to classes
-which have a well-defined semantics for use-after-move.
-This property does not hold for STL objects, but is often the case
-for custom containers.
-  (Difficulty: Medium)
-  
-
   alpha.unix.StreamChecker
 A SimpleStreamChecker has been presented in the Building a Checker 
in 24 
 Hours talk 


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


r358881 - [Sema][NFC] Add more tests for the behavior of argument-dependent name lookup

2019-04-22 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Mon Apr 22 04:40:31 2019
New Revision: 358881

URL: http://llvm.org/viewvc/llvm-project?rev=358881&view=rev
Log:
[Sema][NFC] Add more tests for the behavior of argument-dependent name lookup

The goal here is to exercise each rule in [basic.lookup.argdep] at least once.
These new tests expose what I believe are 2 issues:

1. CWG 1691 needs to be implemented (p2:  [...] Its associated namespaces are
   the innermost enclosing namespaces of its associated classes [...]) The
   corresponding tests are adl_class_type::X2 and adl_class_type::X5.

2. The end of paragraph 2 ([...] Additionally, if the aforementioned set of
   overloaded functions is named with a template-id, its associated classes
   and namespaces also include those of its type template-arguments and its
   template template-arguments.) is not implemented. Closely related, the
   restriction on non-dependent parameter types in this same paragraph needs
   to be removed. The corresponding tests are in adl_overload_set (both issues
   are from CWG 997).

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

Reviewed By: riccibruno, Quuxplusone


Added:

cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-associated-namespaces-classes.cpp

cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-inline-namespace.cpp
Modified:
cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp
cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p3.cpp
cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p4.cpp

Added: 
cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-associated-namespaces-classes.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-associated-namespaces-classes.cpp?rev=358881&view=auto
==
--- 
cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-associated-namespaces-classes.cpp
 (added)
+++ 
cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-associated-namespaces-classes.cpp
 Mon Apr 22 04:40:31 2019
@@ -0,0 +1,336 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+// Attempt to test each rule for forming associated namespaces
+// and classes as described in [basic.lookup.argdep]p2.
+
+// fundamental type: no associated namespace and no associated class
+namespace adl_fundamental_type {
+  constexpr int g(char) { return 1; } // #1
+  template  constexpr int foo(T t) { return g(t); }
+  constexpr int g(int) { return 2; } // #2 not found
+  void test() {
+static_assert(foo(0) == 1); // ok, #1
+  }
+}
+
+// class type:
+//   associated classes: itself, the class of which it is a member (if any),
+//   direct and indirect base classes
+//   associated namespaces: innermost enclosing namespaces of associated 
classes
+namespace adl_class_type {
+  // associated class: itself, simple case
+  namespace X1 {
+namespace N {
+  struct S {};
+  void f(S); // found
+}
+void g(N::S); // not found
+  };
+  void test1() {
+f(X1::N::S{}); // ok
+g(X1::N::S{}); // expected-error {{use of undeclared identifier}}
+  }
+
+  // associated class: itself, local type
+  namespace X2 {
+auto foo() {
+  struct S {} s;
+  return s;
+}
+using S = decltype(foo());
+void f(S); // expected-note {{'X2::f' declared here}}
+  }
+  void test2() {
+f(X2::S{}); // FIXME: This is well-formed; X2 is the innermost enclosing 
namespace
+// of the local struct S.
+// expected-error@-2 {{use of undeclared identifier 'f'}}
+  }
+
+  // associated class: the parent class
+  namespace X3 {
+struct S {
+  struct T {};
+  friend void f(T);
+};
+  }
+  void test3() {
+f(X3::S::T{}); // ok
+  }
+
+  // associated class: direct and indirect base classes
+  namespace X4 {
+namespace IndirectBaseNamespace {
+  struct IndirectBase {};
+  void f(IndirectBase); // #1
+}
+namespace DirectBaseNamespace {
+  struct DirectBase : IndirectBaseNamespace::IndirectBase {};
+  void g(DirectBase); // #2
+}
+struct S : DirectBaseNamespace::DirectBase {};
+  }
+  void test4() {
+f(X4::S{}); // ok, #1
+g(X4::S{}); // ok, #2
+  }
+
+  // associated class: itself, lambda
+  namespace X5 {
+namespace N {
+  auto get_lambda() { return [](){}; }
+  void f(decltype(get_lambda()));
+}
+
+void test5() {
+  auto lambda = N::get_lambda();
+  f(lambda); // FIXME: This is well-formed. expected-error {{use of 
undeclared}}
+}
+  }
+
+  // The parameter types and return type of a lambda's operator() do not
+  // contribute to the associated namespaces and classes of the lambda itself.
+  namespace X6 {
+namespace N {
+  struct A {};
+  template constexpr int f(T) { return 1; }
+}
+
+constexpr int f(N::A (*)()) { return 2; }
+constexpr int f(void (*)(N:

[PATCH] D60570: [Sema] Add more tests for the behavior of argument-dependent name lookup

2019-04-22 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL358881: [Sema][NFC] Add more tests for the behavior of 
argument-dependent name lookup (authored by brunoricci, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D60570?vs=195076&id=196049#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D60570

Files:
  
cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-associated-namespaces-classes.cpp
  
cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-inline-namespace.cpp
  cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp
  cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p3.cpp
  cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p4.cpp

Index: cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-inline-namespace.cpp
===
--- cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-inline-namespace.cpp
+++ cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-inline-namespace.cpp
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+// C++11 [basic.lookup.argdep]p2
+//
+// [...] If an associated namespace is an inline namespace (10.3.1), its
+// enclosing namespace is also included in the set. If an associated
+// namespace directly contains inline namespaces, those inline namespaces
+// are also included in the set.
+
+namespace test1 {
+  namespace L {
+namespace M {
+  inline namespace N {
+inline namespace O {
+  struct S {};
+  void f1(S);
+}
+void f2(S);
+  }
+  void f3(S);
+}
+void f4(M::S); // expected-note {{declared here}}
+  }
+
+  void test() {
+L::M::S s;
+f1(s); // ok
+f2(s); // ok
+f3(s); // ok
+f4(s); // expected-error {{use of undeclared}}
+  }
+}
+
+namespace test2 {
+  namespace L {
+struct S {};
+inline namespace M {
+  inline namespace N {
+inline namespace O {
+  void f1(S);
+}
+void f2(S);
+  }
+  void f3(S);
+}
+void f4(S);
+  }
+
+  void test() {
+L::S s;
+f1(s); // ok
+f2(s); // ok
+f3(s); // ok
+f4(s); // ok
+  }
+}
Index: cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-associated-namespaces-classes.cpp
===
--- cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-associated-namespaces-classes.cpp
+++ cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-associated-namespaces-classes.cpp
@@ -0,0 +1,336 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+// Attempt to test each rule for forming associated namespaces
+// and classes as described in [basic.lookup.argdep]p2.
+
+// fundamental type: no associated namespace and no associated class
+namespace adl_fundamental_type {
+  constexpr int g(char) { return 1; } // #1
+  template  constexpr int foo(T t) { return g(t); }
+  constexpr int g(int) { return 2; } // #2 not found
+  void test() {
+static_assert(foo(0) == 1); // ok, #1
+  }
+}
+
+// class type:
+//   associated classes: itself, the class of which it is a member (if any),
+//   direct and indirect base classes
+//   associated namespaces: innermost enclosing namespaces of associated classes
+namespace adl_class_type {
+  // associated class: itself, simple case
+  namespace X1 {
+namespace N {
+  struct S {};
+  void f(S); // found
+}
+void g(N::S); // not found
+  };
+  void test1() {
+f(X1::N::S{}); // ok
+g(X1::N::S{}); // expected-error {{use of undeclared identifier}}
+  }
+
+  // associated class: itself, local type
+  namespace X2 {
+auto foo() {
+  struct S {} s;
+  return s;
+}
+using S = decltype(foo());
+void f(S); // expected-note {{'X2::f' declared here}}
+  }
+  void test2() {
+f(X2::S{}); // FIXME: This is well-formed; X2 is the innermost enclosing namespace
+// of the local struct S.
+// expected-error@-2 {{use of undeclared identifier 'f'}}
+  }
+
+  // associated class: the parent class
+  namespace X3 {
+struct S {
+  struct T {};
+  friend void f(T);
+};
+  }
+  void test3() {
+f(X3::S::T{}); // ok
+  }
+
+  // associated class: direct and indirect base classes
+  namespace X4 {
+namespace IndirectBaseNamespace {
+  struct IndirectBase {};
+  void f(IndirectBase); // #1
+}
+namespace DirectBaseNamespace {
+  struct DirectBase : IndirectBaseNamespace::IndirectBase {};
+  void g(DirectBase); // #2
+}
+struct S : DirectBaseNamespace::DirectBase {};
+  }
+  void test4() {
+f(X4::S{}); // ok, #1
+g(X4::S{}); // ok, #2
+  }
+
+  // associated class: itself, lambda
+  namespace X5 {

[PATCH] D58033: Add option for emitting dbg info for call site parameters

2019-04-22 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro updated this revision to Diff 196053.
djtodoro added a comment.

-Add only cc1 option
-Set up back end


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

https://reviews.llvm.org/D58033

Files:
  include/clang/Basic/CodeGenOptions.def
  include/clang/Driver/CC1Options.td
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp


Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -746,6 +746,7 @@
 
   Opts.DisableLLVMPasses = Args.hasArg(OPT_disable_llvm_passes);
   Opts.DisableLifetimeMarkers = Args.hasArg(OPT_disable_lifetimemarkers);
+  Opts.EnableParamEntryValues = Args.hasArg(OPT_femit_param_entry_values);
   Opts.DisableO0ImplyOptNone = Args.hasArg(OPT_disable_O0_optnone);
   Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone);
   Opts.IndirectTlsSegRefs = Args.hasArg(OPT_mno_tls_direct_seg_refs);
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3396,6 +3396,10 @@
   if (DebuggerTuning == llvm::DebuggerKind::SCE)
 CmdArgs.push_back("-dwarf-explicit-import");
 
+  // Enable param entry values functionality.
+  if (Args.hasArg(options::OPT_femit_param_entry_values))
+CmdArgs.push_back("-femit-param-entry-values");
+
   RenderDebugInfoCompressionArgs(Args, CmdArgs, D, TC);
 }
 
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -4558,7 +4558,10 @@
   // were part of DWARF v4.
   bool SupportsDWARFv4Ext =
   CGM.getCodeGenOpts().DwarfVersion == 4 &&
-  CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB;
+  (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB ||
+   (CGM.getCodeGenOpts().EnableParamEntryValues &&
+   CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::GDB));
+
   if (!SupportsDWARFv4Ext && CGM.getCodeGenOpts().DwarfVersion < 5)
 return llvm::DINode::FlagZero;
 
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -463,6 +463,7 @@
   Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning();
   Options.EmitStackSizeSection = CodeGenOpts.StackSizeSection;
   Options.EmitAddrsig = CodeGenOpts.Addrsig;
+  Options.EnableParamEntryValues = CodeGenOpts.EnableParamEntryValues;
 
   if (CodeGenOpts.getSplitDwarfMode() != CodeGenOptions::NoFission)
 Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;
Index: include/clang/Driver/CC1Options.td
===
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -364,6 +364,8 @@
 def fno_lto_unit: Flag<["-"], "fno-lto-unit">;
 def fthin_link_bitcode_EQ : Joined<["-"], "fthin-link-bitcode=">,
 HelpText<"Write minimized bitcode to  for the ThinLTO thin link 
only">;
+def femit_param_entry_values : Flag<["-"], "femit-param-entry-values">,
+HelpText<"Enables debug info about call site parameter's entry values">;
 def fdebug_pass_manager : Flag<["-"], "fdebug-pass-manager">,
 HelpText<"Prints debug information for the new pass manager">;
 def fno_debug_pass_manager : Flag<["-"], "fno-debug-pass-manager">,
Index: include/clang/Basic/CodeGenOptions.def
===
--- include/clang/Basic/CodeGenOptions.def
+++ include/clang/Basic/CodeGenOptions.def
@@ -61,6 +61,7 @@
 CODEGENOPT(DebugPassManager, 1, 0) ///< Prints debug information for the new
///< pass manager.
 CODEGENOPT(DisableRedZone, 1, 0) ///< Set when -mno-red-zone is enabled.
+CODEGENOPT(EnableParamEntryValues, 1, 0) ///< Emit call site parameter dbg info
 CODEGENOPT(IndirectTlsSegRefs, 1, 0) ///< Set when -mno-tls-direct-seg-refs
  ///< is specified.
 CODEGENOPT(DisableTailCalls  , 1, 0) ///< Do not emit tail calls.


Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -746,6 +746,7 @@
 
   Opts.DisableLLVMPasses = Args.hasArg(OPT_disable_llvm_passes);
   Opts.DisableLifetimeMarkers = Args.hasArg(OPT_disable_lifetimemarkers);
+  Opts.EnableParamEntryValues = Args.hasArg(OPT_femit_param_entry_values);
   Opts.DisableO0ImplyOptNone = Args.hasArg(OPT_disable_O0_optnone);
   Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone);
   Opts.IndirectTlsSegRefs = Args.hasArg(OPT_mno_tls_direct_seg_refs);
Index: lib/Driver/ToolChains/Clang.cpp
=

[PATCH] D60943: Delay diagnosing "n" constraint until after inlining

2019-04-22 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

I'm in the process of testing this, but feedback will take a bit.

On the more meaty parts of this change, I think further iterations will be 
necessary in-tree to extend this to the other constraints.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60943



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


[PATCH] D60956: [Sema] Fix the lookup for a declaration conflicting with an enumerator (bogus use of LookupResult::getAsSingle)

2019-04-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: lib/Sema/SemaDecl.cpp:16607
+  // Check for other kinds of shadowing not already handled.
+  if (PrevDecl && isa(PrevDecl->getUnderlyingDecl()) &&
+  !TheEnumDecl->isScoped())

Is the change to `PrevDecl->getUnderlyingDecl()` intended here?


Repository:
  rC Clang

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

https://reviews.llvm.org/D60956



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


[PATCH] D60408: [LibTooling] Extend Transformer to support multiple simultaneous changes.

2019-04-22 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

In D60408#1473370 , @liutianle wrote:

> hi ymandel,
>  When I run "check-all", there are some warning/error in TransformerTest.cpp 
> as follow. My version is llvm:0ee120077 and clang:d87ee8e678. Could you 
> please have a fix or guild me how to fix it?
>
>  
> ---
>
> In file included from 
> myLLVM/llvm/utils/unittest/googlemock/include/gmock/internal/gmock-internal-utils.h:47:0,
>
>   from myLLVM/llvm/utils/unittest/googlemock/include/gmock/gmock-actions.h:46,
>   from myLLVM/llvm/utils/unittest/googlemock/include/gmock/gmock.h:58,
>   from myLLVM/llvm/tools/clang/unittests/Tooling/TransformerTest.cpp:13:
>
> myLLVM/llvm/utils/unittest/googletest/include/gtest/gtest.h: In instantiation 
> of 'testing::AssertionResult testing::internal::CmpHelperEQ(const char*, 
> const char*, const T1&, const T2&) [with T1 = long unsigned int; T2 = int]':
>  myLLVM/llvm/utils/unittest/googletest/include/gtest/gtest.h:1421:23:   
> required from 'static testing::AssertionResult 
> testing::internal::EqHelper::Compare(const char*, const 
> char*, const T1&, const T2&) [with T1 = long unsigned int; T2 = int; bool 
> lhs_is_null_literal = false]'
>  myLLVM/llvm/tools/clang/unittests/Tooling/TransformerTest.cpp:372:3:   
> required from here
>  myLLVM/llvm/utils/unittest/googletest/include/gtest/gtest.h:1392:11: 
> warning: comparison between signed and unsigned integer expressions 
> [-Wsign-compare]
>
>   if (lhs == rhs) {
>   ^
>
>  
> --


Sorry about that. Have you sync'd to head? I thought that was fixed with 
r358745 (from Bjorn Pettersson).


Repository:
  rL LLVM

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

https://reviews.llvm.org/D60408



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


[PATCH] D60956: [Sema] Fix the lookup for a declaration conflicting with an enumerator (bogus use of LookupResult::getAsSingle)

2019-04-22 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno marked an inline comment as done.
riccibruno added inline comments.



Comment at: lib/Sema/SemaDecl.cpp:16607
+  // Check for other kinds of shadowing not already handled.
+  if (PrevDecl && isa(PrevDecl->getUnderlyingDecl()) &&
+  !TheEnumDecl->isScoped())

aaron.ballman wrote:
> Is the change to `PrevDecl->getUnderlyingDecl()` intended here?
Yes it is. Previously it was done inside `LookupResult::getAsSingle`. However 
with this patch `PrevDecl` at this point can be a `UsingShadowDecl` for a given 
using-declaration. We need to look for the underlying declaration since this is 
what `CheckShadow` expects.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60956



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


[PATCH] D55793: [clang-tidy] Add duplicated access specifier readability check (PR25403)

2019-04-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/readability/RedundantAccessSpecifiersCheck.cpp:35-36
+  for (DeclContext::specific_decl_iterator
+   AS(MatchedDecl->decls_begin()),
+   ASEnd(MatchedDecl->decls_end());
+   AS != ASEnd; ++AS) {

I have a slight preference for using assignment operators here rather than 
explicit constructor calls.



Comment at: 
clang-tools-extra/clang-tidy/readability/RedundantAccessSpecifiersCheck.cpp:54
+if (ASDecl->getAccess() == DefaultSpecifier) {
+  diag(ASDecl->getLocation(), "redundant access specifier")
+  << FixItHint::CreateRemoval(ASDecl->getSourceRange());

This is a bit terse, how about: `redundant access specifier has the same 
accessibility as the implicit access specifier`?



Comment at: 
clang-tools-extra/clang-tidy/readability/RedundantAccessSpecifiersCheck.cpp:69
+
+  diag(ASDecl->getLocation(), "duplicated access specifier")
+  << FixItHint::CreateRemoval(ASDecl->getSourceRange());

This is a bit terse, how about: `redundant access specifier has the same 
accessibility as the previous access specifier`?



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/readability-redundant-access-specifiers.rst:6
+
+Finds classes, structs and unions containing redundant member access 
specifiers.
+

structs and unions -> structs, and unions

One thing the docs leave unclear is which access specifiers you're talking 
about. Currently, the check only cares about the access specifiers for fields, 
but it seems reasonable that the check could also be talking about access 
specifiers on base class specifiers. e.g.,
```
struct Base {
  int a, b;
};

class C : private Base { // The 'private' here is redundant.
};
```
You should probably clarify this in the docs. Implementing this functionality 
may or may not be useful, but if you want to implement it, you could do it in a 
follow-up patch.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/readability-redundant-access-specifiers.rst:33
+
+   If set to non-zero, the check will also give warning if the first access
+   specifier declaration is redundant (e.g. ``private`` inside ``class``).

give warning -> diagnose



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/readability-redundant-access-specifiers.rst:34
+   If set to non-zero, the check will also give warning if the first access
+   specifier declaration is redundant (e.g. ``private`` inside ``class``).
+   Default is `0`.

May also want to put `public` inside `struct` or `union` as well.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/readability-redundant-access-specifiers.rst:48
+If `CheckFirstDeclaration` option is enabled, a warning about redundant
+access specifier will be emitted, since ``public`` is the default member access
+for structs.

since -> because



Comment at: 
clang-tools-extra/test/clang-tidy/readability-redundant-access-specifiers.cpp:71-72
+private: // comment-5
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: duplicated access specifier 
[readability-redundant-access-specifiers]
+  // CHECK-MESSAGES: :[[@LINE-8]]:1: note: previously declared here
+  // CHECK-FIXES: {{^}}// comment-5{{$}}

I think that diagnosing here is unfortunate. If the user defines `ZZ`, then the 
access specifier is no longer redundant. However, it may not be easy for you to 
handle this case when `ZZ` is not defined because the access specifier will 
have been removed by the preprocessor.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D55793



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


r358882 - [Sema] ADL: Associated namespaces for class types and enumeration types (CWG 1691)

2019-04-22 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Mon Apr 22 05:19:00 2019
New Revision: 358882

URL: http://llvm.org/viewvc/llvm-project?rev=358882&view=rev
Log:
[Sema] ADL: Associated namespaces for class types and enumeration types (CWG 
1691)

CWG 1691 changed the definition of the namespaces associated with a class
type or enumeration type.

For a class type, the associated namespaces are the innermost enclosing
namespaces of the associated classes. For an enumeration type, the associated
namespace is the innermost enclosing namespace of its declaration.

This also fixes CWG 1690 and CWG 1692.

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

Reviewed By: rjmccall, rsmith


Modified:
cfe/trunk/lib/Sema/SemaLookup.cpp

cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-associated-namespaces-classes.cpp
cfe/trunk/test/CXX/drs/dr16xx.cpp

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=358882&r1=358881&r2=358882&view=diff
==
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Mon Apr 22 05:19:00 2019
@@ -2471,30 +2471,38 @@ namespace {
 static void
 addAssociatedClassesAndNamespaces(AssociatedLookup &Result, QualType T);
 
+// Given the declaration context \param Ctx of a class, class template or
+// enumeration, add the associated namespaces to \param Namespaces as described
+// in [basic.lookup.argdep]p2.
 static void CollectEnclosingNamespace(Sema::AssociatedNamespaceSet &Namespaces,
   DeclContext *Ctx) {
-  // Add the associated namespace for this class.
-
-  // We don't use DeclContext::getEnclosingNamespaceContext() as this may
-  // be a locally scoped record.
+  // The exact wording has been changed in C++14 as a result of
+  // CWG 1691 (see also CWG 1690 and CWG 1692). We apply it unconditionally
+  // to all language versions since it is possible to return a local type
+  // from a lambda in C++11.
+  //
+  // C++14 [basic.lookup.argdep]p2:
+  //   If T is a class type [...]. Its associated namespaces are the innermost
+  //   enclosing namespaces of its associated classes. [...]
+  //
+  //   If T is an enumeration type, its associated namespace is the innermost
+  //   enclosing namespace of its declaration. [...]
 
-  // We skip out of inline namespaces. The innermost non-inline namespace
+  // We additionally skip inline namespaces. The innermost non-inline namespace
   // contains all names of all its nested inline namespaces anyway, so we can
   // replace the entire inline namespace tree with its root.
-  while (Ctx->isRecord() || Ctx->isTransparentContext() ||
- Ctx->isInlineNamespace())
+  while (!Ctx->isFileContext() || Ctx->isInlineNamespace())
 Ctx = Ctx->getParent();
 
-  if (Ctx->isFileContext())
-Namespaces.insert(Ctx->getPrimaryContext());
+  Namespaces.insert(Ctx->getPrimaryContext());
 }
 
 // Add the associated classes and namespaces for argument-dependent
-// lookup that involves a template argument (C++ [basic.lookup.koenig]p2).
+// lookup that involves a template argument (C++ [basic.lookup.argdep]p2).
 static void
 addAssociatedClassesAndNamespaces(AssociatedLookup &Result,
   const TemplateArgument &Arg) {
-  // C++ [basic.lookup.koenig]p2, last bullet:
+  // C++ [basic.lookup.argdep]p2, last bullet:
   //   -- [...] ;
   switch (Arg.getKind()) {
 case TemplateArgument::Null:
@@ -2539,9 +2547,8 @@ addAssociatedClassesAndNamespaces(Associ
   }
 }
 
-// Add the associated classes and namespaces for
-// argument-dependent lookup with an argument of class type
-// (C++ [basic.lookup.koenig]p2).
+// Add the associated classes and namespaces for argument-dependent lookup
+// with an argument of class type (C++ [basic.lookup.argdep]p2).
 static void
 addAssociatedClassesAndNamespaces(AssociatedLookup &Result,
   CXXRecordDecl *Class) {
@@ -2550,18 +2557,19 @@ addAssociatedClassesAndNamespaces(Associ
   if (Class->getDeclName() == Result.S.VAListTagName)
 return;
 
-  // C++ [basic.lookup.koenig]p2:
+  // C++ [basic.lookup.argdep]p2:
   //   [...]
   // -- If T is a class type (including unions), its associated
   //classes are: the class itself; the class of which it is a
-  //member, if any; and its direct and indirect base
-  //classes. Its associated namespaces are the namespaces in
-  //which its associated classes are defined.
+  //member, if any; and its direct and indirect base classes.
+  //Its associated namespaces are the innermost enclosing
+  //namespaces of its associated classes.
 
   // Add the class of which it is a member, if any.
   DeclContext *Ctx = Class->getDeclContext();
   if (CXXRecordDecl *EnclosingClass = dyn_cast(Ctx))
 Result.Classes.insert(EnclosingClass);
+
   // Add the as

[PATCH] D60573: [Sema] ADL: Associated namespaces for class types and enumeration types (CWG 1691)

2019-04-22 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC358882: [Sema] ADL: Associated namespaces for class types 
and enumeration types (CWG… (authored by brunoricci, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D60573?vs=194765&id=196058#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D60573

Files:
  lib/Sema/SemaLookup.cpp
  
test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-associated-namespaces-classes.cpp
  test/CXX/drs/dr16xx.cpp

Index: test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-associated-namespaces-classes.cpp
===
--- test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-associated-namespaces-classes.cpp
+++ test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-associated-namespaces-classes.cpp
@@ -38,12 +38,11 @@
   return s;
 }
 using S = decltype(foo());
-void f(S); // expected-note {{'X2::f' declared here}}
+void f(S); // #1
   }
   void test2() {
-f(X2::S{}); // FIXME: This is well-formed; X2 is the innermost enclosing namespace
-// of the local struct S.
-// expected-error@-2 {{use of undeclared identifier 'f'}}
+f(X2::S{}); // This is well-formed; X2 is the innermost enclosing namespace
+// of the local struct S. Calls #1.
   }
 
   // associated class: the parent class
@@ -83,7 +82,7 @@
 
 void test5() {
   auto lambda = N::get_lambda();
-  f(lambda); // FIXME: This is well-formed. expected-error {{use of undeclared}}
+  f(lambda); // ok
 }
   }
 
@@ -193,6 +192,12 @@
   enum F : int;
   friend void g(F);
 };
+auto foo() {
+  enum G {} g;
+  return g;
+}
+using G = decltype(foo());
+void h(G);
   }
 
   void test() {
@@ -200,6 +205,9 @@
 f(e); // ok
 N::S::F f;
 g(f); // ok
+N::G g;
+h(g); // ok
+
   }
 }
 
Index: test/CXX/drs/dr16xx.cpp
===
--- test/CXX/drs/dr16xx.cpp
+++ test/CXX/drs/dr16xx.cpp
@@ -284,6 +284,54 @@
 #endif
 }
 
+namespace dr1690 { // dr1690: 9
+  // See also the various tests in "CXX/basic/basic.lookup/basic.lookup.argdep".
+#if __cplusplus >= 201103L
+  namespace N {
+static auto lambda = []() { struct S {} s; return s; };
+void f(decltype(lambda()));
+  }
+
+  void test() {
+auto s = N::lambda();
+f(s); // ok
+  }
+#endif
+}
+
+namespace dr1691 { // dr1691: 9
+#if __cplusplus >= 201103L
+  namespace N {
+namespace M {
+  enum E : int;
+  void f(E);
+}
+enum M::E : int {};
+void g(M::E); // expected-note {{declared here}}
+  }
+  void test() {
+N::M::E e;
+f(e); // ok
+g(e); // expected-error {{use of undeclared}}
+  }
+#endif
+}
+
+namespace dr1692 { // dr1692: 9
+  namespace N {
+struct A {
+  struct B {
+struct C {};
+  };
+};
+void f(A::B::C);
+  }
+  void test() {
+N::A::B::C c;
+f(c); // ok
+  }
+}
+
 namespace dr1696 { // dr1696: 7
   namespace std_examples {
 #if __cplusplus >= 201402L
Index: lib/Sema/SemaLookup.cpp
===
--- lib/Sema/SemaLookup.cpp
+++ lib/Sema/SemaLookup.cpp
@@ -2471,30 +2471,38 @@
 static void
 addAssociatedClassesAndNamespaces(AssociatedLookup &Result, QualType T);
 
+// Given the declaration context \param Ctx of a class, class template or
+// enumeration, add the associated namespaces to \param Namespaces as described
+// in [basic.lookup.argdep]p2.
 static void CollectEnclosingNamespace(Sema::AssociatedNamespaceSet &Namespaces,
   DeclContext *Ctx) {
-  // Add the associated namespace for this class.
-
-  // We don't use DeclContext::getEnclosingNamespaceContext() as this may
-  // be a locally scoped record.
+  // The exact wording has been changed in C++14 as a result of
+  // CWG 1691 (see also CWG 1690 and CWG 1692). We apply it unconditionally
+  // to all language versions since it is possible to return a local type
+  // from a lambda in C++11.
+  //
+  // C++14 [basic.lookup.argdep]p2:
+  //   If T is a class type [...]. Its associated namespaces are the innermost
+  //   enclosing namespaces of its associated classes. [...]
+  //
+  //   If T is an enumeration type, its associated namespace is the innermost
+  //   enclosing namespace of its declaration. [...]
 
-  // We skip out of inline namespaces. The innermost non-inline namespace
+  // We additionally skip inline namespaces. The innermost non-inline namespace
   // contains all names of all its nested inline namespaces anyway, so we can
   // replace the entire inline namespace tree with its root.
-  while (Ctx->isRecord() || Ctx->isTransparentContext() ||
- Ctx->isInlineNamespace())
+  while (!Ctx->isFileContext() || Ctx->isInlineNamespace())
 Ctx = Ctx->getParent();
 

[PATCH] D60956: [Sema] Fix the lookup for a declaration conflicting with an enumerator (bogus use of LookupResult::getAsSingle)

2019-04-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: lib/Sema/SemaDecl.cpp:16607
+  // Check for other kinds of shadowing not already handled.
+  if (PrevDecl && isa(PrevDecl->getUnderlyingDecl()) &&
+  !TheEnumDecl->isScoped())

riccibruno wrote:
> aaron.ballman wrote:
> > Is the change to `PrevDecl->getUnderlyingDecl()` intended here?
> Yes it is. Previously it was done inside `LookupResult::getAsSingle`. However 
> with this patch `PrevDecl` at this point can be a `UsingShadowDecl` for a 
> given using-declaration. We need to look for the underlying declaration since 
> this is what `CheckShadow` expects.
But when it's not a `UsingShadowDecl`, will the behavior now be incorrect? 
e.g., if it was a `NamespaceAliasDecl`, won't this check whether you are 
shadowing the aliased namespace as opposed to the alias name itself? Might be 
worth some tests.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60956



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


[PATCH] D55411: [clang-tidy] check for flagging using declarations not in the inner most namespace

2019-04-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/abseil/SafelyScopedCheck.cpp:22
+  // The target using declaration is either:
+  // 1. not in any namespace declaration, or
+  // 2. in some namespace declaration but not in the innermost layer

aaron.ballman wrote:
> Why is this not also checking that the using declaration is not within a 
> header file?
I'm still wondering about this. The Abseil tip specifically says `Never declare 
namespace aliases or convenience using-declarations at namespace scope in 
header files, only in .cc files.`, which is why I had figured I would see some 
enforcement from this check.



Comment at: clang-tidy/abseil/SafelyScopedCheck.cpp:37
+  diag(MatchedDecl->getLocation(),
+   "using declaration %0 not declared in the innermost namespace.")
+  << MatchedDecl;

aaron.ballman wrote:
> You should remove the full stop at the end of the diagnostic.
The diagnostic still doesn't meet our (somewhat strange) requirements; 
diagnostics should not be full sentences with capitalization and punctuation. 
However, it also doesn't really tell the user what is wrong with their code, 
just how to fix it to make the diagnostic go away.

I don't have a particularly great suggestion for a replacement, however. I'm 
still trying to wrap my mind around the suggested changes to code, because it 
seems like this advice isn't general purpose. Consider:
```
namespace Foo { // I control this namespace.
  namespace details {
int func(int I);
  } // namespace details

  using Frobble::Bobble;

  void f(SomeNameFromFrobbleBobble FB) {
FB.whatever(details::func(12));
  }
} // namespace Foo
```
The suggestion to move the using declaration into the innermost namespace is 
actually a poor one -- we don't want the interface of `f()` to be `void 
f(details::SomeNameFromFrobbleBobble FB)`, which is what this check seems to 
suggest we do. I don't see how we can determine whether the using declaration 
should or should not be moved, so I can't really tell what the diagnostic text 
should be.


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

https://reviews.llvm.org/D55411



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


[PATCH] D60507: [clang-tidy] new check: bugprone-unhandled-self-assignment

2019-04-22 Thread Tamás Zolnai via Phabricator via cfe-commits
ztamas updated this revision to Diff 196066.
ztamas added a comment.

Add false positive test cases.
Added a note about template related limitation to the docs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60507

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-self-assignment.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-oop54-cpp.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/bugprone-unhandled-self-assignment.cpp

Index: clang-tools-extra/test/clang-tidy/bugprone-unhandled-self-assignment.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/bugprone-unhandled-self-assignment.cpp
@@ -0,0 +1,502 @@
+// RUN: %check_clang_tidy %s bugprone-unhandled-self-assignment %t
+
+namespace std {
+
+template 
+void swap(T x, T y) {
+}
+
+template 
+T &&move(T x) {
+}
+
+template 
+class unique_ptr {
+};
+
+template 
+class shared_ptr {
+};
+
+template 
+class weak_ptr {
+};
+
+template 
+class auto_ptr {
+};
+
+} // namespace std
+
+void assert(int expression){};
+
+///
+/// Test cases correctly caught by the check.
+
+class PtrField {
+public:
+  PtrField &operator=(const PtrField &object);
+
+private:
+  int *p;
+};
+
+PtrField &PtrField::operator=(const PtrField &object) {
+  // CHECK-MESSAGES: [[@LINE-1]]:21: warning: operator=() might not handle self-assignment properly [bugprone-unhandled-self-assignment]
+  // ...
+  return *this;
+}
+
+// Class with an inline operator definition.
+class InlineDefinition {
+public:
+  InlineDefinition &operator=(const InlineDefinition &object) {
+// CHECK-MESSAGES: [[@LINE-1]]:21: warning: operator=() might not handle self-assignment properly [bugprone-unhandled-self-assignment]
+// ...
+return *this;
+  }
+
+private:
+  int *p;
+};
+
+class UniquePtrField {
+public:
+  UniquePtrField &operator=(const UniquePtrField &object) {
+// CHECK-MESSAGES: [[@LINE-1]]:19: warning: operator=() might not handle self-assignment properly [bugprone-unhandled-self-assignment]
+// ...
+return *this;
+  }
+
+private:
+  std::unique_ptr p;
+};
+
+class SharedPtrField {
+public:
+  SharedPtrField &operator=(const SharedPtrField &object) {
+// CHECK-MESSAGES: [[@LINE-1]]:19: warning: operator=() might not handle self-assignment properly [bugprone-unhandled-self-assignment]
+// ...
+return *this;
+  }
+
+private:
+  std::shared_ptr p;
+};
+
+class WeakPtrField {
+public:
+  WeakPtrField &operator=(const WeakPtrField &object) {
+// CHECK-MESSAGES: [[@LINE-1]]:17: warning: operator=() might not handle self-assignment properly [bugprone-unhandled-self-assignment]
+// ...
+return *this;
+  }
+
+private:
+  std::weak_ptr p;
+};
+
+class AutoPtrField {
+public:
+  AutoPtrField &operator=(const AutoPtrField &object) {
+// CHECK-MESSAGES: [[@LINE-1]]:17: warning: operator=() might not handle self-assignment properly [bugprone-unhandled-self-assignment]
+// ...
+return *this;
+  }
+
+private:
+  std::auto_ptr p;
+};
+
+// Class with C array field.
+class CArrayField {
+public:
+  CArrayField &operator=(const CArrayField &object) {
+// CHECK-MESSAGES: [[@LINE-1]]:16: warning: operator=() might not handle self-assignment properly [bugprone-unhandled-self-assignment]
+// ...
+return *this;
+  }
+
+private:
+  int array[256];
+};
+
+// Make sure to not ignore cases when the operator definition calls
+// a copy constructor of another class.
+class CopyConstruct {
+public:
+  CopyConstruct &operator=(const CopyConstruct &object) {
+// CHECK-MESSAGES: [[@LINE-1]]:18: warning: operator=() might not handle self-assignment properly [bugprone-unhandled-self-assignment]
+WeakPtrField a;
+WeakPtrField b(a);
+// ...
+return *this;
+  }
+
+private:
+  int *p;
+};
+
+// Make sure to not ignore cases when the operator definition calls
+// a copy assignment operator of another class.
+class AssignOperator {
+public:
+  AssignOperator &operator=(const AssignOperator &object) {
+// CHECK-MESSAGES: [[@LINE-1]]:19: warning: operator=() might not handle self-assignment properly [bugprone-unhandled-self-assignment]
+a.operator=(object.a);
+// ...
+return *this;
+  }
+
+private:
+  int *p;
+  WeakPtrField a;
+};
+
+///
+/// Test cases correctly ignored by the check.
+
+// Self-assignment is checked using the equality operator.
+class SelfCheck1 {
+public:
+  SelfCheck1 &operat

[PATCH] D59754: [Sema] Add c++2a designated initializer warnings

2019-04-22 Thread Don Hinton via Phabricator via cfe-commits
hintonda marked an inline comment as done.
hintonda added inline comments.



Comment at: clang/lib/Sema/SemaInit.cpp:2069-2072
+if (!VerifyOnly && HasDesignatedInit && SemaRef.getLangOpts().CPlusPlus2a) 
{
+  SemaRef.Diag(Init->getBeginLoc(), diag::ext_c20_designated_init)
+  << "mixed" << Init->getSourceRange();
+}

hintonda wrote:
> rsmith wrote:
> > I think it would be preferable to diagnose the "mixed" case in the parser 
> > rather than here (it's a grammatical restriction in C++, after all). I'm 
> > worried that handling it here will get some cases wrong, such as perhaps:
> > 
> > ```
> > struct A {
> >   union { int x, y; };
> >   int z;
> > };
> > A a = { .x = 123, 456 }; // should be rejected, but I think this patch 
> > might accept
> > ```
> > 
> > ... and it might also get template instantiation cases wrong for a case 
> > like:
> > 
> > ```
> > struct Q { Q(); };
> > struct A { Q x, y; };
> > template void f() {
> >   A a = {.y = Q()};
> > }
> > void g() { f(); }
> > ```
> > 
> > ... where we might possibly end up passing an `InitListExpr` representing 
> > `{Q(), .y = Q()}` into `InitListChecker`.
> > 
> > I think the only C++20 restriction that it makes sense to check in 
> > `InitListChecker` is that the field names are in the right order; 
> > everything else should be checked earlier. This would also match the 
> > semantics of overload resolution, for which the "fields are in the right 
> > order" check is deferred until after a function is selected, whereas all 
> > the other checks are performed eagerly.
> Will work on moving these to the parser.
> 
> Btw, the first one is diagnosed correctly, but doesn't complain about the 
> second.  Not sure I grok the problem there either since Q has a default ctor.
> 
Woke up this morning and realized what you meant about the union.  I'll take 
care of it in the next patch.

thanks again...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59754



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


[PATCH] D41284: [Concepts] Associated constraints infrastructure.

2019-04-22 Thread Saar Raz via Phabricator via cfe-commits
saar.raz updated this revision to Diff 196074.
saar.raz added a comment.

- Address CR comments by rsmith
  - Remove obsolete TODOs
  - Fix redeclaration checking
  - Change getAssociatedConstraints interface
- Add requires clause to ASTNodeTraverser


Repository:
  rC Clang

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

https://reviews.llvm.org/D41284

Files:
  include/clang/AST/ASTNodeTraverser.h
  include/clang/AST/DeclTemplate.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/AST/ASTContext.cpp
  lib/AST/DeclTemplate.cpp
  lib/Sema/SemaConcept.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CXX/concepts-ts/temp/concept/p4.cpp
  test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/class-template-decl.cpp
  test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/func-template-decl.cpp
  test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/var-template-decl.cpp

Index: test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/var-template-decl.cpp
===
--- /dev/null
+++ test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/var-template-decl.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -std=c++2a -fconcepts-ts -x c++ -verify %s
+
+namespace nodiag {
+
+struct B {
+template  requires bool(T())
+static int A;
+};
+
+template  requires bool(U())
+int B::A = int(U());
+
+} // end namespace nodiag
+
+namespace diag {
+
+struct B {
+template  requires bool(T()) // expected-note{{previous template declaration is here}}
+static int A;
+};
+
+template  requires !bool(U())  // expected-error{{requires clause differs in template redeclaration}}
+int B::A = int(U());
+
+} // end namespace diag
\ No newline at end of file
Index: test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/func-template-decl.cpp
===
--- /dev/null
+++ test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/func-template-decl.cpp
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -std=c++2a -fconcepts-ts -x c++ -verify %s
+
+namespace nodiag {
+
+template  requires bool(T())
+int A();
+template  requires bool(U())
+int A();
+
+} // end namespace nodiag
+
+namespace diag {
+
+namespace orig {
+  template  requires true
+  int A();
+  template 
+  int B();
+  template  requires true
+  int C();
+}
+
+template 
+int orig::A();
+// expected-error@-1{{out-of-line declaration of 'A' does not match any declaration in namespace 'diag::orig'}}
+template  requires true
+int orig::B();
+// expected-error@-1{{out-of-line declaration of 'B' does not match any declaration in namespace 'diag::orig'}}
+template  requires !0
+int orig::C();
+// expected-error@-1{{out-of-line declaration of 'C' does not match any declaration in namespace 'diag::orig'}}
+
+} // end namespace diag
+
+namespace nodiag {
+
+struct AA {
+  template  requires someFunc(T())
+  int A();
+};
+
+template  requires someFunc(T())
+int AA::A() { return sizeof(T); }
+
+} // end namespace nodiag
+
+namespace diag {
+
+template 
+struct TA {
+  template  class TT> requires TT::happy
+  int A();
+};
+
+template 
+template  class TT> int TA::A() { return sizeof(TT); }
+// expected-error@-1{{out-of-line definition of 'A' does not match any declaration in 'TA'}}
+
+} // end namespace diag
Index: test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/class-template-decl.cpp
===
--- test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/class-template-decl.cpp
+++ test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/class-template-decl.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++14 -fconcepts-ts -x c++ -verify %s
+// RUN: %clang_cc1 -std=c++2a -fconcepts-ts -x c++ -verify %s
 
 namespace nodiag {
 
@@ -13,15 +13,15 @@
 
 template  requires true // expected-note{{previous template declaration is here}}
 struct A;
-template  struct A; // expected-error{{associated constraints differ in template redeclaration}}
+template  struct A; // expected-error{{requires clause differs in template redeclaration}}
 
 template  struct B; // expected-note{{previous template declaration is here}}
-template  requires true // expected-error{{associated constraints differ in template redeclaration}}
+template  requires true // expected-error{{requires clause differs in template redeclaration}}
 struct B;
 
 template  requires true // expected-note{{previous template declaration is here}}
 struct C;
-template  requires !0 // expected-error{{associated constraints differ in template redeclaration}}
+template  requires !0 // expected-error{{requires clause differs in template redeclaration}}
 struct C;
 
 } // end namespace diag
@@ -33,7 +33,7 @@
   struct A;
 };
 
-t

[libunwind] r358896 - [NFC] Fix typo in debug log

2019-04-22 Thread Louis Dionne via cfe-commits
Author: ldionne
Date: Mon Apr 22 08:40:50 2019
New Revision: 358896

URL: http://llvm.org/viewvc/llvm-project?rev=358896&view=rev
Log:
[NFC] Fix typo in debug log

Modified:
libunwind/trunk/src/UnwindCursor.hpp

Modified: libunwind/trunk/src/UnwindCursor.hpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/UnwindCursor.hpp?rev=358896&r1=358895&r2=358896&view=diff
==
--- libunwind/trunk/src/UnwindCursor.hpp (original)
+++ libunwind/trunk/src/UnwindCursor.hpp Mon Apr 22 08:40:50 2019
@@ -1740,7 +1740,7 @@ bool UnwindCursor::getInfoFromComp
 --personalityIndex; // change 1-based to zero-based index
 if (personalityIndex > sectionHeader.personalityArrayCount()) {
   _LIBUNWIND_DEBUG_LOG("found encoding 0x%08X with personality index %d,  "
-"but personality table has only %d entires",
+"but personality table has only %d entries",
 encoding, personalityIndex,
 sectionHeader.personalityArrayCount());
   return false;


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


[PATCH] D46421: [analyzer][CrossTU] Extend CTU to VarDecls with initializer

2019-04-22 Thread Rafael Stahl via Phabricator via cfe-commits
r.stahl updated this revision to Diff 196075.
r.stahl added a comment.

@xazax.hun good point and that actually fixes a bug since that branch should 
also do the deep check. Added that to the tests.


Repository:
  rC Clang

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

https://reviews.llvm.org/D46421

Files:
  include/clang/CrossTU/CrossTranslationUnit.h
  lib/CrossTU/CrossTranslationUnit.cpp
  lib/StaticAnalyzer/Core/RegionStore.cpp
  lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
  test/Analysis/Inputs/ctu-other.cpp
  test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt
  test/Analysis/ctu-main.cpp
  test/Analysis/func-mapping-test.cpp
  test/Analysis/redecl.c
  tools/clang-extdef-mapping/ClangExtDefMapGen.cpp

Index: tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
===
--- tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
+++ tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
@@ -34,20 +34,22 @@
 class MapExtDefNamesConsumer : public ASTConsumer {
 public:
   MapExtDefNamesConsumer(ASTContext &Context)
-  : SM(Context.getSourceManager()) {}
+  : Ctx(Context), SM(Context.getSourceManager()) {}
 
   ~MapExtDefNamesConsumer() {
 // Flush results to standard output.
 llvm::outs() << createCrossTUIndexString(Index);
   }
 
-  void HandleTranslationUnit(ASTContext &Ctx) override {
-handleDecl(Ctx.getTranslationUnitDecl());
+  void HandleTranslationUnit(ASTContext &Context) override {
+handleDecl(Context.getTranslationUnitDecl());
   }
 
 private:
   void handleDecl(const Decl *D);
+  void addIfInMain(const DeclaratorDecl *DD, SourceLocation defStart);
 
+  ASTContext &Ctx;
   SourceManager &SM;
   llvm::StringMap Index;
   std::string CurrentFileName;
@@ -58,30 +60,13 @@
 return;
 
   if (const auto *FD = dyn_cast(D)) {
-if (FD->isThisDeclarationADefinition()) {
-  if (const Stmt *Body = FD->getBody()) {
-if (CurrentFileName.empty()) {
-  CurrentFileName =
-  SM.getFileEntryForID(SM.getMainFileID())->tryGetRealPathName();
-  if (CurrentFileName.empty())
-CurrentFileName = "invalid_file";
-}
-
-switch (FD->getLinkageInternal()) {
-case ExternalLinkage:
-case VisibleNoLinkage:
-case UniqueExternalLinkage:
-  if (SM.isInMainFile(Body->getBeginLoc())) {
-std::string LookupName =
-CrossTranslationUnitContext::getLookupName(FD);
-Index[LookupName] = CurrentFileName;
-  }
-  break;
-default:
-  break;
-}
-  }
-}
+if (FD->isThisDeclarationADefinition())
+  if (const Stmt *Body = FD->getBody())
+addIfInMain(FD, Body->getBeginLoc());
+  } else if (const auto *VD = dyn_cast(D)) {
+if (cross_tu::containsConst(VD, Ctx) && VD->hasInit())
+  if (const Expr *Init = VD->getInit())
+addIfInMain(VD, Init->getBeginLoc());
   }
 
   if (const auto *DC = dyn_cast(D))
@@ -89,6 +74,27 @@
   handleDecl(D);
 }
 
+void MapExtDefNamesConsumer::addIfInMain(const DeclaratorDecl *DD,
+ SourceLocation defStart) {
+  std::string LookupName = CrossTranslationUnitContext::getLookupName(DD);
+  if (CurrentFileName.empty()) {
+CurrentFileName =
+SM.getFileEntryForID(SM.getMainFileID())->tryGetRealPathName();
+if (CurrentFileName.empty())
+  CurrentFileName = "invalid_file";
+  }
+
+  switch (DD->getLinkageInternal()) {
+  case ExternalLinkage:
+  case VisibleNoLinkage:
+  case UniqueExternalLinkage:
+if (SM.isInMainFile(defStart))
+  Index[LookupName] = CurrentFileName;
+  default:
+break;
+  }
+}
+
 class MapExtDefNamesAction : public ASTFrontendAction {
 protected:
   std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
Index: test/Analysis/redecl.c
===
--- /dev/null
+++ test/Analysis/redecl.c
@@ -0,0 +1,13 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s
+// XFAIL: *
+
+void clang_analyzer_eval(int);
+
+extern const int extInt;
+
+int main()
+{
+clang_analyzer_eval(extInt == 2); // expected-warning{{TRUE}}
+}
+
+extern const int extInt = 2;
Index: test/Analysis/func-mapping-test.cpp
===
--- test/Analysis/func-mapping-test.cpp
+++ test/Analysis/func-mapping-test.cpp
@@ -1,7 +1,43 @@
-// RUN: %clang_extdef_map %s -- | FileCheck %s
+// RUN: %clang_extdef_map %s -- | FileCheck --implicit-check-not "c:@y" --implicit-check-not "c:@z" %s
 
 int f(int) {
   return 0;
 }
+// CHECK-DAG: c:@F@f#I#
 
-// CHECK: c:@F@f#I#
+extern const int x = 5;
+// CHECK-DAG: c:@x
+
+// Non-const variables should not be collected.
+int y = 5;
+
+// In C++, const implies internal linkage, so not collected.
+const int z = 5;
+
+struct S {
+  int a;
+};
+extern S const s = {.a = 2};
+// CHECK-DAG: c

r358898 - [sema][objc] Minor refactor to OverrideSearch. NFCI.

2019-04-22 Thread Matt Davis via cfe-commits
Author: mattd
Date: Mon Apr 22 09:04:44 2019
New Revision: 358898

URL: http://llvm.org/viewvc/llvm-project?rev=358898&view=rev
Log:
[sema][objc] Minor refactor to OverrideSearch. NFCI.

Summary:
* Removed a member that was only used during construction.
* Use range-based for iteration when accessing the result of the search.
* Require an `ObjCMethodDecl` reference upon construction of an
* Constify.

Reviewers: rjmccall

Reviewed By: rjmccall

Subscribers: llvm-commits

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

Modified:
cfe/trunk/lib/Sema/SemaDeclObjC.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=358898&r1=358897&r2=358898&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Mon Apr 22 09:04:44 2019
@@ -4166,13 +4166,12 @@ namespace {
 /// overrides.
 class OverrideSearch {
 public:
-  Sema &S;
-  ObjCMethodDecl *Method;
+  const ObjCMethodDecl *Method;
   llvm::SmallSetVector Overridden;
   bool Recursive;
 
 public:
-  OverrideSearch(Sema &S, ObjCMethodDecl *method) : S(S), Method(method) {
+  OverrideSearch(Sema &S, const ObjCMethodDecl *method) : Method(method) {
 Selector selector = method->getSelector();
 
 // Bypass this search if we've never seen an instance/class method
@@ -4186,19 +4185,20 @@ public:
   if (it == S.MethodPool.end())
 return;
 }
-ObjCMethodList &list =
+const ObjCMethodList &list =
   method->isInstanceMethod() ? it->second.first : it->second.second;
 if (!list.getMethod()) return;
 
-ObjCContainerDecl *container
+const ObjCContainerDecl *container
   = cast(method->getDeclContext());
 
 // Prevent the search from reaching this container again.  This is
 // important with categories, which override methods from the
 // interface and each other.
-if (ObjCCategoryDecl *Category = dyn_cast(container)) {
+if (const ObjCCategoryDecl *Category =
+dyn_cast(container)) {
   searchFromContainer(container);
-  if (ObjCInterfaceDecl *Interface = Category->getClassInterface())
+  if (const ObjCInterfaceDecl *Interface = Category->getClassInterface())
 searchFromContainer(Interface);
 } else {
   searchFromContainer(container);
@@ -4210,7 +4210,7 @@ public:
   iterator end() const { return Overridden.end(); }
 
 private:
-  void searchFromContainer(ObjCContainerDecl *container) {
+  void searchFromContainer(const ObjCContainerDecl *container) {
 if (container->isInvalidDecl()) return;
 
 switch (container->getDeclKind()) {
@@ -4226,7 +4226,7 @@ private:
 }
   }
 
-  void searchFrom(ObjCProtocolDecl *protocol) {
+  void searchFrom(const ObjCProtocolDecl *protocol) {
 if (!protocol->hasDefinition())
   return;
 
@@ -4235,14 +4235,14 @@ private:
 search(protocol->getReferencedProtocols());
   }
 
-  void searchFrom(ObjCCategoryDecl *category) {
+  void searchFrom(const ObjCCategoryDecl *category) {
 // A method in a category declaration overrides declarations from
 // the main class and from protocols the category references.
 // The main class is handled in the constructor.
 search(category->getReferencedProtocols());
   }
 
-  void searchFrom(ObjCCategoryImplDecl *impl) {
+  void searchFrom(const ObjCCategoryImplDecl *impl) {
 // A method in a category definition that has a category
 // declaration overrides declarations from the category
 // declaration.
@@ -4252,12 +4252,12 @@ private:
 search(Interface);
 
 // Otherwise it overrides declarations from the class.
-} else if (ObjCInterfaceDecl *Interface = impl->getClassInterface()) {
+} else if (const auto *Interface = impl->getClassInterface()) {
   search(Interface);
 }
   }
 
-  void searchFrom(ObjCInterfaceDecl *iface) {
+  void searchFrom(const ObjCInterfaceDecl *iface) {
 // A method in a class declaration overrides declarations from
 if (!iface->hasDefinition())
   return;
@@ -4274,20 +4274,19 @@ private:
 search(iface->getReferencedProtocols());
   }
 
-  void searchFrom(ObjCImplementationDecl *impl) {
+  void searchFrom(const ObjCImplementationDecl *impl) {
 // A method in a class implementation overrides declarations from
 // the class interface.
-if (ObjCInterfaceDecl *Interface = impl->getClassInterface())
+if (const auto *Interface = impl->getClassInterface())
   search(Interface);
   }
 
   void search(const ObjCProtocolList &protocols) {
-for (ObjCProtocolList::iterator i = protocols.begin(), e = protocols.end();
- i != e; ++i)
-  search(*i);
+for (const auto *Proto : protocols)
+  search(Proto);
   }
 
-  void search(ObjCContainerDecl *container) {
+  void search(const ObjCContainerDecl *container) {
 // Check for a method in this container which 

[PATCH] D60850: [sema][objc] Minor refactor to OverrideSearch. NFCI.

2019-04-22 Thread Matt Davis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC358898: [sema][objc] Minor refactor to OverrideSearch. NFCI. 
(authored by mattd, committed by ).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D60850?vs=195876&id=196077#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D60850

Files:
  lib/Sema/SemaDeclObjC.cpp

Index: lib/Sema/SemaDeclObjC.cpp
===
--- lib/Sema/SemaDeclObjC.cpp
+++ lib/Sema/SemaDeclObjC.cpp
@@ -4166,13 +4166,12 @@
 /// overrides.
 class OverrideSearch {
 public:
-  Sema &S;
-  ObjCMethodDecl *Method;
+  const ObjCMethodDecl *Method;
   llvm::SmallSetVector Overridden;
   bool Recursive;
 
 public:
-  OverrideSearch(Sema &S, ObjCMethodDecl *method) : S(S), Method(method) {
+  OverrideSearch(Sema &S, const ObjCMethodDecl *method) : Method(method) {
 Selector selector = method->getSelector();
 
 // Bypass this search if we've never seen an instance/class method
@@ -4186,19 +4185,20 @@
   if (it == S.MethodPool.end())
 return;
 }
-ObjCMethodList &list =
+const ObjCMethodList &list =
   method->isInstanceMethod() ? it->second.first : it->second.second;
 if (!list.getMethod()) return;
 
-ObjCContainerDecl *container
+const ObjCContainerDecl *container
   = cast(method->getDeclContext());
 
 // Prevent the search from reaching this container again.  This is
 // important with categories, which override methods from the
 // interface and each other.
-if (ObjCCategoryDecl *Category = dyn_cast(container)) {
+if (const ObjCCategoryDecl *Category =
+dyn_cast(container)) {
   searchFromContainer(container);
-  if (ObjCInterfaceDecl *Interface = Category->getClassInterface())
+  if (const ObjCInterfaceDecl *Interface = Category->getClassInterface())
 searchFromContainer(Interface);
 } else {
   searchFromContainer(container);
@@ -4210,7 +4210,7 @@
   iterator end() const { return Overridden.end(); }
 
 private:
-  void searchFromContainer(ObjCContainerDecl *container) {
+  void searchFromContainer(const ObjCContainerDecl *container) {
 if (container->isInvalidDecl()) return;
 
 switch (container->getDeclKind()) {
@@ -4226,7 +4226,7 @@
 }
   }
 
-  void searchFrom(ObjCProtocolDecl *protocol) {
+  void searchFrom(const ObjCProtocolDecl *protocol) {
 if (!protocol->hasDefinition())
   return;
 
@@ -4235,14 +4235,14 @@
 search(protocol->getReferencedProtocols());
   }
 
-  void searchFrom(ObjCCategoryDecl *category) {
+  void searchFrom(const ObjCCategoryDecl *category) {
 // A method in a category declaration overrides declarations from
 // the main class and from protocols the category references.
 // The main class is handled in the constructor.
 search(category->getReferencedProtocols());
   }
 
-  void searchFrom(ObjCCategoryImplDecl *impl) {
+  void searchFrom(const ObjCCategoryImplDecl *impl) {
 // A method in a category definition that has a category
 // declaration overrides declarations from the category
 // declaration.
@@ -4252,12 +4252,12 @@
 search(Interface);
 
 // Otherwise it overrides declarations from the class.
-} else if (ObjCInterfaceDecl *Interface = impl->getClassInterface()) {
+} else if (const auto *Interface = impl->getClassInterface()) {
   search(Interface);
 }
   }
 
-  void searchFrom(ObjCInterfaceDecl *iface) {
+  void searchFrom(const ObjCInterfaceDecl *iface) {
 // A method in a class declaration overrides declarations from
 if (!iface->hasDefinition())
   return;
@@ -4274,20 +4274,19 @@
 search(iface->getReferencedProtocols());
   }
 
-  void searchFrom(ObjCImplementationDecl *impl) {
+  void searchFrom(const ObjCImplementationDecl *impl) {
 // A method in a class implementation overrides declarations from
 // the class interface.
-if (ObjCInterfaceDecl *Interface = impl->getClassInterface())
+if (const auto *Interface = impl->getClassInterface())
   search(Interface);
   }
 
   void search(const ObjCProtocolList &protocols) {
-for (ObjCProtocolList::iterator i = protocols.begin(), e = protocols.end();
- i != e; ++i)
-  search(*i);
+for (const auto *Proto : protocols)
+  search(Proto);
   }
 
-  void search(ObjCContainerDecl *container) {
+  void search(const ObjCContainerDecl *container) {
 // Check for a method in this container which matches this selector.
 ObjCMethodDecl *meth = container->getMethod(Method->getSelector(),
 Method->isInstanceMethod(),
@@ -4313,6 +4312,8 @@
 void Sema::CheckObjCMethodOverrides(ObjCMethodDecl *ObjCMethod,
 ObjCInterfaceDecl *CurrentClass,
   

[PATCH] D60967: Move setTargetAttributes after setGVProperties in SetFunctionAttributes

2019-04-22 Thread Scott Linder via Phabricator via cfe-commits
scott.linder created this revision.
scott.linder added reviewers: atanasyan, rjmccall, yaxunl.
Herald added subscribers: cfe-commits, arichardson, tpr, sdardis.
Herald added a project: clang.

AMDGPU relies on global properties being set before setTargetProperties is 
called. Existing targets like MIPS which rely on setTargetProperties do not 
seem to rely on the current behavior, so this patch moves the call later in 
SetFunctionAttributes.


Repository:
  rC Clang

https://reviews.llvm.org/D60967

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGenOpenCL/visibility.cl


Index: test/CodeGenOpenCL/visibility.cl
===
--- test/CodeGenOpenCL/visibility.cl
+++ test/CodeGenOpenCL/visibility.cl
@@ -72,6 +72,57 @@
 // FVIS-HIDDEN: define void @func_default()
 __attribute__((visibility("default"))) void func_default() {}
 
+extern kernel void ext_kern();
+__attribute__((visibility("hidden"))) extern kernel void ext_kern_hidden();
+__attribute__((visibility("protected"))) extern kernel void 
ext_kern_protected();
+__attribute__((visibility("default"))) extern kernel void ext_kern_default();
+
+extern void ext_func();
+__attribute__((visibility("hidden"))) extern void ext_func_hidden();
+__attribute__((visibility("protected"))) extern void ext_func_protected();
+__attribute__((visibility("default"))) extern void ext_func_default();
+
 void use() {
 glob = ext + ext_hidden + ext_protected + ext_default;
+ext_kern();
+ext_kern_hidden();
+ext_kern_protected();
+ext_kern_default();
+ext_func();
+ext_func_hidden();
+ext_func_protected();
+ext_func_default();
 }
+
+// FVIS-DEFAULT: declare amdgpu_kernel void @ext_kern()
+// FVIS-PROTECTED: declare protected amdgpu_kernel void @ext_kern()
+// FVIS-HIDDEN: declare protected amdgpu_kernel void @ext_kern()
+
+// FVIS-DEFAULT: declare protected amdgpu_kernel void @ext_kern_hidden()
+// FVIS-PROTECTED: declare protected amdgpu_kernel void @ext_kern_hidden()
+// FVIS-HIDDEN: declare protected amdgpu_kernel void @ext_kern_hidden()
+
+// FVIS-DEFAULT: declare protected amdgpu_kernel void @ext_kern_protected()
+// FVIS-PROTECTED: declare protected amdgpu_kernel void @ext_kern_protected()
+// FVIS-HIDDEN: declare protected amdgpu_kernel void @ext_kern_protected()
+
+// FVIS-DEFAULT: declare amdgpu_kernel void @ext_kern_default()
+// FVIS-PROTECTED: declare amdgpu_kernel void @ext_kern_default()
+// FVIS-HIDDEN: declare amdgpu_kernel void @ext_kern_default()
+
+
+// FVIS-DEFAULT: declare void @ext_func()
+// FVIS-PROTECTED: declare protected void @ext_func()
+// FVIS-HIDDEN: declare hidden void @ext_func()
+
+// FVIS-DEFAULT: declare hidden void @ext_func_hidden()
+// FVIS-PROTECTED: declare hidden void @ext_func_hidden()
+// FVIS-HIDDEN: declare hidden void @ext_func_hidden()
+
+// FVIS-DEFAULT: declare protected void @ext_func_protected()
+// FVIS-PROTECTED: declare protected void @ext_func_protected()
+// FVIS-HIDDEN: declare protected void @ext_func_protected()
+
+// FVIS-DEFAULT: declare void @ext_func_default()
+// FVIS-PROTECTED: declare void @ext_func_default()
+// FVIS-HIDDEN: declare void @ext_func_default()
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -1558,12 +1558,8 @@
 
   const auto *FD = cast(GD.getDecl());
 
-  if (!IsIncompleteFunction) {
+  if (!IsIncompleteFunction)
 SetLLVMFunctionAttributes(GD, getTypes().arrangeGlobalDeclaration(GD), F);
-// Setup target-specific attributes.
-if (F->isDeclaration())
-  getTargetCodeGenInfo().setTargetAttributes(FD, F, *this);
-  }
 
   // Add the Returned attribute for "this", except for iOS 5 and earlier
   // where substantial code, including the libstdc++ dylib, was compiled with
@@ -1583,6 +1579,10 @@
   setLinkageForGV(F, FD);
   setGVProperties(F, FD);
 
+  // Setup target-specific attributes.
+  if (!IsIncompleteFunction && F->isDeclaration())
+getTargetCodeGenInfo().setTargetAttributes(FD, F, *this);
+
   if (const auto *CSA = FD->getAttr())
 F->setSection(CSA->getName());
   else if (const auto *SA = FD->getAttr())


Index: test/CodeGenOpenCL/visibility.cl
===
--- test/CodeGenOpenCL/visibility.cl
+++ test/CodeGenOpenCL/visibility.cl
@@ -72,6 +72,57 @@
 // FVIS-HIDDEN: define void @func_default()
 __attribute__((visibility("default"))) void func_default() {}
 
+extern kernel void ext_kern();
+__attribute__((visibility("hidden"))) extern kernel void ext_kern_hidden();
+__attribute__((visibility("protected"))) extern kernel void ext_kern_protected();
+__attribute__((visibility("default"))) extern kernel void ext_kern_default();
+
+extern void ext_func();
+__attribute__((visibility("hidden"))) extern void ext_func_hidden();
+__attribute__((visibility("protected"))) extern void ext_func_protected();
+__attribu

[PATCH] D46421: [analyzer][CrossTU] Extend CTU to VarDecls with initializer

2019-04-22 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

Looks good, thanks. Can you commit this or do you need someone to commit it on 
your behalf?


Repository:
  rC Clang

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

https://reviews.llvm.org/D46421



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


[PATCH] D59465: [analyzer] Add example plugin for checker option handling

2019-04-22 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus updated this revision to Diff 196079.
Szelethus added a comment.

- Move the existing plugin to `test/`
- Implement the new plugin in there also


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

https://reviews.llvm.org/D59465

Files:
  examples/CMakeLists.txt
  examples/analyzer-plugin/CMakeLists.txt
  examples/analyzer-plugin/MainCallChecker.cpp
  examples/analyzer-plugin/SampleAnalyzerPlugin.exports
  test/Analysis/checker-plugins.c
  test/Analysis/lit.local.cfg
  test/Analysis/plugins/CMakeLists.txt
  test/Analysis/plugins/CheckerDependencyHandling/CMakeLists.txt
  test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandling.cpp
  
test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandlingAnalyzerPlugin.exports
  test/Analysis/plugins/SampleAnalyzer/CMakeLists.txt
  test/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp
  test/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports
  test/CMakeLists.txt

Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -137,13 +137,15 @@
   # check-all would launch those tests via check-clang.
   set(EXCLUDE_FROM_ALL ON)
 
+  add_subdirectory(Analysis/plugins)
+  list(APPEND CLANG_TEST_DEPS clang-analyzer-plugin)
+
   add_lit_testsuite(check-clang-analyzer "Running the Clang analyzer tests"
 ${CMAKE_CURRENT_BINARY_DIR}/Analysis
 PARAMS ${ANALYZER_TEST_PARAMS}
 DEPENDS ${CLANG_TEST_DEPS})
   set_target_properties(check-clang-analyzer PROPERTIES FOLDER "Clang tests")
 
-
   if (LLVM_WITH_Z3)
 add_lit_testsuite(check-clang-analyzer-z3 "Running the Clang analyzer tests, using Z3 as a solver"
   ${CMAKE_CURRENT_BINARY_DIR}/Analysis
Index: test/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports
===
--- /dev/null
+++ test/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports
@@ -0,0 +1,2 @@
+clang_registerCheckers
+clang_analyzerAPIVersionString
Index: test/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp
===
--- test/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp
+++ test/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp
@@ -1,13 +1,13 @@
-#include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
-#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
 
 using namespace clang;
 using namespace ento;
 
 namespace {
-class MainCallChecker : public Checker < check::PreStmt > {
+class MainCallChecker : public Checker> {
   mutable std::unique_ptr BT;
 
 public:
@@ -15,7 +15,8 @@
 };
 } // end anonymous namespace
 
-void MainCallChecker::checkPreStmt(const CallExpr *CE, CheckerContext &C) const {
+void MainCallChecker::checkPreStmt(const CallExpr *CE,
+   CheckerContext &C) const {
   const Expr *Callee = CE->getCallee();
   const FunctionDecl *FD = C.getSVal(Callee).getAsFunctionDecl();
 
@@ -24,7 +25,7 @@
 
   // Get the name of the callee.
   IdentifierInfo *II = FD->getIdentifier();
-  if (!II)   // if no identifier, not a simple C function
+  if (!II) // if no identifier, not a simple C function
 return;
 
   if (II->isStr("main")) {
@@ -43,12 +44,11 @@
 }
 
 // Register plugin!
-extern "C"
-void clang_registerCheckers (CheckerRegistry ®istry) {
+extern "C" void clang_registerCheckers(CheckerRegistry ®istry) {
   registry.addChecker(
   "example.MainCallChecker", "Disallows calls to functions called main",
   "");
 }
 
-extern "C"
-const char clang_analyzerAPIVersionString[] = CLANG_ANALYZER_API_VERSION_STRING;
+extern "C" const char clang_analyzerAPIVersionString[] =
+CLANG_ANALYZER_API_VERSION_STRING;
Index: test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandling.cpp
===
--- /dev/null
+++ test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandling.cpp
@@ -0,0 +1,28 @@
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
+
+using namespace clang;
+using namespace ento;
+
+namespace {
+struct Dependency : public Checker {
+  void checkBeginFunction(CheckerContext &Ctx) const {}
+};
+struct DependendentChecker : public Checker {
+  void checkBeginFunction(CheckerContext &Ctx) const {}
+};
+} // end anonymous namespace
+
+// Register plugin!
+extern "C" void clang_registerCheckers(CheckerRegistry ®istry) {
+  registry.addChecker("example.Dependency", "", "");
+  registry.addChecker("example.Dependende

[PATCH] D59464: [analyzer] Add an example plugin for checker dependency handling

2019-04-22 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus updated this revision to Diff 196083.
Szelethus added a comment.

- Move the existing plugin to `test/`
- Implement the new plugin in there also


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

https://reviews.llvm.org/D59464

Files:
  examples/CMakeLists.txt
  examples/analyzer-plugin/CMakeLists.txt
  examples/analyzer-plugin/MainCallChecker.cpp
  examples/analyzer-plugin/SampleAnalyzerPlugin.exports
  test/Analysis/checker-plugins.c
  test/Analysis/lit.local.cfg
  test/Analysis/plugins/CMakeLists.txt
  test/Analysis/plugins/CheckerDependencyHandling/CMakeLists.txt
  test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandling.cpp
  
test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandlingAnalyzerPlugin.exports
  test/Analysis/plugins/SampleAnalyzer/CMakeLists.txt
  test/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp
  test/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports
  test/CMakeLists.txt

Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -137,13 +137,15 @@
   # check-all would launch those tests via check-clang.
   set(EXCLUDE_FROM_ALL ON)
 
+  add_subdirectory(Analysis/plugins)
+  list(APPEND CLANG_TEST_DEPS clang-analyzer-plugin)
+
   add_lit_testsuite(check-clang-analyzer "Running the Clang analyzer tests"
 ${CMAKE_CURRENT_BINARY_DIR}/Analysis
 PARAMS ${ANALYZER_TEST_PARAMS}
 DEPENDS ${CLANG_TEST_DEPS})
   set_target_properties(check-clang-analyzer PROPERTIES FOLDER "Clang tests")
 
-
   if (LLVM_WITH_Z3)
 add_lit_testsuite(check-clang-analyzer-z3 "Running the Clang analyzer tests, using Z3 as a solver"
   ${CMAKE_CURRENT_BINARY_DIR}/Analysis
Index: test/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports
===
--- /dev/null
+++ test/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports
@@ -0,0 +1,2 @@
+clang_registerCheckers
+clang_analyzerAPIVersionString
Index: test/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp
===
--- test/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp
+++ test/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp
@@ -1,13 +1,13 @@
-#include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
-#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
 
 using namespace clang;
 using namespace ento;
 
 namespace {
-class MainCallChecker : public Checker < check::PreStmt > {
+class MainCallChecker : public Checker> {
   mutable std::unique_ptr BT;
 
 public:
@@ -15,7 +15,8 @@
 };
 } // end anonymous namespace
 
-void MainCallChecker::checkPreStmt(const CallExpr *CE, CheckerContext &C) const {
+void MainCallChecker::checkPreStmt(const CallExpr *CE,
+   CheckerContext &C) const {
   const Expr *Callee = CE->getCallee();
   const FunctionDecl *FD = C.getSVal(Callee).getAsFunctionDecl();
 
@@ -24,7 +25,7 @@
 
   // Get the name of the callee.
   IdentifierInfo *II = FD->getIdentifier();
-  if (!II)   // if no identifier, not a simple C function
+  if (!II) // if no identifier, not a simple C function
 return;
 
   if (II->isStr("main")) {
@@ -43,12 +44,11 @@
 }
 
 // Register plugin!
-extern "C"
-void clang_registerCheckers (CheckerRegistry ®istry) {
+extern "C" void clang_registerCheckers(CheckerRegistry ®istry) {
   registry.addChecker(
   "example.MainCallChecker", "Disallows calls to functions called main",
   "");
 }
 
-extern "C"
-const char clang_analyzerAPIVersionString[] = CLANG_ANALYZER_API_VERSION_STRING;
+extern "C" const char clang_analyzerAPIVersionString[] =
+CLANG_ANALYZER_API_VERSION_STRING;
Index: test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandling.cpp
===
--- /dev/null
+++ test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandling.cpp
@@ -0,0 +1,28 @@
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
+
+using namespace clang;
+using namespace ento;
+
+namespace {
+struct Dependency : public Checker {
+  void checkBeginFunction(CheckerContext &Ctx) const {}
+};
+struct DependendentChecker : public Checker {
+  void checkBeginFunction(CheckerContext &Ctx) const {}
+};
+} // end anonymous namespace
+
+// Register plugin!
+extern "C" void clang_registerCheckers(CheckerRegistry ®istry) {
+  registry.addChecker("example.Dependency", "", "");
+  registry.addChecker("example.Dependende

[PATCH] D59465: [analyzer] Add example plugin for checker option handling

2019-04-22 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus updated this revision to Diff 196080.
Szelethus added a comment.

Accidentally uploaded the wrong diff. Rebase on top of D59464 
.


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

https://reviews.llvm.org/D59465

Files:
  examples/StaticAnalyzer/CMakeLists.txt
  examples/StaticAnalyzer/OptionHandlingPlugin/CMakeLists.txt
  examples/StaticAnalyzer/OptionHandlingPlugin/CheckerOptionHandling.cpp
  
examples/StaticAnalyzer/OptionHandlingPlugin/OptionHandlingAnalyzerPlugin.exports
  test/Analysis/checker-plugins.c

Index: test/Analysis/checker-plugins.c
===
--- test/Analysis/checker-plugins.c
+++ test/Analysis/checker-plugins.c
@@ -30,3 +30,18 @@
 
 // CHECK-IMPLICITLY-DISABLED-NOT: example.Dependency
 // CHECK-IMPLICITLY-DISABLED-NOT: example.DependendentChecker
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -load %llvmshlibdir/OptionHandlingAnalyzerPlugin%pluginext\
+// RUN:   -analyzer-checker=example.MyChecker \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-CHECKER-OPTION-OUTPUT
+
+// CHECK-CHECKER-OPTION-OUTPUT: Example option is set to false
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -load %llvmshlibdir/OptionHandlingAnalyzerPlugin%pluginext\
+// RUN:   -analyzer-checker=example.MyChecker \
+// RUN:   -analyzer-config example.MyChecker:ExampleOption=true \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-CHECKER-OPTION-OUTPUT-TRUE
+
+// CHECK-CHECKER-OPTION-OUTPUT-TRUE: Example option is set to true
Index: examples/StaticAnalyzer/OptionHandlingPlugin/OptionHandlingAnalyzerPlugin.exports
===
--- /dev/null
+++ examples/StaticAnalyzer/OptionHandlingPlugin/OptionHandlingAnalyzerPlugin.exports
@@ -0,0 +1,2 @@
+clang_registerCheckers
+clang_analyzerAPIVersionString
Index: examples/StaticAnalyzer/OptionHandlingPlugin/CheckerOptionHandling.cpp
===
--- /dev/null
+++ examples/StaticAnalyzer/OptionHandlingPlugin/CheckerOptionHandling.cpp
@@ -0,0 +1,42 @@
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
+
+using namespace clang;
+using namespace ento;
+
+namespace {
+struct MyChecker : public Checker {
+  void checkBeginFunction(CheckerContext &Ctx) const {}
+};
+
+void registerMyChecker(CheckerManager &Mgr) {
+  MyChecker *Checker = Mgr.registerChecker();
+  llvm::outs() << "Example option is set to "
+   << (Mgr.getAnalyzerOptions().getCheckerBooleanOption(
+   Checker, "ExampleOption", false)
+   ? "true"
+   : "false")
+   << '\n';
+}
+
+bool shouldRegisterMyChecker(const LangOptions &LO) { return true; }
+
+} // end anonymous namespace
+
+// Register plugin!
+extern "C" void clang_registerCheckers(CheckerRegistry ®istry) {
+  registry.addChecker(registerMyChecker, shouldRegisterMyChecker,
+  "example.MyChecker", "Example Description",
+  "example.mychecker.documentation.nonexistent.html");
+
+  registry.addCheckerOption(/*OptionType*/ "bool",
+/*CheckerFullName*/ "example.MyChecker",
+/*OptionName*/ "ExampleOption",
+/*DefaultValStr*/ "false",
+/*Description*/ "This is an example checker opt.");
+}
+
+extern "C" const char clang_analyzerAPIVersionString[] =
+CLANG_ANALYZER_API_VERSION_STRING;
Index: examples/StaticAnalyzer/OptionHandlingPlugin/CMakeLists.txt
===
--- /dev/null
+++ examples/StaticAnalyzer/OptionHandlingPlugin/CMakeLists.txt
@@ -0,0 +1,11 @@
+set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/OptionHandlingAnalyzerPlugin.exports)
+add_llvm_library(OptionHandlingAnalyzerPlugin MODULE CheckerOptionHandling.cpp PLUGIN_TOOL clang)
+
+if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
+  target_link_libraries(OptionHandlingAnalyzerPlugin PRIVATE
+clangAnalysis
+clangAST
+clangStaticAnalyzerCore
+LLVMSupport
+)
+endif()
Index: examples/StaticAnalyzer/CMakeLists.txt
===
--- examples/StaticAnalyzer/CMakeLists.txt
+++ examples/StaticAnalyzer/CMakeLists.txt
@@ -1,2 +1,3 @@
 add_subdirectory(SampleAnalyzerPlugin)
 add_subdirectory(CheckerDependencyHandlingPlugin)
+add_subdirectory(OptionHandlingPlugin)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59802: [clang-tidy] Add new checker: llvm-prefer-isa-or-dyn-cast-in-conditionals

2019-04-22 Thread Don Hinton via Phabricator via cfe-commits
hintonda added a comment.

@aaron.ballman, I just ran it over llvm/lib, including all in-tree headers, and 
it seems to work fine.  However, it did miss this one:

- if (V && isa(V) && (EntInst = cast(V)) &&

+if (isa_and_nonnull(V) && (EntInst = 
cast(V)) &&

It got the first, but not the second.  Not sure how to pick that one up.  Even 
ran it a second time on just that file, but still didn't pick it up.  Any ideas?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59802



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


[PATCH] D58033: Add option for emitting dbg info for call site parameters

2019-04-22 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a comment.

Is there some kind of testcase?


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

https://reviews.llvm.org/D58033



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


[PATCH] D59509: Make static constructors + destructors minsize + cold (except for in -O0)

2019-04-22 Thread Jessica Paquette via Phabricator via cfe-commits
paquette updated this revision to Diff 196085.
paquette added a comment.

Made the test less fragile by splitting the WITHOUT-NOT into three lines.

(Thanks for the suggestion!)


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

https://reviews.llvm.org/D59509

Files:
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/test/CodeGen/address-safety-attr.cpp
  clang/test/CodeGen/static-attr.cpp

Index: clang/test/CodeGen/static-attr.cpp
===
--- /dev/null
+++ clang/test/CodeGen/static-attr.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -disable-O0-optnone -emit-llvm %s -o - | FileCheck -check-prefix=WITH %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm %s -o - | FileCheck -check-prefix=WITHOUT %s
+
+// WITHOUT-NOT: cold
+// WITHOUT-NOT: minsize
+// WITHOUT-NOT: noinline
+// WITH: define internal void @__cxx_global_var_init() [[ATTR:#[0-9]]]
+
+extern int
+baz(void);
+
+int foo(void) {
+  return baz();
+}
+
+static struct StaticInitializer {
+  StaticInitializer() {
+foo();
+  }
+} I;
+
+int bar() {
+  StaticInitializer I;
+  return 0;
+}
+
+// WITH: attributes [[ATTR]] = { {{.*}}cold minsize noinline nounwind optsize{{.*}} }
Index: clang/test/CodeGen/address-safety-attr.cpp
===
--- clang/test/CodeGen/address-safety-attr.cpp
+++ clang/test/CodeGen/address-safety-attr.cpp
@@ -26,17 +26,16 @@
 
 // Check that functions generated for global in different source file are
 // not blacklisted.
-// WITHOUT: @__cxx_global_var_init{{.*}}[[NOATTR:#[0-9]+]]
-// WITHOUT: @__cxx_global_array_dtor{{.*}}[[NOATTR]]
-// BLFILE: @__cxx_global_var_init{{.*}}[[WITH:#[0-9]+]]
-// BLFILE: @__cxx_global_array_dtor{{.*}}[[WITH]]
-// BLFUNC: @__cxx_global_var_init{{.*}}[[WITH:#[0-9]+]]
-// BLFUNC: @__cxx_global_array_dtor{{.*}}[[WITH]]
-// ASAN: @__cxx_global_var_init{{.*}}[[WITH:#[0-9]+]]
-// ASAN: @__cxx_global_array_dtor{{.*}}[[WITH]]
-
-
-// WITHOUT:  NoAddressSafety1{{.*}}) [[NOATTR]]
+// WITHOUT: @__cxx_global_var_init{{.*}}[[NOATTR_STATIC:#[0-9]+]]
+// WITHOUT: @__cxx_global_array_dtor{{.*}}[[NOATTR_STATIC]]
+// BLFILE: @__cxx_global_var_init{{.*}}[[WITH_STATIC:#[0-9]+]]
+// BLFILE: @__cxx_global_array_dtor{{.*}}[[WITH_STATIC]]
+// BLFUNC: @__cxx_global_var_init{{.*}}[[WITH_STATIC:#[0-9]+]]
+// BLFUNC: @__cxx_global_array_dtor{{.*}}[[WITH_STATIC]]
+// ASAN: @__cxx_global_var_init{{.*}}[[WITH_STATIC:#[0-9]+]]
+// ASAN: @__cxx_global_array_dtor{{.*}}[[WITH_STATIC]]
+
+// WITHOUT:  NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]]
 // BLFILE:  NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]]
 // BLFUNC:  NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]]
 // ASAN:  NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]]
@@ -138,18 +137,23 @@
 // Check that __cxx_global_var_init* get the sanitize_address attribute.
 int global1 = 0;
 int global2 = *(int*)((char*)&global1+1);
-// WITHOUT: @__cxx_global_var_init{{.*}}[[NOATTR]]
-// BLFILE: @__cxx_global_var_init{{.*}}[[NOATTR:#[0-9]+]]
-// BLFUNC: @__cxx_global_var_init{{.*}}[[WITH]]
-// ASAN: @__cxx_global_var_init{{.*}}[[WITH]]
+// WITHOUT: @__cxx_global_var_init{{.*}}[[NOATTR_STATIC]]
+// BLFILE: @__cxx_global_var_init{{.*}}[[NOATTR_STATIC:#[0-9]+]]
+// BLFUNC: @__cxx_global_var_init{{.*}}[[WITH_STATIC]]
+// ASAN: @__cxx_global_var_init{{.*}}[[WITH_STATIC]]
 
 // WITHOUT: attributes [[NOATTR]] = { noinline nounwind{{.*}} }
+// WITHOUT: attributes [[NOATTR_STATIC]] = { cold minsize noinline nounwind optsize{{.*}} }
 
 // BLFILE: attributes [[WITH]] = { noinline nounwind sanitize_address{{.*}} }
+// BLFILE: attributes [[WITH_STATIC]] = { cold minsize noinline nounwind optsize sanitize_address{{.*}} }
 // BLFILE: attributes [[NOATTR]] = { noinline nounwind{{.*}} }
+// BLFILE: attributes [[NOATTR_STATIC]] = { cold minsize noinline nounwind optsize{{.*}} }
 
 // BLFUNC: attributes [[WITH]] = { noinline nounwind sanitize_address{{.*}} }
+// BLFUNC: attributes [[WITH_STATIC]] = { cold minsize noinline nounwind optsize sanitize_address{{.*}} }
 // BLFUNC: attributes [[NOATTR]] = { noinline nounwind{{.*}} }
 
 // ASAN: attributes [[WITH]] = { noinline nounwind sanitize_address{{.*}} }
+// ASAN: attributes [[WITH_STATIC]] = { cold minsize noinline nounwind optsize sanitize_address{{.*}} }
 // ASAN: attributes [[NOATTR]] = { noinline nounwind{{.*}} }
Index: clang/lib/CodeGen/CGDeclCXX.cpp
===
--- clang/lib/CodeGen/CGDeclCXX.cpp
+++ clang/lib/CodeGen/CGDeclCXX.cpp
@@ -391,6 +391,15 @@
   if (getCodeGenOpts().BranchTargetEnforcement)
 Fn->addFnAttr("branch-target-enforcement");
 
+  // If we're optimizing, then we can make these small, since they're only ever
+  // run once.
+  if (getCodeGenOpts().DisableO0ImplyOptNone ||
+  getCodeGenOpts().OptimizationLevel != 0) {
+Fn->addFnAttr(llvm::Attribute::OptimizeForSize);
+Fn->addFnAttr(llvm::Attribute::MinSize);
+Fn->addFnAttr(ll

[PATCH] D60920: [ASTMatchers] Introduce Objective-C matchers `isClassMessage`, `isClassMethod`, and `isInstanceMethod`

2019-04-22 Thread Michael Wyman via Phabricator via cfe-commits
mwyman accepted this revision.
mwyman added a comment.

Thanks. I don't believe I have commit access, so I'll need someone to commit 
this to trunk.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60920



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


[PATCH] D38061: Set AnonymousTagLocations false for ASTContext if column info is expected not to be used

2019-04-22 Thread Taewook Oh via Phabricator via cfe-commits
twoh added a subscriber: wenlei.
twoh added a comment.
Herald added a subscriber: dexonsmith.
Herald added a project: clang.

Hello @rsmith, @wenlei and I took another look at this, and we couldn't find 
any use of `AnonymousTagLocations` outside of debug info. If that's actually 
the case, wouldn't it make sense to have `DebugColumnInfo` to control the field 
even if `AnonymousTagLocations` the part of generic printing policy?


Repository:
  rC Clang

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

https://reviews.llvm.org/D38061



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


[PATCH] D41569: [Concepts] Constraint enforcement and diagnostics

2019-04-22 Thread Saar Raz via Phabricator via cfe-commits
saar.raz updated this revision to Diff 196091.
saar.raz added a comment.

Adjusted to changes in getAssociatedConstraints interface


Repository:
  rC Clang

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

https://reviews.llvm.org/D41569

Files:
  include/clang/AST/ExprCXX.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  include/clang/Sema/SemaConcept.h
  include/clang/Sema/TemplateDeduction.h
  lib/AST/ExprCXX.cpp
  lib/Sema/SemaConcept.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaOverload.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateDeduction.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  test/CXX/concepts-ts/expr/expr.prim/expr.prim.id/p3.cpp
  
test/CXX/concepts-ts/temp/temp.constr/temp.constr.constr/function-templates.cpp
  
test/CXX/concepts-ts/temp/temp.constr/temp.constr.constr/non-function-templates.cpp
  
test/CXX/concepts-ts/temp/temp.constr/temp.constr.constr/partial-specializations.cpp

Index: test/CXX/concepts-ts/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
===
--- /dev/null
+++ test/CXX/concepts-ts/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -std=c++2a -fconcepts-ts -x c++ -verify %s
+
+namespace class_templates
+{
+  template requires sizeof(T) >= 4 // expected-note {{because 'sizeof(char) >= 4' (1 >= 4) evaluated to false}}
+  struct is_same { static constexpr bool value = false; };
+
+  template requires sizeof(T*) >= 4 && sizeof(T) >= 4
+  struct is_same { static constexpr bool value = true; };
+
+  static_assert(!is_same::value);
+  static_assert(!is_same::value);
+  static_assert(is_same::value);
+  static_assert(is_same::value); // expected-error {{constraints not satisfied for class template 'is_same' [with T = char, U = char]}}
+
+  template
+  struct A { using type = typename T::type; }; // expected-error{{type 'int *' cannot be used prior to '::' because it has no members}}
+
+  template
+  struct B {};
+
+  template requires A::type // expected-note{{in instantiation of template class 'class_templates::A' requested here}}
+   // expected-note@-1{{while substituting template arguments into constraint expression here}}
+  struct B {};
+
+  template requires T{} // expected-error{{atomic constraint must be of type 'bool' (found 'int')}}
+  struct B {};
+
+  static_assert((B{}, true)); // expected-note{{while checking constraint satisfaction for class template partial specialization 'B' required here}}
+  // expected-note@-1{{while checking constraint satisfaction for class template partial specialization 'B' required here}}
+  // expected-note@-2{{during template argument deduction for class template partial specialization 'B' [with T = int *]}}
+  // expected-note@-3{{during template argument deduction for class template partial specialization 'B' [with T = int]}}
+  // expected-note@-4 2{{in instantiation of template class 'class_templates::B' requested here}}
+}
+
+namespace variable_templates
+{
+  template requires sizeof(T) >= 4
+  constexpr bool is_same_v = false;
+
+  template requires sizeof(T*) >= 4 && sizeof(T) >= 4
+  constexpr bool is_same_v = true;
+
+  static_assert(!is_same_v);
+  static_assert(!is_same_v);
+  static_assert(is_same_v);
+
+  template
+  struct A { using type = typename T::type; }; // expected-error{{type 'int *' cannot be used prior to '::' because it has no members}}
+
+  template
+  constexpr bool v1 = false;
+
+  template requires A::type // expected-note{{in instantiation of template class 'variable_templates::A' requested here}}
+   // expected-note@-1{{while substituting template arguments into constraint expression here}}
+  constexpr bool v1 = true;
+
+  template requires T{} // expected-error{{atomic constraint must be of type 'bool' (found 'int')}}
+  constexpr bool v1 = true;
+
+  static_assert(v1); // expected-note{{while checking constraint satisfaction for variable template partial specialization 'v1' required here}}
+  // expected-note@-1{{while checking constraint satisfaction for variable template partial specialization 'v1' required here}}
+  // expected-note@-2{{during template argument deduction for variable template partial specialization 'v1' [with T = int *]}}
+  // expected-note@-3{{during template argument deduction for variable template partial specialization 'v1' [with T = int]}}
+  // expected-error@-4{{static_assert failed due to requirement 'v1'}}
+
+}
\ No newline at end of file
Index: test/CXX/concepts-ts/temp/temp.constr/temp.constr.constr/non-function-templates.cpp
===
--- /dev/null
+++ test/CXX/concepts-ts/temp/temp.constr/temp.constr.constr/non-function-templates.cpp

r358904 - [ASTMatchers] Introduce Objective-C matchers `isClassMessage`, `isClassMethod`, and `isInstanceMethod`

2019-04-22 Thread Ben Hamilton via cfe-commits
Author: benhamilton
Date: Mon Apr 22 10:54:11 2019
New Revision: 358904

URL: http://llvm.org/viewvc/llvm-project?rev=358904&view=rev
Log:
[ASTMatchers] Introduce Objective-C matchers `isClassMessage`, `isClassMethod`, 
and `isInstanceMethod`

Summary:
isClassMessage is an equivalent to isInstanceMessage for ObjCMessageExpr, but 
matches message expressions to classes.

isClassMethod and isInstanceMethod check whether a method declaration (or 
definition) is for a class method or instance method (respectively).

Contributed by @mywman!

Reviewers: benhamilton, klimek, mwyman

Reviewed By: benhamilton, mwyman

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=358904&r1=358903&r2=358904&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Mon Apr 22 10:54:11 2019
@@ -3567,11 +3567,24 @@ represent an error condition in the tree
 
 
 
+MatcherObjCMessageExpr>isClassMessage
+Returns true when 
the Objective-C message is sent to a class.
+
+Example
+matcher = objcMessageExpr(isClassMessage())
+matches
+  [NSString stringWithFormat:@"format"];
+but not
+  NSString *x = @"hello";
+  [x containsString:@"h"];
+
+
+
 MatcherObjCMessageExpr>isInstanceMessage
 Returns true when 
the Objective-C message is sent to an instance.
 
 Example
-matcher = objcMessagaeExpr(isInstanceMessage())
+matcher = objcMessageExpr(isInstanceMessage())
 matches
   NSString *x = @"hello";
   [x containsString:@"h"];
@@ -3580,6 +3593,30 @@ but not
 
 
 
+MatcherObjCMethodDecl>isClassMethod
+Returns true when the 
Objective-C method declaration is a class method.
+
+Example
+matcher = objcMethodDecl(isClassMethod())
+matches
+  @interface I + (void)foo; @end
+but not
+  @interface I - (void)bar; @end
+
+
+
+MatcherObjCMethodDecl>isInstanceMethod
+Returns true when 
the Objective-C method declaration is an instance method.
+
+Example
+matcher = objcMethodDecl(isInstanceMethod())
+matches
+  @interface I - (void)bar; @end
+but not
+  @interface I + (void)foo; @end
+
+
+
 MatcherObjCMessageExpr>matchesSelectorstd::string 
RegExp
 Matches ObjC 
selectors whose name contains
 a substring matched by the given RegExp.

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=358904&r1=358903&r2=358904&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Mon Apr 22 10:54:11 2019
@@ -2938,10 +2938,59 @@ AST_MATCHER_P(ObjCMessageExpr, hasReceiv
   return InnerMatcher.matches(TypeDecl, Finder, Builder);
 }
 
+/// Returns true when the Objective-C method declaration is a class method.
+///
+/// Example
+/// matcher = objcMethodDecl(isClassMethod())
+/// matches
+/// \code
+/// @interface I + (void)foo; @end
+/// \endcode
+/// but not
+/// \code
+/// @interface I - (void)bar; @end
+/// \endcode
+AST_MATCHER(ObjCMethodDecl, isClassMethod) {
+  return Node.isClassMethod();
+}
+
+/// Returns true when the Objective-C method declaration is an instance method.
+///
+/// Example
+/// matcher = objcMethodDecl(isInstanceMethod())
+/// matches
+/// \code
+/// @interface I - (void)bar; @end
+/// \endcode
+/// but not
+/// \code
+/// @interface I + (void)foo; @end
+/// \endcode
+AST_MATCHER(ObjCMethodDecl, isInstanceMethod) {
+  return Node.isInstanceMethod();
+}
+
+/// Returns true when the Objective-C message is sent to a class.
+///
+/// Example
+/// matcher = objcMessageExpr(isClassMessage())
+/// matches
+/// \code
+///   [NSString stringWithFormat:@"format"];
+/// \endcode
+/// but not
+/// \code
+///   NSString *x = @"hello";
+///   [x containsString:@"h"];
+/// \endcode
+AST_MATCHER(ObjCMessageExpr, isClassMessage) {
+  return Node.isClassMessage();
+}
+
 /// Returns true when the Objective-C message is sent to an instance.
 ///
 /// Example
-/// matcher = objcMessagaeExpr(isInstanceMessage())
+/// matcher = objcMessageExpr(isInstanceMessage())
 /// matches
 /// \code
 ///   NSString *x = @"hello";

Modified: cfe/trunk/li

[PATCH] D60920: [ASTMatchers] Introduce Objective-C matchers `isClassMessage`, `isClassMethod`, and `isInstanceMethod`

2019-04-22 Thread Ben Hamilton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC358904: [ASTMatchers] Introduce Objective-C matchers 
`isClassMessage`, `isClassMethod`… (authored by benhamilton, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D60920?vs=195905&id=196095#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D60920

Files:
  docs/LibASTMatchersReference.html
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -344,6 +344,8 @@
   REGISTER_MATCHER(isBitField);
   REGISTER_MATCHER(isCatchAll);
   REGISTER_MATCHER(isClass);
+  REGISTER_MATCHER(isClassMessage);
+  REGISTER_MATCHER(isClassMethod);
   REGISTER_MATCHER(isConst);
   REGISTER_MATCHER(isConstQualified);
   REGISTER_MATCHER(isConstexpr);
@@ -367,6 +369,7 @@
   REGISTER_MATCHER(isInTemplateInstantiation);
   REGISTER_MATCHER(isInline);
   REGISTER_MATCHER(isInstanceMessage);
+  REGISTER_MATCHER(isInstanceMethod);
   REGISTER_MATCHER(isInstantiated);
   REGISTER_MATCHER(isInstantiationDependent);
   REGISTER_MATCHER(isInteger);
Index: unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -454,6 +454,20 @@
   objcMessageExpr(hasReceiver(declRefExpr(to(varDecl(hasName("x";
 }
 
+TEST(Matcher, isClassMessage) {
+  EXPECT_TRUE(matchesObjC(
+  "@interface NSString +(NSString *) stringWithFormat; @end "
+  "void f() { [NSString stringWithFormat]; }",
+  objcMessageExpr(isClassMessage(;
+
+  EXPECT_FALSE(matchesObjC(
+  "@interface NSString @end "
+  "void f(NSString *x) {"
+  "[x containsString];"
+  "}",
+  objcMessageExpr(isClassMessage(;
+}
+
 TEST(Matcher, isInstanceMessage) {
   EXPECT_TRUE(matchesObjC(
   "@interface NSString @end "
@@ -469,6 +483,46 @@
 
 }
 
+TEST(Matcher, isClassMethod) {
+  EXPECT_TRUE(matchesObjC(
+"@interface Bar + (void)bar; @end",
+objcMethodDecl(isClassMethod(;
+
+  EXPECT_TRUE(matchesObjC(
+"@interface Bar @end"
+"@implementation Bar + (void)bar {} @end",
+objcMethodDecl(isClassMethod(;
+
+  EXPECT_FALSE(matchesObjC(
+"@interface Foo - (void)foo; @end",
+objcMethodDecl(isClassMethod(;
+
+  EXPECT_FALSE(matchesObjC(
+"@interface Foo @end "
+"@implementation Foo - (void)foo {} @end",
+objcMethodDecl(isClassMethod(;
+}
+
+TEST(Matcher, isInstanceMethod) {
+  EXPECT_TRUE(matchesObjC(
+"@interface Foo - (void)foo; @end",
+objcMethodDecl(isInstanceMethod(;
+
+  EXPECT_TRUE(matchesObjC(
+"@interface Foo @end "
+"@implementation Foo - (void)foo {} @end",
+objcMethodDecl(isInstanceMethod(;
+
+  EXPECT_FALSE(matchesObjC(
+"@interface Bar + (void)bar; @end",
+objcMethodDecl(isInstanceMethod(;
+
+  EXPECT_FALSE(matchesObjC(
+"@interface Bar @end"
+"@implementation Bar + (void)bar {} @end",
+objcMethodDecl(isInstanceMethod(;
+}
+
 TEST(MatcherCXXMemberCallExpr, On) {
   auto Snippet1 = R"cc(
 struct Y {
Index: docs/LibASTMatchersReference.html
===
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ -3567,11 +3567,24 @@
 
 
 
+MatcherObjCMessageExpr>isClassMessage
+Returns true when the Objective-C message is sent to a class.
+
+Example
+matcher = objcMessageExpr(isClassMessage())
+matches
+  [NSString stringWithFormat:@"format"];
+but not
+  NSString *x = @"hello";
+  [x containsString:@"h"];
+
+
+
 MatcherObjCMessageExpr>isInstanceMessage
 Returns true when the Objective-C message is sent to an instance.
 
 Example
-matcher = objcMessagaeExpr(isInstanceMessage())
+matcher = objcMessageExpr(isInstanceMessage())
 matches
   NSString *x = @"hello";
   [x containsString:@"h"];
@@ -3580,6 +3593,30 @@
 
 
 
+MatcherObjCMethodDecl>isClassMethod
+Returns true when the Objective-C method declaration is a class method.
+
+Example
+matcher = objcMethodDecl(isClassMethod())
+matches
+  @interface I + (void)foo; @end
+but not
+  @interface I - (void)bar; @end
+
+
+
+MatcherObjCMethodDecl>isInstanceMethod
+Returns true when the Objective-C method declaration is an instance method.
+
+Example
+matcher = objcMethodDecl(isInstanceMethod())
+matches
+  @interface I

[PATCH] D60930: [codeview] Fix symbol names for dynamic initializers and atexit stubs

2019-04-22 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

Looks good to me.  We are basically de-mangled name for those __E  initialize 
global’s  function and __F destroy global's function.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60930



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-22 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi created this revision.
Herald added subscribers: cfe-commits, eraman, mgorny.
Herald added a project: clang.

This enables -emit-ifso to generate an interface library for each .o file. 
Currently it just writes a text file with the mangled names in it.


Repository:
  rC Clang

https://reviews.llvm.org/D60974

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/IFSO/foo-inline.h
  clang/test/IFSO/foo.cpp

Index: clang/test/IFSO/foo.cpp
===
--- /dev/null
+++ clang/test/IFSO/foo.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang -emit-ifso -fvisibility=hidden %s -o - | FileCheck --check-prefix=CHECK-HIDDEN %s
+// RUN: %clang -emit-ifso %s -o - | FileCheck %s
+
+// CHECK-HIDDEN-NOT: __Z4fbarff
+// CHECK: __Z4fbarff
+
+
+
+
+// CHECK-HIDDEN-NOT: __Z3fooii
+// CHECK-NOT:__Z3fooii
+
+
+
+#include "foo-inline.h"
+
+__attribute__ ((visibility ("hidden"))) int foo(int a, int b) { return a + b; }
+__attribute__ ((visibility ("default"))) int foo_default_visi(int a, int b) { return a + b; }
+
+
+__attribute__ ((visibility ("default"))) int fvih_1(int a, int b) { return a + fvih(); }
+
+int dataA = 34;
+
+namespace baz {
+  template 
+  T add(T a, T b) {
+return a + b;
+  }
+}
+
+namespace n {
+  template 
+  struct __attribute__((__visibility__("default"))) S {
+S() = default;
+~S() = default;
+int __attribute__((__visibility__(("default" func() const { return 32; }
+int __attribute__((__visibility__(("hidden" operator()() const { return 53; }
+  };
+}
+
+template  T neverUsed(T t) { return t + 2; }
+
+template<> int neverUsed(int t);
+
+void g() { n::S()(); }
+
+namespace qux {
+int bar(int a, int b) { return baz::add(a, b); }
+}
+
+float fbar(float a, float b) { return baz::add(a, b); }
+
Index: clang/test/IFSO/foo-inline.h
===
--- /dev/null
+++ clang/test/IFSO/foo-inline.h
@@ -0,0 +1,6 @@
+
+inline int fvih() {
+static int fortytwo = 42;
+  return fortytwo;
+}
+
Index: clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -64,6 +64,7 @@
   case GenerateHeaderModule:
 return llvm::make_unique();
   case GeneratePCH:return llvm::make_unique();
+  case GenerateIFSO:   return llvm::make_unique();
   case InitOnly:   return llvm::make_unique();
   case ParseSyntaxOnly:return llvm::make_unique();
   case ModuleFileInfo: return llvm::make_unique();
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -25,6 +25,8 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/YAMLTraits.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Index/CodegenNameGenerator.h"
 #include 
 #include 
 
@@ -158,6 +160,136 @@
   return true;
 }
 
+class IFSOFunctionsConsumer : public ASTConsumer {
+  CompilerInstance &Instance;
+  StringRef InFile = "";
+  std::set ParsedTemplates;
+
+  enum RootDeclOrigin { TopLevel = 0, FromTU = 1, IsLate = 2 };
+
+  template 
+  bool WriteNamedDecl(const NamedDecl *ND, raw_pwrite_stream &OS, int RDO) {
+if (!isa(ND))
+  return false;
+if (ND->getVisibility() != DefaultVisibility)
+  return true;
+// If this is a FunctionDecl that is dependent on a template parameter, then
+// don't get the symbol because we can only export specializations.
+bool IsRDOLate = (RDO & IsLate);
+if (const auto *FD = dyn_cast(ND))
+  if (FD->isDependentContext() && !IsRDOLate)
+return true;
+index::CodegenNameGenerator CGNameGen(ND->getASTContext());
+std::string MangledName = CGNameGen.getName(ND);
+OS << (IsRDOLate ? "late-parsed-decl: " : "")
+   << (IsRDOLate ? ND->getNameAsString() : MangledName) << "\n";
+// For now, lets just dump the -fdelayed-template-parsing decls until we
+// decide how to handle them.
+if (IsRDOLate)
+  ND->dump();
+return true;
+  }
+
+  template 
+  bool HandleSomeDecl(const NamedDecl *ND, raw_pwrite_stream &OS,
+  int RDO) {
+if (!isa(ND))
+  return false;
+for (auto *I : cast(ND)->decls())
+  HandleNamedDecl(dyn_cast(I), OS, RDO);
+return true;
+  }
+
+  template 
+  bool HandleSomeDeclSpec(const NamedDecl *ND,

[PATCH] D60974: Clang IFSO driver action.

2019-04-22 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi marked an inline comment as done.
plotfi added inline comments.



Comment at: clang/lib/Frontend/FrontendActions.cpp:185
+OS << (IsRDOLate ? "late-parsed-decl: " : "")
+   << (IsRDOLate ? ND->getNameAsString() : MangledName) << "\n";
+// For now, lets just dump the -fdelayed-template-parsing decls until we

Still feeling out what the proper format should be. Might just go with yaml for 
now. 


Repository:
  rC Clang

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

https://reviews.llvm.org/D60974



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


[PATCH] D41910: [Concepts] Constrained partial specializations and function overloads.

2019-04-22 Thread Saar Raz via Phabricator via cfe-commits
saar.raz updated this revision to Diff 196106.
saar.raz added a comment.

- Fixed importing of ACs when importing partial specs.
- Adjust to getAssociatedConstraints interface change


Repository:
  rC Clang

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

https://reviews.llvm.org/D41910

Files:
  include/clang/AST/DeclTemplate.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/AST/ASTImporter.cpp
  lib/AST/DeclTemplate.cpp
  lib/Sema/SemaConcept.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateDeduction.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CXX/concepts-ts/temp/temp.constr/temp.constr.normal/p1.cpp
  
test/CXX/concepts-ts/temp/temp.constr/temp.constr.order/class-template-partial-specializations.cpp
  test/CXX/concepts-ts/temp/temp.constr/temp.constr.order/function-templates.cpp
  
test/CXX/concepts-ts/temp/temp.constr/temp.constr.order/var-template-partial-specializations.cpp

Index: test/CXX/concepts-ts/temp/temp.constr/temp.constr.order/var-template-partial-specializations.cpp
===
--- /dev/null
+++ test/CXX/concepts-ts/temp/temp.constr/temp.constr.order/var-template-partial-specializations.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -std=c++2a -fconcepts-ts -x c++ -verify %s
+
+template requires sizeof(T) >= 4
+bool a = false; // expected-note{{template is declared here}}
+
+template requires sizeof(T) >= 4 && sizeof(T) <= 10
+bool a = true; // expected-error{{variable template partial specialization is not more specialized than the primary template}}
+
+template
+concept C1 = sizeof(T) >= 4;
+
+template requires C1
+bool b = false;
+
+template requires C1 && sizeof(T) <= 10
+bool b = true;
+
+template
+concept C2 = sizeof(T) > 1 && sizeof(T) <= 8;
+
+template
+bool c = false;
+
+template requires C1
+bool c = true;
+
+template
+bool d = false;
+
+template
+bool d = true; // expected-error{{variable template partial specialization does not specialize any template argument; to define the primary template, remove the template argument list}}
+
+template requires C1
+bool e = false;
+
+template
+bool e = true; // expected-error{{variable template partial specialization does not specialize any template argument; to define the primary template, remove the template argument list}}
+
+template
+constexpr int f = 1;
+
+template requires C1 && C2
+constexpr int f = 2;
+
+template requires C1 || C2
+constexpr int f = 3;
+
+static_assert(f == 2);
+static_assert(f == 3);
+static_assert(f == 1);
+
+
+
Index: test/CXX/concepts-ts/temp/temp.constr/temp.constr.order/function-templates.cpp
===
--- /dev/null
+++ test/CXX/concepts-ts/temp/temp.constr/temp.constr.order/function-templates.cpp
@@ -0,0 +1,82 @@
+// RUN: %clang_cc1 -std=c++2a -fconcepts-ts -x c++ -verify %s
+
+template requires sizeof(T) >= 4
+bool a() { return false; } // expected-note {{candidate function [with T = unsigned int]}}
+
+template requires sizeof(T) >= 4 && sizeof(T) <= 10
+bool a() { return true; } // expected-note {{candidate function [with T = unsigned int]}}
+
+bool av = a(); // expected-error {{call to 'a' is ambiguous}}
+
+template
+concept C1 = sizeof(T) >= 4;
+
+template requires C1
+constexpr bool b() { return false; }
+
+template requires C1 && sizeof(T) <= 10
+constexpr bool b() { return true; }
+
+static_assert(b());
+static_assert(!b());
+
+template
+concept C2 = sizeof(T) > 1 && sizeof(T) <= 8;
+
+template
+bool c() { return false; }
+
+template requires C1
+bool c() { return true; }
+
+template requires C1
+constexpr bool d() { return false; }
+
+template
+constexpr bool d() { return true; }
+
+static_assert(!d());
+
+template
+constexpr int e() { return 1; }
+
+template requires C1 && C2
+constexpr int e() { return 2; }
+
+template requires C1 || C2
+constexpr int e() { return 3; }
+
+static_assert(e() == 2);
+static_assert(e() == 3);
+static_assert(e() == 1);
+
+template
+concept BiggerThan = sizeof(T) > sizeof(U);
+
+template
+concept BiggerThanInt = BiggerThan;
+
+template requires BiggerThan
+void f() { }
+// expected-note@-1 {{candidate function [with T = long long, U = int]}}
+
+template requires BiggerThanInt
+void f() { }
+// expected-note@-1 {{candidate function [with T = long long, U = int]}}
+
+static_assert(sizeof(f()));
+// expected-error@-1 {{call to 'f' is ambiguous}}
+
+template
+concept C3 = true;
+
+template
+concept C4 = true && C3;
+
+template requires C3
+int g() { }
+
+template requires C4
+int g() { }
+
+static_assert(sizeof(g()));
\ No newline at end of file
Index: test/CXX/concepts-ts/temp/temp.constr/temp.constr.order/class-template-partial-specializations.cpp
===
--- /dev/null
+++ test/CXX/concepts-ts/temp/temp.constr/temp.constr.order/class-template-partial-specializations.c

[PATCH] D41910: [Concepts] Constrained partial specializations and function overloads.

2019-04-22 Thread Saar Raz via Phabricator via cfe-commits
saar.raz updated this revision to Diff 196107.
saar.raz added a comment.

Renamed PartSpec to PartSpec2 (CR)


Repository:
  rC Clang

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

https://reviews.llvm.org/D41910

Files:
  include/clang/AST/DeclTemplate.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/AST/ASTImporter.cpp
  lib/AST/DeclTemplate.cpp
  lib/Sema/SemaConcept.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateDeduction.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CXX/concepts-ts/temp/temp.constr/temp.constr.normal/p1.cpp
  
test/CXX/concepts-ts/temp/temp.constr/temp.constr.order/class-template-partial-specializations.cpp
  test/CXX/concepts-ts/temp/temp.constr/temp.constr.order/function-templates.cpp
  
test/CXX/concepts-ts/temp/temp.constr/temp.constr.order/var-template-partial-specializations.cpp

Index: test/CXX/concepts-ts/temp/temp.constr/temp.constr.order/var-template-partial-specializations.cpp
===
--- /dev/null
+++ test/CXX/concepts-ts/temp/temp.constr/temp.constr.order/var-template-partial-specializations.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -std=c++2a -fconcepts-ts -x c++ -verify %s
+
+template requires sizeof(T) >= 4
+bool a = false; // expected-note{{template is declared here}}
+
+template requires sizeof(T) >= 4 && sizeof(T) <= 10
+bool a = true; // expected-error{{variable template partial specialization is not more specialized than the primary template}}
+
+template
+concept C1 = sizeof(T) >= 4;
+
+template requires C1
+bool b = false;
+
+template requires C1 && sizeof(T) <= 10
+bool b = true;
+
+template
+concept C2 = sizeof(T) > 1 && sizeof(T) <= 8;
+
+template
+bool c = false;
+
+template requires C1
+bool c = true;
+
+template
+bool d = false;
+
+template
+bool d = true; // expected-error{{variable template partial specialization does not specialize any template argument; to define the primary template, remove the template argument list}}
+
+template requires C1
+bool e = false;
+
+template
+bool e = true; // expected-error{{variable template partial specialization does not specialize any template argument; to define the primary template, remove the template argument list}}
+
+template
+constexpr int f = 1;
+
+template requires C1 && C2
+constexpr int f = 2;
+
+template requires C1 || C2
+constexpr int f = 3;
+
+static_assert(f == 2);
+static_assert(f == 3);
+static_assert(f == 1);
+
+
+
Index: test/CXX/concepts-ts/temp/temp.constr/temp.constr.order/function-templates.cpp
===
--- /dev/null
+++ test/CXX/concepts-ts/temp/temp.constr/temp.constr.order/function-templates.cpp
@@ -0,0 +1,82 @@
+// RUN: %clang_cc1 -std=c++2a -fconcepts-ts -x c++ -verify %s
+
+template requires sizeof(T) >= 4
+bool a() { return false; } // expected-note {{candidate function [with T = unsigned int]}}
+
+template requires sizeof(T) >= 4 && sizeof(T) <= 10
+bool a() { return true; } // expected-note {{candidate function [with T = unsigned int]}}
+
+bool av = a(); // expected-error {{call to 'a' is ambiguous}}
+
+template
+concept C1 = sizeof(T) >= 4;
+
+template requires C1
+constexpr bool b() { return false; }
+
+template requires C1 && sizeof(T) <= 10
+constexpr bool b() { return true; }
+
+static_assert(b());
+static_assert(!b());
+
+template
+concept C2 = sizeof(T) > 1 && sizeof(T) <= 8;
+
+template
+bool c() { return false; }
+
+template requires C1
+bool c() { return true; }
+
+template requires C1
+constexpr bool d() { return false; }
+
+template
+constexpr bool d() { return true; }
+
+static_assert(!d());
+
+template
+constexpr int e() { return 1; }
+
+template requires C1 && C2
+constexpr int e() { return 2; }
+
+template requires C1 || C2
+constexpr int e() { return 3; }
+
+static_assert(e() == 2);
+static_assert(e() == 3);
+static_assert(e() == 1);
+
+template
+concept BiggerThan = sizeof(T) > sizeof(U);
+
+template
+concept BiggerThanInt = BiggerThan;
+
+template requires BiggerThan
+void f() { }
+// expected-note@-1 {{candidate function [with T = long long, U = int]}}
+
+template requires BiggerThanInt
+void f() { }
+// expected-note@-1 {{candidate function [with T = long long, U = int]}}
+
+static_assert(sizeof(f()));
+// expected-error@-1 {{call to 'f' is ambiguous}}
+
+template
+concept C3 = true;
+
+template
+concept C4 = true && C3;
+
+template requires C3
+int g() { }
+
+template requires C4
+int g() { }
+
+static_assert(sizeof(g()));
\ No newline at end of file
Index: test/CXX/concepts-ts/temp/temp.constr/temp.constr.order/class-template-partial-specializations.cpp
===
--- /dev/null
+++ test/CXX/concepts-ts/temp/temp.constr/temp.constr.order/class-template-partial-specializations.cpp
@@ -0,0 +1,84 @@
+// RUN: %clang_cc1 -std=c++2a -fconcepts-ts -x c++ -v

[PATCH] D60349: [COFF, ARM64] Fix ABI implementation of struct returns

2019-04-22 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang updated this revision to Diff 196109.

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

https://reviews.llvm.org/D60349

Files:
  include/clang/CodeGen/CGFunctionInfo.h
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/Sema/SemaDeclCXX.cpp
  test/CodeGen/arm64-microsoft-arguments.cpp
  test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp

Index: test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
===
--- test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
+++ test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
@@ -164,8 +164,8 @@
 // WIN64: define dso_local void @"?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(i32 %s.coerce) {{.*}} {
 // WIN64:   call void @"??1SmallWithDtor@@QEAA@XZ"
 // WIN64: }
-// WOA64: define dso_local void @"?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(i64 %s.coerce) {{.*}} {
-// WOA64:   call void @"??1SmallWithDtor@@QEAA@XZ"
+// WOA64: define dso_local void @"?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(%struct.SmallWithDtor* %s) {{.*}} {
+// WOA64:   call void @"??1SmallWithDtor@@QEAA@XZ"(%struct.SmallWithDtor* %s)
 // WOA64: }
 
 // FIXME: MSVC incompatible!
Index: test/CodeGen/arm64-microsoft-arguments.cpp
===
--- test/CodeGen/arm64-microsoft-arguments.cpp
+++ test/CodeGen/arm64-microsoft-arguments.cpp
@@ -1,25 +1,31 @@
 // RUN: %clang_cc1 -triple aarch64-windows -ffreestanding -emit-llvm -O0 \
 // RUN: -x c++ -o - %s | FileCheck %s
 
-struct pod { int a, b, c, d, e; };
+// Return type size <= 8 bytes.
+// CHECK: define {{.*}} i64 @{{.*}}f1{{.*}}()
+struct S1 { int a, b; };
+S1 f1() { return S1{}; }
 
-struct non_pod {
-  int a;
-  non_pod() {}
-};
+// Return type size <= 16 bytes.
+// CHECK: define {{.*}} [2 x i64] @{{.*}}f2{{.*}}()
+struct S2 { int a, b, c, d; };
+S2 f2() { return S2{}; }
 
-struct pod s;
-struct non_pod t;
+// Return type size > 16 bytes.
+// CHECK: define {{.*}} void @{{.*}}f3{{.*}}(%struct.S3* noalias sret %agg.result)
+struct S3 { int a, b, c, d, e; };
+S3 f3() { return S3{}; }
 
-struct pod bar() { return s; }
-struct non_pod foo() { return t; }
-// CHECK: define {{.*}} void @{{.*}}bar{{.*}}(%struct.pod* noalias sret %agg.result)
-// CHECK: define {{.*}} void @{{.*}}foo{{.*}}(%struct.non_pod* noalias %agg.result)
+// Instance methods.
+// CHECK: define {{.*}} void @{{.*}}inst@C{{.*}}(%class.C* %this, %class.A* inreg noalias sret %agg.result)
 
+class A {};
 
-// Check instance methods.
-struct pod2 { int x; };
-struct Baz { pod2 baz(); };
+class C {
+public:
+  A inst();
+};
 
-int qux() { return Baz().baz().x; }
-// CHECK: declare {{.*}} void @{{.*}}baz@Baz{{.*}}(%struct.Baz*, %struct.pod2*)
+A C::inst() {
+  return A();
+}
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -5902,8 +5902,13 @@
!D->hasNonTrivialCopyConstructorForCall();
 
   if (CCK == TargetInfo::CCK_MicrosoftWin64) {
+bool isAArch64 = S.Context.getTargetInfo().getTriple().isAArch64();
+if (isAArch64 && !D->isAggregate())
+  return false;
+
 bool CopyCtorIsTrivial = false, CopyCtorIsTrivialForCall = false;
 bool DtorIsTrivialForCall = false;
+bool CopyAssignmentIsTrivial = !isAArch64;
 
 // If a class has at least one non-deleted, trivial copy constructor, it
 // is passed according to the C ABI. Otherwise, it is passed indirectly.
@@ -5929,6 +5934,9 @@
   }
 }
 
+if (isAArch64 && D->needsImplicitCopyAssignment())
+  CopyAssignmentIsTrivial = D->hasTrivialCopyAssignment();
+
 if (D->needsImplicitDestructor()) {
   if (!D->defaultedDestructorIsDeleted() &&
   D->hasTrivialDestructorForCall())
@@ -5939,7 +5947,8 @@
 }
 
 // If the copy ctor and dtor are both trivial-for-calls, pass direct.
-if (CopyCtorIsTrivialForCall && DtorIsTrivialForCall)
+if (CopyCtorIsTrivialForCall && DtorIsTrivialForCall &&
+CopyAssignmentIsTrivial)
   return true;
 
 // If a class has a destructor, we'd really like to pass it indirectly
@@ -5952,7 +5961,7 @@
 
 // Note: This permits small classes with nontrivial destructors to be
 // passed in registers, which is non-conforming.
-if (CopyCtorIsTrivial &&
+if (!isAArch64 && CopyCtorIsTrivial &&
 S.getASTContext().getTypeSize(D->getTypeForDecl()) <= 64)
   return true;
 return false;
Index: lib/CodeGen/MicrosoftCXXABI.cpp
===
--- lib/CodeGen/MicrosoftCXXABI.cpp
+++ lib/CodeGen/MicrosoftCXXABI.cpp
@@ -52,6 +52,10 @@
 
   bool classifyReturnType(CGFunctionInfo &FI) const override;
 
+  bool passClassIndirect(const CXXRecordDecl *RD) const {
+return !canCopyArgument(RD);
+  }
+
   RecordArgABI getRecordArgABI(const CXXRecordDecl *RD) const override;
 
   bool isSRetParameterAfterThis() const override { ret

[PATCH] D60926: [CMake] Replace the sanitizer support in runtimes build with multilib

2019-04-22 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

Ping?


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

https://reviews.llvm.org/D60926



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-22 Thread Jake Ehrlich via Phabricator via cfe-commits
jakehehrlich added a comment.

Can you elaborate on the use case for this? Like can you explain end to end how 
this would be used?


Repository:
  rC Clang

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

https://reviews.llvm.org/D60974



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


[PATCH] D60349: [COFF, ARM64] Fix ABI implementation of struct returns

2019-04-22 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: lib/Sema/SemaDeclCXX.cpp:5906
+bool isAArch64 = S.Context.getTargetInfo().getTriple().isAArch64();
+if (isAArch64 && !D->isAggregate())
+  return false;

The isAggregate predicate is not appropriate to check here; it varies depending 
on whether the language version is C++14 or C++17.  For example, C++17 
aggregates are allowed to have base classes.  You have to split out checking 
the relevant properties (getNumBases(), isDynamicClass(), etc.).


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

https://reviews.llvm.org/D60349



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


[PATCH] D59418: [OpenMP][Offloading] Extract common functionality

2019-04-22 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59418



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


[PATCH] D59420: [NFC][OpenMP] Move runtime function generation to the target codegen

2019-04-22 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59420



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


[PATCH] D59424: [OpenMP][NVPTX] Replace void** buffer by byte-wise buffer

2019-04-22 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59424



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


[PATCH] D59712: [APSInt][OpenMP] Fix isNegative, etc. for unsigned types

2019-04-22 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

Thanks for the reviews!  Will push soon.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59712



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


[PATCH] D60926: [CMake] Replace the sanitizer support in runtimes build with multilib

2019-04-22 Thread Chris Bieneman via Phabricator via cfe-commits
beanz accepted this revision.
beanz added a comment.
This revision is now accepted and ready to land.

I really like this. Using `+` to add variants seems much widely useful.


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

https://reviews.llvm.org/D60926



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


r358917 - [VerifyDiagnosticConsumer] Document -verify= in doxygen

2019-04-22 Thread Joel E. Denny via cfe-commits
Author: jdenny
Date: Mon Apr 22 13:25:06 2019
New Revision: 358917

URL: http://llvm.org/viewvc/llvm-project?rev=358917&view=rev
Log:
[VerifyDiagnosticConsumer] Document -verify= in doxygen

Previously, it was only documented by `-cc1 -help`, so people weren't
aware of it, as discussed in D60732.

Reviewed By: Charusso, NoQ

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

Modified:
cfe/trunk/include/clang/Frontend/VerifyDiagnosticConsumer.h

Modified: cfe/trunk/include/clang/Frontend/VerifyDiagnosticConsumer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/VerifyDiagnosticConsumer.h?rev=358917&r1=358916&r2=358917&view=diff
==
--- cfe/trunk/include/clang/Frontend/VerifyDiagnosticConsumer.h (original)
+++ cfe/trunk/include/clang/Frontend/VerifyDiagnosticConsumer.h Mon Apr 22 
13:25:06 2019
@@ -33,7 +33,33 @@ class TextDiagnosticBuffer;
 /// markers in the input source to check that all the emitted diagnostics match
 /// those expected.
 ///
-/// USING THE DIAGNOSTIC CHECKER:
+/// INVOKING THE DIAGNOSTIC CHECKER:
+///
+/// VerifyDiagnosticConsumer is typically invoked via the "-verify" option to
+/// "clang -cc1".  "-verify" is equivalent to "-verify=expected", so all
+/// diagnostics are typically specified with the prefix "expected".  For
+/// example:
+///
+/// \code
+///   int A = B; // expected-error {{use of undeclared identifier 'B'}}
+/// \endcode
+///
+/// Custom prefixes can be specified as a comma-separated sequence.  Each
+/// prefix must start with a letter and contain only alphanumeric characters,
+/// hyphens, and underscores.  For example, given just "-verify=foo,bar",
+/// the above diagnostic would be ignored, but the following diagnostics would
+/// be recognized:
+///
+/// \code
+///   int A = B; // foo-error {{use of undeclared identifier 'B'}}
+///   int C = D; // bar-error {{use of undeclared identifier 'D'}}
+/// \endcode
+///
+/// Multiple occurrences accumulate prefixes.  For example,
+/// "-verify -verify=foo,bar -verify=baz" is equivalent to
+/// "-verify=expected,foo,bar,baz".
+///
+/// SPECIFYING DIAGNOSTICS:
 ///
 /// Indicating that a line expects an error or a warning is simple. Put a
 /// comment on the line that has the diagnostic, use:


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


[PATCH] D60845: [VerifyDiagnosticConsumer] Document -verify= in doxygen

2019-04-22 Thread Joel E. Denny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC358917: [VerifyDiagnosticConsumer] Document 
-verify= in doxygen (authored by jdenny, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D60845?vs=195742&id=196127#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D60845

Files:
  include/clang/Frontend/VerifyDiagnosticConsumer.h


Index: include/clang/Frontend/VerifyDiagnosticConsumer.h
===
--- include/clang/Frontend/VerifyDiagnosticConsumer.h
+++ include/clang/Frontend/VerifyDiagnosticConsumer.h
@@ -33,7 +33,33 @@
 /// markers in the input source to check that all the emitted diagnostics match
 /// those expected.
 ///
-/// USING THE DIAGNOSTIC CHECKER:
+/// INVOKING THE DIAGNOSTIC CHECKER:
+///
+/// VerifyDiagnosticConsumer is typically invoked via the "-verify" option to
+/// "clang -cc1".  "-verify" is equivalent to "-verify=expected", so all
+/// diagnostics are typically specified with the prefix "expected".  For
+/// example:
+///
+/// \code
+///   int A = B; // expected-error {{use of undeclared identifier 'B'}}
+/// \endcode
+///
+/// Custom prefixes can be specified as a comma-separated sequence.  Each
+/// prefix must start with a letter and contain only alphanumeric characters,
+/// hyphens, and underscores.  For example, given just "-verify=foo,bar",
+/// the above diagnostic would be ignored, but the following diagnostics would
+/// be recognized:
+///
+/// \code
+///   int A = B; // foo-error {{use of undeclared identifier 'B'}}
+///   int C = D; // bar-error {{use of undeclared identifier 'D'}}
+/// \endcode
+///
+/// Multiple occurrences accumulate prefixes.  For example,
+/// "-verify -verify=foo,bar -verify=baz" is equivalent to
+/// "-verify=expected,foo,bar,baz".
+///
+/// SPECIFYING DIAGNOSTICS:
 ///
 /// Indicating that a line expects an error or a warning is simple. Put a
 /// comment on the line that has the diagnostic, use:


Index: include/clang/Frontend/VerifyDiagnosticConsumer.h
===
--- include/clang/Frontend/VerifyDiagnosticConsumer.h
+++ include/clang/Frontend/VerifyDiagnosticConsumer.h
@@ -33,7 +33,33 @@
 /// markers in the input source to check that all the emitted diagnostics match
 /// those expected.
 ///
-/// USING THE DIAGNOSTIC CHECKER:
+/// INVOKING THE DIAGNOSTIC CHECKER:
+///
+/// VerifyDiagnosticConsumer is typically invoked via the "-verify" option to
+/// "clang -cc1".  "-verify" is equivalent to "-verify=expected", so all
+/// diagnostics are typically specified with the prefix "expected".  For
+/// example:
+///
+/// \code
+///   int A = B; // expected-error {{use of undeclared identifier 'B'}}
+/// \endcode
+///
+/// Custom prefixes can be specified as a comma-separated sequence.  Each
+/// prefix must start with a letter and contain only alphanumeric characters,
+/// hyphens, and underscores.  For example, given just "-verify=foo,bar",
+/// the above diagnostic would be ignored, but the following diagnostics would
+/// be recognized:
+///
+/// \code
+///   int A = B; // foo-error {{use of undeclared identifier 'B'}}
+///   int C = D; // bar-error {{use of undeclared identifier 'D'}}
+/// \endcode
+///
+/// Multiple occurrences accumulate prefixes.  For example,
+/// "-verify -verify=foo,bar -verify=baz" is equivalent to
+/// "-verify=expected,foo,bar,baz".
+///
+/// SPECIFYING DIAGNOSTICS:
 ///
 /// Indicating that a line expects an error or a warning is simple. Put a
 /// comment on the line that has the diagnostic, use:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D60943: Delay diagnosing "n" constraint until after inlining

2019-04-22 Thread Bill Wendling via Phabricator via cfe-commits
void added a comment.

In D60943#1474091 , @joerg wrote:

> I'm in the process of testing this, but feedback will take a bit.
>
> On the more meaty parts of this change, I think further iterations will be 
> necessary in-tree to extend this to the other constraints.


Thanks, Joerg. I was wondering about other constraints. This can be easily 
extended to encompass them. I just didn't want to jump the gun and come up with 
a "fix" that wasn't necessary.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60943



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


[PATCH] D59168: [runtimes] Move libunwind, libc++abi and libc++ to lib/clang/ and include/

2019-04-22 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

Does the following match what you have in mind?

  $prefix/
include/
  c++/
v1/
  limits.h
  ...
  openmp/
v1/ <-- I don't think openmp has anything like this now
  omp.h
  ompt.h
  ...
lib/
  c++/
$target/
  libc++abi.so
  ...
  openmp/
$target/
  libomp.so
  ...
  clang/
9.0.0/ <- resource directory
  include/
  lib/
$target/
  libclang_rt.asan_cxx.a
  ...


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

https://reviews.llvm.org/D59168



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-22 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D60974#1474591 , @jakehehrlich 
wrote:

> Can you elaborate on the use case for this? Like can you explain end to end 
> how this would be used?


There are a few that I have in mind.

1. -emit-ifso could be added to a build to produce .so files as part of a 
device SDK (where we don't want to ship the runnable bits in the SDK, we ship 
those on the device updates).
2. -emit-ifso could be added to whatever the existing set of build flags are to 
be run as a pre-build step to produce tapi-like .so files that break up build 
dependencies.
3. -emit-ifso -fvisibility=hidden could added to the invocation to disallow 
usage of non-public apis.

The way we are thinking it would work is similar to the dwos and .o files where 
you get one .ifso for each TU, then have a link-action that merges the mangled 
names and produces the .so file.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-22 Thread Jake Ehrlich via Phabricator via cfe-commits
jakehehrlich added a comment.

In D60974#1474751 , @plotfi wrote:

> There are a few that I have in mind.
>
> 1. -emit-ifso could be added to a build to produce .so files as part of a 
> device SDK (where we don't want to ship the runnable bits in the SDK, we ship 
> those on the device updates).


This would require creating a linker for these files. Is this what you intend 
to do?

> 2. -emit-ifso could be added to whatever the existing set of build flags are 
> to be run as a pre-build step to produce tapi-like .so files that break up 
> build dependencies.

How would this work? To be clear, this would happen at the same time that .o 
files are produced correct? The build graph would basically look the same but 
your new linking step would replace the original link step and there would be a 
pendent node for the original link step. This would not break up the build 
graph much at all save for the fact that we might imagine that this new link 
step would be much faster.

> 3. -emit-ifso -fvisibility=hidden could added to the invocation to disallow 
> usage of non-public apis.

Can you be more specific? This is already how the actual modules do this today 
so what is the advantage here.

> The way we are thinking it would work is similar to the dwos and .o files 
> where you get one .ifso for each TU, then have a link-action that merges the 
> mangled names and produces the .so file.

That requires a linker but one that only has to link dwarf which is designed to 
be linked using the dumbest possible semantics so that it can be format 
agnostic and not create undo complexity in the linker. The linker needed for 
this sort of thing would have to understand almost everything that a real full 
linker has to just to determine if a symbol is public or not. I think this 
might even require processing relocations. Beyond being public symbols have 
extra information that matters at both static and dynamic link time. This is 
mostly just point out how complicated this task is and not a complaint about 
the current output format. That could be improved but we have to be aware of 
the complexity of introducing yet a third type of linker and the issues with 
maintaining parity with the behavior of existing linker as well. In particular 
I think introducing a linker is an even bigger llvm-dev discussion that we need 
to have before we should proceed with this method.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60974



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


[PATCH] D60985: Fix compatability for cuda sm_75

2019-04-22 Thread Chuan Qiu via Phabricator via cfe-commits
eagleonhill created this revision.
Herald added subscribers: cfe-commits, jholewinski.
Herald added a project: clang.

This allows compute capability 7.5 to use 7.X intrinsics.


Repository:
  rC Clang

https://reviews.llvm.org/D60985

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def


Index: clang/include/clang/Basic/BuiltinsNVPTX.def
===
--- clang/include/clang/Basic/BuiltinsNVPTX.def
+++ clang/include/clang/Basic/BuiltinsNVPTX.def
@@ -19,7 +19,7 @@
 #endif
 
 #pragma push_macro("SM_70")
-#define SM_70 "sm_70|sm_71"
+#define SM_70 "sm_70|sm_71|sm_75"
 #pragma push_macro("SM_60")
 #define SM_60 "sm_60|sm_61|sm_62|" SM_70
 


Index: clang/include/clang/Basic/BuiltinsNVPTX.def
===
--- clang/include/clang/Basic/BuiltinsNVPTX.def
+++ clang/include/clang/Basic/BuiltinsNVPTX.def
@@ -19,7 +19,7 @@
 #endif
 
 #pragma push_macro("SM_70")
-#define SM_70 "sm_70|sm_71"
+#define SM_70 "sm_70|sm_71|sm_75"
 #pragma push_macro("SM_60")
 #define SM_60 "sm_60|sm_61|sm_62|" SM_70
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r358932 - [c++2a] Implement semantic restrictions for 'export' declarations.

2019-04-22 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon Apr 22 15:50:11 2019
New Revision: 358932

URL: http://llvm.org/viewvc/llvm-project?rev=358932&view=rev
Log:
[c++2a] Implement semantic restrictions for 'export' declarations.

Added:
cfe/trunk/test/CXX/module/module.interface/Inputs/
cfe/trunk/test/CXX/module/module.interface/Inputs/header.h
cfe/trunk/test/CXX/module/module.interface/p2.cpp
cfe/trunk/test/CXX/module/module.interface/p3.cpp
cfe/trunk/test/CXX/module/module.interface/p5.cpp
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/DeclBase.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaModule.cpp
cfe/trunk/test/CXX/module/module.interface/p1.cpp
cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp
cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cppm
cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/user.cpp
cfe/trunk/test/SemaCXX/anonymous-union-export.cpp
cfe/trunk/test/SemaCXX/modules-ts.cppm

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=358932&r1=358931&r2=358932&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon Apr 22 15:50:11 2019
@@ -4239,8 +4239,10 @@ public:
   SourceLocation getRBraceLoc() const { return RBraceLoc; }
   void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
 
+  bool hasBraces() const { return RBraceLoc.isValid(); }
+
   SourceLocation getEndLoc() const LLVM_READONLY {
-if (RBraceLoc.isValid())
+if (hasBraces())
   return RBraceLoc;
 // No braces: get the end location of the (only) declaration in context
 // (if present).

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=358932&r1=358931&r2=358932&view=diff
==
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Mon Apr 22 15:50:11 2019
@@ -600,10 +600,6 @@ public:
 return getModuleOwnershipKind() == ModuleOwnershipKind::ModulePrivate;
   }
 
-  /// Whether this declaration is exported (by virtue of being lexically
-  /// within an ExportDecl or by being a NamespaceDecl).
-  bool isExported() const;
-
   /// Return true if this declaration has an attribute which acts as
   /// definition of the entity, such as 'alias' or 'ifunc'.
   bool hasDefiningAttr() const;

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=358932&r1=358931&r2=358932&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Mon Apr 22 15:50:11 2019
@@ -168,6 +168,7 @@ def ExtraTokens : DiagGroup<"extra-token
 def CXX98CompatExtraSemi : DiagGroup<"c++98-compat-extra-semi">;
 def CXX11ExtraSemi : DiagGroup<"c++11-extra-semi">;
 def EmptyInitStatement : DiagGroup<"empty-init-stmt">;
+def ExportUnnamed : DiagGroup<"export-unnamed">;
 def ExtraSemiStmt : DiagGroup<"extra-semi-stmt", [EmptyInitStatement]>;
 def ExtraSemi : DiagGroup<"extra-semi", [CXX98CompatExtraSemi,
  CXX11ExtraSemi]>;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=358932&r1=358931&r2=358932&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Apr 22 15:50:11 
2019
@@ -9273,8 +9273,27 @@ def err_module_decl_not_at_start : Error
 def note_global_module_introducer_missing : Note<
   "add 'module;' to the start of the file to introduce a "
   "global module fragment">;
+def err_export_within_anonymous_namespace : Error<
+  "export declaration appears within anonymous namespace">;
+def note_anonymous_namespace : Note<"anonymous namespace begins here">;
+def ext_export_no_name_block : ExtWarn<
+  "ISO C++20 does not permit %select{an empty|a static_assert}0 declaration "
+  "to appear in an export block">, InGroup;
+def ext_export_no_names : ExtWarn<
+  "ISO C++20 does not permit a declaration that does not introduce any names "
+  "to be exported">, InGroup;
+def note_export : Note<"export block begins here">;
+def err_export_no_name : Error<
+  "%select{empty|static_assert|a

[PATCH] D59963: [clang-tidy] Add a module for the Linux kernel.

2019-04-22 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder updated this revision to Diff 196148.
tmroeder marked an inline comment as done.
tmroeder added a comment.

Updated with an initial check.

Verified that add_new_check.py works (that's how I added the check). Also added 
some basic docs and a test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59963

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/linuxkernel/CMakeLists.txt
  clang-tools-extra/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp
  clang-tools-extra/clang-tidy/linuxkernel/MustCheckErrsCheck.cpp
  clang-tools-extra/clang-tidy/linuxkernel/MustCheckErrsCheck.h
  clang-tools-extra/clang-tidy/plugin/CMakeLists.txt
  clang-tools-extra/clang-tidy/tool/CMakeLists.txt
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/linuxkernel-must-check-errs.c

Index: clang-tools-extra/test/clang-tidy/linuxkernel-must-check-errs.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/linuxkernel-must-check-errs.c
@@ -0,0 +1,43 @@
+// RUN: %check_clang_tidy %s linuxkernel-must-check-errs %t
+
+#define __must_check __attribute__((warn_unused_result))
+
+// Prototypes of the error functions.
+void * __must_check ERR_PTR(long error);
+long  __must_check PTR_ERR(const void *ptr);
+int  __must_check IS_ERR(const void *ptr);
+int  __must_check IS_ERR_OR_NULL(const void *ptr);
+void * __must_check ERR_CAST(const void *ptr);
+int  __must_check PTR_ERR_OR_ZERO(const void *ptr);
+
+void f() {
+  ERR_PTR(0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unused result from error function ERR_PTR
+  PTR_ERR((void *)0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unused result from error function PTR_ERR
+  IS_ERR((void *)0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unused result from error function IS_ERR
+  ERR_CAST((void *)0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unused result from error function ERR_CAST
+out:
+  PTR_ERR_OR_ZERO((void *)0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unused result from error function PTR_ERR_OR_ZERO
+}
+
+void *f1() {
+  return ERR_PTR(0);
+}
+
+long f2() {
+  if (IS_ERR((void *)0)) {
+return PTR_ERR((void *)0);
+  }
+  return -1;
+}
+
+void f3() {
+  f1();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unused result from function f1, which returns an error value
+  f2();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unused result from function f2, which returns an error value
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -175,6 +175,7 @@
hicpp-use-nullptr (redirects to modernize-use-nullptr) 
hicpp-use-override (redirects to modernize-use-override) 
hicpp-vararg (redirects to cppcoreguidelines-pro-type-vararg) 
+   linuxkernel-must-use-errs
llvm-header-guard
llvm-include-order
llvm-namespace-comment
Index: clang-tools-extra/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst
@@ -0,0 +1,26 @@
+.. title:: clang-tidy - linuxkernel-must-use-errs
+
+linuxkernel-must-use-errs
+=
+
+Checks for cases where the kernel error functions ``ERR_PTR``,
+``PTR_ERR``, ``IS_ERR``, ``IS_ERR_OR_NULL``, ``ERR_CAST``, and
+``PTR_ERR_OR_ZERO`` are called but the results are not used. These
+functions are marked with ``__attribute__((warn_unused_result))``, but
+the compiler warning for this attribute is not always enabled.
+
+This also checks for unused values returned by functions that return
+``ERR_PTR``.
+
+Examples:
+
+.. code-block:: c
+
+  /* Trivial unused call to an ERR function */
+  PTR_ERR_OR_ZERO(some_function_call());
+
+  /* A function that returns ERR_PTR. */
+  void *fn() { ERR_PTR(-EINVAL); }
+
+  /* An invalid use of fn. */
+  fn();
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -142,6 +142,11 @@
   ` now supports `OverrideSpelling`
   and `FinalSpelling` options.
 
+- New :doc:`linuxkernel-must-use-errs
+  ` check.
+
+  FIXME: add release notes.
+
 - New :doc:`openmp-exception-escape
   ` check.
 
Index: clang-tools-extra/clang-tidy/tool/CMakeLists.txt
===
--- clang-tools-extra/clang-tidy/tool/CMakeLists.txt
+++ clang-tools-extra/clang-tidy/tool/CMakeLists.txt
@@

[PATCH] D60349: [COFF, ARM64] Fix ABI implementation of struct returns

2019-04-22 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang updated this revision to Diff 196144.

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

https://reviews.llvm.org/D60349

Files:
  include/clang/CodeGen/CGFunctionInfo.h
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/Sema/SemaDeclCXX.cpp
  test/CodeGen/arm64-microsoft-arguments.cpp
  test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp

Index: test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
===
--- test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
+++ test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
@@ -164,8 +164,8 @@
 // WIN64: define dso_local void @"?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(i32 %s.coerce) {{.*}} {
 // WIN64:   call void @"??1SmallWithDtor@@QEAA@XZ"
 // WIN64: }
-// WOA64: define dso_local void @"?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(i64 %s.coerce) {{.*}} {
-// WOA64:   call void @"??1SmallWithDtor@@QEAA@XZ"
+// WOA64: define dso_local void @"?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(%struct.SmallWithDtor* %s) {{.*}} {
+// WOA64:   call void @"??1SmallWithDtor@@QEAA@XZ"(%struct.SmallWithDtor* %s)
 // WOA64: }
 
 // FIXME: MSVC incompatible!
Index: test/CodeGen/arm64-microsoft-arguments.cpp
===
--- test/CodeGen/arm64-microsoft-arguments.cpp
+++ test/CodeGen/arm64-microsoft-arguments.cpp
@@ -1,25 +1,31 @@
 // RUN: %clang_cc1 -triple aarch64-windows -ffreestanding -emit-llvm -O0 \
 // RUN: -x c++ -o - %s | FileCheck %s
 
-struct pod { int a, b, c, d, e; };
+// Return type size <= 8 bytes.
+// CHECK: define {{.*}} i64 @{{.*}}f1{{.*}}()
+struct S1 { int a, b; };
+S1 f1() { return S1{}; }
 
-struct non_pod {
-  int a;
-  non_pod() {}
-};
+// Return type size <= 16 bytes.
+// CHECK: define {{.*}} [2 x i64] @{{.*}}f2{{.*}}()
+struct S2 { int a, b, c, d; };
+S2 f2() { return S2{}; }
 
-struct pod s;
-struct non_pod t;
+// Return type size > 16 bytes.
+// CHECK: define {{.*}} void @{{.*}}f3{{.*}}(%struct.S3* noalias sret %agg.result)
+struct S3 { int a, b, c, d, e; };
+S3 f3() { return S3{}; }
 
-struct pod bar() { return s; }
-struct non_pod foo() { return t; }
-// CHECK: define {{.*}} void @{{.*}}bar{{.*}}(%struct.pod* noalias sret %agg.result)
-// CHECK: define {{.*}} void @{{.*}}foo{{.*}}(%struct.non_pod* noalias %agg.result)
+// Instance methods.
+// CHECK: define {{.*}} void @{{.*}}inst@C{{.*}}(%class.C* %this, %class.A* inreg noalias sret %agg.result)
 
+class A {};
 
-// Check instance methods.
-struct pod2 { int x; };
-struct Baz { pod2 baz(); };
+class C {
+public:
+  A inst();
+};
 
-int qux() { return Baz().baz().x; }
-// CHECK: declare {{.*}} void @{{.*}}baz@Baz{{.*}}(%struct.Baz*, %struct.pod2*)
+A C::inst() {
+  return A();
+}
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -5902,6 +5902,27 @@
!D->hasNonTrivialCopyConstructorForCall();
 
   if (CCK == TargetInfo::CCK_MicrosoftWin64) {
+bool isAArch64 = S.Context.getTargetInfo().getTriple().isAArch64();
+
+// The checks below ensure that thare no user provided constructors.
+// For AArch64, we use the C++14 definition of an aggregate, so we also
+// check for:
+//   No private or protected non static data members.
+//   No base classes
+//   No virtual functions
+// Additionally, we need to ensure that there is a trivial copy assignment
+// operator.
+if (isAArch64) {
+  if (D->getAccess() == AS_private || D->getAccess() == AS_protected)
+return false;
+  if (D->getNumBases() > 0)
+return false;
+  if (D->isPolymorphic())
+return false;
+  if (D->needsImplicitCopyAssignment() && !D->hasTrivialCopyAssignment())
+return false;
+}
+
 bool CopyCtorIsTrivial = false, CopyCtorIsTrivialForCall = false;
 bool DtorIsTrivialForCall = false;
 
@@ -5952,7 +5973,7 @@
 
 // Note: This permits small classes with nontrivial destructors to be
 // passed in registers, which is non-conforming.
-if (CopyCtorIsTrivial &&
+if (!isAArch64 && CopyCtorIsTrivial &&
 S.getASTContext().getTypeSize(D->getTypeForDecl()) <= 64)
   return true;
 return false;
Index: lib/CodeGen/MicrosoftCXXABI.cpp
===
--- lib/CodeGen/MicrosoftCXXABI.cpp
+++ lib/CodeGen/MicrosoftCXXABI.cpp
@@ -52,6 +52,10 @@
 
   bool classifyReturnType(CGFunctionInfo &FI) const override;
 
+  bool passClassIndirect(const CXXRecordDecl *RD) const {
+return !canCopyArgument(RD);
+  }
+
   RecordArgABI getRecordArgABI(const CXXRecordDecl *RD) const override;
 
   bool isSRetParameterAfterThis() const override { return true; }
@@ -1056,28 +1060,17 @@
   if (!RD)
 return false;
 
-  CharUnits Align = CGM.getContext().getTypeAlignInChars(FI.getReturnType());
-  if (FI.isInstanceMethod()) {
-// If it's 

[PATCH] D59673: [Driver] Allow setting the DWO name DWARF attribute separately

2019-04-22 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert updated this revision to Diff 196149.
aaronpuchert added a comment.

Introduce -split-dwarf-output instead to mirror the behavior of llc, which 
already allows to set the attribute separately from the output file name.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59673

Files:
  include/clang/Basic/CodeGenOptions.def
  include/clang/Basic/CodeGenOptions.h
  include/clang/Driver/CC1Options.td
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/split-debug-filename.c
  test/CodeGen/split-debug-output.c
  test/CodeGen/split-debug-single-file.c
  test/Driver/split-debug.c
  test/Misc/cc1as-split-dwarf.s
  tools/driver/cc1as_main.cpp

Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -98,7 +98,7 @@
   llvm::DebugCompressionType CompressDebugSections =
   llvm::DebugCompressionType::None;
   std::string MainFileName;
-  std::string SplitDwarfFile;
+  std::string SplitDwarfOutput;
 
   /// @}
   /// @name Frontend Options
@@ -258,7 +258,7 @@
   }
   Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
   Opts.OutputPath = Args.getLastArgValue(OPT_o);
-  Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file);
+  Opts.SplitDwarfOutput = Args.getLastArgValue(OPT_split_dwarf_output);
   if (Arg *A = Args.getLastArg(OPT_filetype)) {
 StringRef Name = A->getValue();
 unsigned OutputType = StringSwitch(Name)
@@ -367,8 +367,8 @@
   if (!FDOS)
 return true;
   std::unique_ptr DwoOS;
-  if (!Opts.SplitDwarfFile.empty())
-DwoOS = getOutputStream(Opts.SplitDwarfFile, Diags, IsBinary);
+  if (!Opts.SplitDwarfOutput.empty())
+DwoOS = getOutputStream(Opts.SplitDwarfOutput, Diags, IsBinary);
 
   // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and
   // MCObjectFileInfo needs a MCContext reference in order to initialize itself.
@@ -527,8 +527,8 @@
   if (Failed) {
 if (Opts.OutputPath != "-")
   sys::fs::remove(Opts.OutputPath);
-if (!Opts.SplitDwarfFile.empty() && Opts.SplitDwarfFile != "-")
-  sys::fs::remove(Opts.SplitDwarfFile);
+if (!Opts.SplitDwarfOutput.empty() && Opts.SplitDwarfOutput != "-")
+  sys::fs::remove(Opts.SplitDwarfOutput);
   }
 
   return Failed;
Index: test/Misc/cc1as-split-dwarf.s
===
--- test/Misc/cc1as-split-dwarf.s
+++ test/Misc/cc1as-split-dwarf.s
@@ -1,5 +1,5 @@
 // REQUIRES: x86-registered-target
-// RUN: %clang -cc1as -triple x86_64-pc-linux-gnu %s -filetype obj -o %t1 -split-dwarf-file %t2
+// RUN: %clang -cc1as -triple x86_64-pc-linux-gnu %s -filetype obj -o %t1 -split-dwarf-output %t2
 // RUN: llvm-objdump -s %t1 | FileCheck --check-prefix=O %s
 // RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=DWO %s
 
Index: test/Driver/split-debug.c
===
--- test/Driver/split-debug.c
+++ test/Driver/split-debug.c
@@ -3,7 +3,7 @@
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -c -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-ACTIONS < %t %s
 //
-// CHECK-ACTIONS: "-split-dwarf-file" "split-debug.dwo"
+// CHECK-ACTIONS: "-split-dwarf-file" "split-debug.dwo" "-split-dwarf-output" "split-debug.dwo"
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -c -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-ACTIONS < %t %s
@@ -13,13 +13,15 @@
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf=single -c -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-ACTIONS-SINGLE-SPLIT < %t %s
 //
-// CHECK-ACTIONS-SINGLE-SPLIT: "-enable-split-dwarf=single"
+// CHECK-ACTIONS-SINGLE-SPLIT: "-enable-split-dwarf"
 // CHECK-ACTIONS-SINGLE-SPLIT: "-split-dwarf-file" "split-debug.o"
+// CHECK-ACTIONS-SINGLE-SPLIT-NOT: "-split-dwarf-output"
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf=single -c -### -o %tfoo.o %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-SINGLE-SPLIT-FILENAME < %t %s
 //
 // CHECK-SINGLE-SPLIT-FILENAME: "-split-dwarf-file" "{{.*}}foo.o"
+// CHECK-SINGLE-SPLIT-FILENAME-NOT: "-split-dwarf-output"
 
 // RUN: %clang -target x86_64-macosx -gsplit-dwarf -c -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-NO-ACTIONS < %t %s
@@ -41,7 +43,7 @@
 // RUN: %clang -target amdgcn-amd-amdhsa -gsplit-dwarf -c -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-OPTION < %t %s
 //
-// CHECK-OPTION: "-split-dwarf-file" "split-debug.dwo"
+// CHECK-OPTION: "-split-dwarf-file" "split-debug.dwo" "-split-dwarf-output" "split-debug.dwo"
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -S -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-ASM < %t %s
@@ -59,6 +61,7 @@
 // CHECK-GMLT-WITH-SPLIT: "-enable-split-dwarf"
 // CHECK-GMLT-WITH-SPLIT: "-debug-inf

[PATCH] D59963: [clang-tidy] Add a module for the Linux kernel.

2019-04-22 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:148
+
+  FIXME: add release notes.
+

Please add short description. Should be same as first statements in 
documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59963



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


[PATCH] D59963: [clang-tidy] Add a module for the Linux kernel.

2019-04-22 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder updated this revision to Diff 196150.
tmroeder added a comment.

Actually add the documentation in the release notes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59963

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/linuxkernel/CMakeLists.txt
  clang-tools-extra/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp
  clang-tools-extra/clang-tidy/linuxkernel/MustCheckErrsCheck.cpp
  clang-tools-extra/clang-tidy/linuxkernel/MustCheckErrsCheck.h
  clang-tools-extra/clang-tidy/plugin/CMakeLists.txt
  clang-tools-extra/clang-tidy/tool/CMakeLists.txt
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/linuxkernel-must-check-errs.c

Index: clang-tools-extra/test/clang-tidy/linuxkernel-must-check-errs.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/linuxkernel-must-check-errs.c
@@ -0,0 +1,43 @@
+// RUN: %check_clang_tidy %s linuxkernel-must-check-errs %t
+
+#define __must_check __attribute__((warn_unused_result))
+
+// Prototypes of the error functions.
+void * __must_check ERR_PTR(long error);
+long  __must_check PTR_ERR(const void *ptr);
+int  __must_check IS_ERR(const void *ptr);
+int  __must_check IS_ERR_OR_NULL(const void *ptr);
+void * __must_check ERR_CAST(const void *ptr);
+int  __must_check PTR_ERR_OR_ZERO(const void *ptr);
+
+void f() {
+  ERR_PTR(0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unused result from error function ERR_PTR
+  PTR_ERR((void *)0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unused result from error function PTR_ERR
+  IS_ERR((void *)0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unused result from error function IS_ERR
+  ERR_CAST((void *)0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unused result from error function ERR_CAST
+out:
+  PTR_ERR_OR_ZERO((void *)0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unused result from error function PTR_ERR_OR_ZERO
+}
+
+void *f1() {
+  return ERR_PTR(0);
+}
+
+long f2() {
+  if (IS_ERR((void *)0)) {
+return PTR_ERR((void *)0);
+  }
+  return -1;
+}
+
+void f3() {
+  f1();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unused result from function f1, which returns an error value
+  f2();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unused result from function f2, which returns an error value
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -175,6 +175,7 @@
hicpp-use-nullptr (redirects to modernize-use-nullptr) 
hicpp-use-override (redirects to modernize-use-override) 
hicpp-vararg (redirects to cppcoreguidelines-pro-type-vararg) 
+   linuxkernel-must-use-errs
llvm-header-guard
llvm-include-order
llvm-namespace-comment
Index: clang-tools-extra/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst
@@ -0,0 +1,26 @@
+.. title:: clang-tidy - linuxkernel-must-use-errs
+
+linuxkernel-must-use-errs
+=
+
+Checks for cases where the kernel error functions ``ERR_PTR``,
+``PTR_ERR``, ``IS_ERR``, ``IS_ERR_OR_NULL``, ``ERR_CAST``, and
+``PTR_ERR_OR_ZERO`` are called but the results are not used. These
+functions are marked with ``__attribute__((warn_unused_result))``, but
+the compiler warning for this attribute is not always enabled.
+
+This also checks for unused values returned by functions that return
+``ERR_PTR``.
+
+Examples:
+
+.. code-block:: c
+
+  /* Trivial unused call to an ERR function */
+  PTR_ERR_OR_ZERO(some_function_call());
+
+  /* A function that returns ERR_PTR. */
+  void *fn() { ERR_PTR(-EINVAL); }
+
+  /* An invalid use of fn. */
+  fn();
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -142,6 +142,11 @@
   ` now supports `OverrideSpelling`
   and `FinalSpelling` options.
 
+- New :doc:`linuxkernel-must-use-errs
+  ` check.
+
+  Checks Linux Kernel code for misuse of important error functions.
+
 - New :doc:`openmp-exception-escape
   ` check.
 
Index: clang-tools-extra/clang-tidy/tool/CMakeLists.txt
===
--- clang-tools-extra/clang-tidy/tool/CMakeLists.txt
+++ clang-tools-extra/clang-tidy/tool/CMakeLists.txt
@@ -26,6 +26,7 @@
   clangTidyFuchsiaModule
   clangTidyGoogleModule
   clangTidyHICPPModule

[PATCH] D59977: [Lexer] Fix an off-by-one bug in Lexer::getAsCharRange() - NFC.

2019-04-22 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 196145.
NoQ added a comment.
Herald added subscribers: kadircet, arphaman, jkorous.

In D59977#1458051 , @alexfh wrote:

> It looks like there's a number of users of this function beyond what you've 
> mentioned:
>  clang-tidy/readability/IsolateDeclarationCheck.cpp:210


This one uses only char-ranges, not token-ranges, so it's unaffected by the 
change.

In D59977#1458051 , @alexfh wrote:

> clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp:43


They're using this function for counting the number of `::`s in 
`a::b::c::...::l`, and for them an off-by-one doesn't affect the answer.

In D59977#1458051 , @alexfh wrote:

> clang-tidy/readability/NamespaceCommentCheck.cpp:106


Yup, that's one of the failing tests. They were expecting their 
`CharSourceRange` for `x::y {` (which starts with token `x` and ends with token 
`{`) to not include token `{`. I had to manually `rtrim()` it from the string. 
It sounds as if `CharSourceRange` is indeed supposed to be "inclusive" (include 
its last token), so the new behavior is correct:

  229 /// The underlying SourceRange can either specify the starting/ending 
character
  230 /// of the range, or it can specify the start of the range and the start 
of the
  231 /// last token of the range (a "token range").  In the token range case, 
the
  232 /// size of the last token must be measured to determine the actual end 
of the
  233 /// range.
  234 class CharSourceRange {



In D59977#1458051 , @alexfh wrote:

> clang/lib/ARCMigrate/PlistReporter.cpp:110
>  clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp:192


These are addressed all together by the hack in `PlistSupport.h`.

-

Also fixed `SelectionTests`; they were artificially adding `1` to the resulting 
range and i removed it.

I believe it should all work now.


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

https://reviews.llvm.org/D59977

Files:
  clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
  clang-tools-extra/unittests/clangd/SelectionTests.cpp
  clang/include/clang/Basic/PlistSupport.h
  clang/include/clang/Lex/Lexer.h
  clang/unittests/Lex/LexerTest.cpp


Index: clang/unittests/Lex/LexerTest.cpp
===
--- clang/unittests/Lex/LexerTest.cpp
+++ clang/unittests/Lex/LexerTest.cpp
@@ -513,4 +513,23 @@
   EXPECT_EQ(String6, R"(a\\\n\n\nb)");
 }
 
+TEST_F(LexerTest, CharRangeOffByOne) {
+  std::vector toks = Lex(R"(#define MOO 1
+void foo() { MOO; })");
+  const Token &moo = toks[5];
+
+  EXPECT_EQ(getSourceText(moo, moo), "MOO");
+
+  SourceRange R{moo.getLocation(), moo.getLocation()};
+
+  EXPECT_TRUE(
+  Lexer::isAtStartOfMacroExpansion(R.getBegin(), SourceMgr, LangOpts));
+  EXPECT_TRUE(
+  Lexer::isAtEndOfMacroExpansion(R.getEnd(), SourceMgr, LangOpts));
+
+  CharSourceRange CR = Lexer::getAsCharRange(R, SourceMgr, LangOpts);
+
+  EXPECT_EQ(Lexer::getSourceText(CR, SourceMgr, LangOpts), "MOO"); // Was "MO".
+}
+
 } // anonymous namespace
Index: clang/include/clang/Lex/Lexer.h
===
--- clang/include/clang/Lex/Lexer.h
+++ clang/include/clang/Lex/Lexer.h
@@ -382,7 +382,7 @@
 SourceLocation End = getLocForEndOfToken(Range.getEnd(), 0, SM, LangOpts);
 return End.isInvalid() ? CharSourceRange()
: CharSourceRange::getCharRange(
- Range.getBegin(), End.getLocWithOffset(-1));
+ Range.getBegin(), End);
   }
   static CharSourceRange getAsCharRange(CharSourceRange Range,
 const SourceManager &SM,
Index: clang/include/clang/Basic/PlistSupport.h
===
--- clang/include/clang/Basic/PlistSupport.h
+++ clang/include/clang/Basic/PlistSupport.h
@@ -127,7 +127,11 @@
   assert(R.isCharRange() && "cannot handle a token range");
   Indent(o, indent) << "\n";
   EmitLocation(o, SM, R.getBegin(), FM, indent + 1);
-  EmitLocation(o, SM, R.getEnd(), FM, indent + 1);
+
+  // The ".getLocWithOffset(-1)" emulates the behavior of an off-by-one bug
+  // in Lexer that is already fixed. It is here for backwards compatibility
+  // even though it is incorrect.
+  EmitLocation(o, SM, R.getEnd().getLocWithOffset(-1), FM, indent + 1);
   Indent(o, indent) << "\n";
 }
 
Index: clang-tools-extra/unittests/clangd/SelectionTests.cpp
===
--- clang-tools-extra/unittests/clangd/SelectionTests.cpp
+++ clang-tools-extra/unittests/clangd/SelectionTests.cpp
@@ -45,7 +45,7 @@
   CharSourceRange R =
   Lexer::getAsCharRange(SR, SM, AST.getASTContext().getLangOpts());
   return Range{offsetToPosition(Bu

[PATCH] D59963: [clang-tidy] Add a module for the Linux kernel.

2019-04-22 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder updated this revision to Diff 196151.
tmroeder added a comment.

Fix a line-length issue in the check code and rewrite the doc text.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59963

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/linuxkernel/CMakeLists.txt
  clang-tools-extra/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp
  clang-tools-extra/clang-tidy/linuxkernel/MustCheckErrsCheck.cpp
  clang-tools-extra/clang-tidy/linuxkernel/MustCheckErrsCheck.h
  clang-tools-extra/clang-tidy/plugin/CMakeLists.txt
  clang-tools-extra/clang-tidy/tool/CMakeLists.txt
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/linuxkernel-must-check-errs.c

Index: clang-tools-extra/test/clang-tidy/linuxkernel-must-check-errs.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/linuxkernel-must-check-errs.c
@@ -0,0 +1,43 @@
+// RUN: %check_clang_tidy %s linuxkernel-must-check-errs %t
+
+#define __must_check __attribute__((warn_unused_result))
+
+// Prototypes of the error functions.
+void * __must_check ERR_PTR(long error);
+long  __must_check PTR_ERR(const void *ptr);
+int  __must_check IS_ERR(const void *ptr);
+int  __must_check IS_ERR_OR_NULL(const void *ptr);
+void * __must_check ERR_CAST(const void *ptr);
+int  __must_check PTR_ERR_OR_ZERO(const void *ptr);
+
+void f() {
+  ERR_PTR(0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unused result from error function ERR_PTR
+  PTR_ERR((void *)0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unused result from error function PTR_ERR
+  IS_ERR((void *)0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unused result from error function IS_ERR
+  ERR_CAST((void *)0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unused result from error function ERR_CAST
+out:
+  PTR_ERR_OR_ZERO((void *)0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unused result from error function PTR_ERR_OR_ZERO
+}
+
+void *f1() {
+  return ERR_PTR(0);
+}
+
+long f2() {
+  if (IS_ERR((void *)0)) {
+return PTR_ERR((void *)0);
+  }
+  return -1;
+}
+
+void f3() {
+  f1();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unused result from function f1, which returns an error value
+  f2();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unused result from function f2, which returns an error value
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -175,6 +175,7 @@
hicpp-use-nullptr (redirects to modernize-use-nullptr) 
hicpp-use-override (redirects to modernize-use-override) 
hicpp-vararg (redirects to cppcoreguidelines-pro-type-vararg) 
+   linuxkernel-must-use-errs
llvm-header-guard
llvm-include-order
llvm-namespace-comment
Index: clang-tools-extra/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst
@@ -0,0 +1,26 @@
+.. title:: clang-tidy - linuxkernel-must-use-errs
+
+linuxkernel-must-use-errs
+=
+
+Checks for cases where the kernel error functions ``ERR_PTR``,
+``PTR_ERR``, ``IS_ERR``, ``IS_ERR_OR_NULL``, ``ERR_CAST``, and
+``PTR_ERR_OR_ZERO`` are called but the results are not used. These
+functions are marked with ``__attribute__((warn_unused_result))``, but
+the compiler warning for this attribute is not always enabled.
+
+This also checks for unused values returned by functions that return
+``ERR_PTR``.
+
+Examples:
+
+.. code-block:: c
+
+  /* Trivial unused call to an ERR function */
+  PTR_ERR_OR_ZERO(some_function_call());
+
+  /* A function that returns ERR_PTR. */
+  void *fn() { ERR_PTR(-EINVAL); }
+
+  /* An invalid use of fn. */
+  fn();
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -142,6 +142,13 @@
   ` now supports `OverrideSpelling`
   and `FinalSpelling` options.
 
+- New :doc:`linuxkernel-must-use-errs
+  ` check.
+
+  Checks Linux Kernel code to see if it uses the results from the functions in
+  linux/err.h. Also checks to see if code uses the results from functions that
+  directly return a value from one of these error functions.
+
 - New :doc:`openmp-exception-escape
   ` check.
 
Index: clang-tools-extra/clang-tidy/tool/CMakeLists.txt
===
--- clang-tools-extra/clang-tid

[PATCH] D59963: [clang-tidy] Add a module for the Linux kernel.

2019-04-22 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder marked an inline comment as done.
tmroeder added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:148
+
+  FIXME: add release notes.
+

Eugene.Zelenko wrote:
> Please add short description. Should be same as first statements in 
> documentation.
Please take a look. I've rewritten the initial documentation lines in the check 
header and used that text here, as suggested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59963



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


[PATCH] D60899: [analyzer] Unbreak body farms in presence of multiple declarations.

2019-04-22 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D60899#1473412 , @a_sidorin wrote:

> the correct solution is to synthesize a shining new function and include it 
> into the redeclaration chain.


Mmm, what are the pros and cons?


Repository:
  rC Clang

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

https://reviews.llvm.org/D60899



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


[PATCH] D58537: lib/Header: Simplify CMakeLists.txt

2019-04-22 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

@tstellar ping. Someone appears to be running into this on the CMake mailing 
list too: https://cmake.org/pipermail/cmake/2019-April/069359.html


Repository:
  rL LLVM

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

https://reviews.llvm.org/D58537



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


[PATCH] D58537: lib/Header: Simplify CMakeLists.txt

2019-04-22 Thread Tom Stellard via Phabricator via cfe-commits
tstellar added a comment.

In D58537#1474824 , @smeenai wrote:

> @tstellar ping. Someone appears to be running into this on the CMake mailing 
> list too: https://cmake.org/pipermail/cmake/2019-April/069359.html


Sorry, I missed this.  I will take a look.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D58537



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


[PATCH] D59673: [Clang] Harmonize Split DWARF options with llc

2019-04-22 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a subscriber: pcc.
aaronpuchert added inline comments.



Comment at: lib/CodeGen/BackendUtil.cpp:1345
   Conf.RemarksPasses = CGOpts.OptRecordPasses;
-  Conf.DwoPath = CGOpts.SplitDwarfFile;
+  Conf.DwoPath = CGOpts.SplitDwarfOutput;
   switch (Action) {

@pcc Your documentation for `DwoPath` suggests that this should be the actual 
output filename. However, the test that you added together with this line in 
rC333677 doesn't fail whatever garbage I write into that field here. What can I 
add to that so that it fails when we don't do the right thing here?


Repository:
  rC Clang

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

https://reviews.llvm.org/D59673



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


[PATCH] D59673: [Clang] Harmonize Split DWARF options with llc

2019-04-22 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert updated this revision to Diff 196156.
aaronpuchert added a comment.

Adapt one more test case.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59673

Files:
  include/clang/Basic/CodeGenOptions.def
  include/clang/Basic/CodeGenOptions.h
  include/clang/Driver/CC1Options.td
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/split-debug-filename.c
  test/CodeGen/split-debug-output.c
  test/CodeGen/split-debug-single-file.c
  test/Driver/split-debug.c
  test/Driver/split-debug.s
  test/Misc/cc1as-split-dwarf.s
  tools/driver/cc1as_main.cpp

Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -98,7 +98,7 @@
   llvm::DebugCompressionType CompressDebugSections =
   llvm::DebugCompressionType::None;
   std::string MainFileName;
-  std::string SplitDwarfFile;
+  std::string SplitDwarfOutput;
 
   /// @}
   /// @name Frontend Options
@@ -258,7 +258,7 @@
   }
   Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
   Opts.OutputPath = Args.getLastArgValue(OPT_o);
-  Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file);
+  Opts.SplitDwarfOutput = Args.getLastArgValue(OPT_split_dwarf_output);
   if (Arg *A = Args.getLastArg(OPT_filetype)) {
 StringRef Name = A->getValue();
 unsigned OutputType = StringSwitch(Name)
@@ -367,8 +367,8 @@
   if (!FDOS)
 return true;
   std::unique_ptr DwoOS;
-  if (!Opts.SplitDwarfFile.empty())
-DwoOS = getOutputStream(Opts.SplitDwarfFile, Diags, IsBinary);
+  if (!Opts.SplitDwarfOutput.empty())
+DwoOS = getOutputStream(Opts.SplitDwarfOutput, Diags, IsBinary);
 
   // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and
   // MCObjectFileInfo needs a MCContext reference in order to initialize itself.
@@ -527,8 +527,8 @@
   if (Failed) {
 if (Opts.OutputPath != "-")
   sys::fs::remove(Opts.OutputPath);
-if (!Opts.SplitDwarfFile.empty() && Opts.SplitDwarfFile != "-")
-  sys::fs::remove(Opts.SplitDwarfFile);
+if (!Opts.SplitDwarfOutput.empty() && Opts.SplitDwarfOutput != "-")
+  sys::fs::remove(Opts.SplitDwarfOutput);
   }
 
   return Failed;
Index: test/Misc/cc1as-split-dwarf.s
===
--- test/Misc/cc1as-split-dwarf.s
+++ test/Misc/cc1as-split-dwarf.s
@@ -1,5 +1,5 @@
 // REQUIRES: x86-registered-target
-// RUN: %clang -cc1as -triple x86_64-pc-linux-gnu %s -filetype obj -o %t1 -split-dwarf-file %t2
+// RUN: %clang -cc1as -triple x86_64-pc-linux-gnu %s -filetype obj -o %t1 -split-dwarf-output %t2
 // RUN: llvm-objdump -s %t1 | FileCheck --check-prefix=O %s
 // RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=DWO %s
 
Index: test/Driver/split-debug.s
===
--- test/Driver/split-debug.s
+++ test/Driver/split-debug.s
@@ -3,7 +3,7 @@
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -c -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-ACTIONS < %t %s
 //
-// CHECK-ACTIONS: "-split-dwarf-file" "split-debug.dwo"
+// CHECK-ACTIONS: "-split-dwarf-output" "split-debug.dwo"
 
 // Check we pass -split-dwarf-file to `as` if -gsplit-dwarf=split.
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf=split -c -### %s 2> %t
Index: test/Driver/split-debug.c
===
--- test/Driver/split-debug.c
+++ test/Driver/split-debug.c
@@ -3,7 +3,7 @@
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -c -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-ACTIONS < %t %s
 //
-// CHECK-ACTIONS: "-split-dwarf-file" "split-debug.dwo"
+// CHECK-ACTIONS: "-split-dwarf-file" "split-debug.dwo" "-split-dwarf-output" "split-debug.dwo"
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -c -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-ACTIONS < %t %s
@@ -13,13 +13,15 @@
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf=single -c -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-ACTIONS-SINGLE-SPLIT < %t %s
 //
-// CHECK-ACTIONS-SINGLE-SPLIT: "-enable-split-dwarf=single"
+// CHECK-ACTIONS-SINGLE-SPLIT: "-enable-split-dwarf"
 // CHECK-ACTIONS-SINGLE-SPLIT: "-split-dwarf-file" "split-debug.o"
+// CHECK-ACTIONS-SINGLE-SPLIT-NOT: "-split-dwarf-output"
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf=single -c -### -o %tfoo.o %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-SINGLE-SPLIT-FILENAME < %t %s
 //
 // CHECK-SINGLE-SPLIT-FILENAME: "-split-dwarf-file" "{{.*}}foo.o"
+// CHECK-SINGLE-SPLIT-FILENAME-NOT: "-split-dwarf-output"
 
 // RUN: %clang -target x86_64-macosx -gsplit-dwarf -c -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-NO-ACTIONS < %t %s
@@ -41,7 +43,7 @@
 // RUN: %clang -target amdgc

[PATCH] D60349: [COFF, ARM64] Fix ABI implementation of struct returns

2019-04-22 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: lib/Sema/SemaDeclCXX.cpp:5904
 
   if (CCK == TargetInfo::CCK_MicrosoftWin64) {
+bool isAArch64 = S.Context.getTargetInfo().getTriple().isAArch64();

I'm not entirely sure it makes sense to do all of these Windows-specific checks 
here... I think it makes trivial_abi not work the way it should.  But that's 
not something we need to worry about for the initial patch, I think.



Comment at: lib/Sema/SemaDeclCXX.cpp:5916
+if (isAArch64) {
+  if (D->getAccess() == AS_private || D->getAccess() == AS_protected)
+return false;

D->getAccess() is the access specifier for the class itself (if the class is 
nested inside another class), not the access specifier for any of its members.

I think you're looking for HasProtectedFields and HasPrivateFields.  (I think 
there currently isn't any getter on CXXRecordDecl for them at the moment, but 
you can add one.)



Comment at: lib/Sema/SemaDeclCXX.cpp:5922
+return false;
+  if (D->needsImplicitCopyAssignment() && !D->hasTrivialCopyAssignment())
+return false;

Why are you checking needsImplicitCopyAssignment()?


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

https://reviews.llvm.org/D60349



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


r358935 - [CMake] Replace the sanitizer support in runtimes build with multilib

2019-04-22 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Mon Apr 22 16:31:39 2019
New Revision: 358935

URL: http://llvm.org/viewvc/llvm-project?rev=358935&view=rev
Log:
[CMake] Replace the sanitizer support in runtimes build with multilib

This is a more generic solution; while the sanitizer support can be used
only for sanitizer instrumented builds, the multilib support can be used
to build other variants such as noexcept which is what we would like to use
in Fuchsia.

The name CMake target name uses the target name, same as for the regular
runtimes build and the name of the multilib, concatenated with '+'. The
libraries are installed in a subdirectory named after the multilib.

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

Modified:
cfe/trunk/cmake/caches/Fuchsia-stage2.cmake

Modified: cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/caches/Fuchsia-stage2.cmake?rev=358935&r1=358934&r2=358935&view=diff
==
--- cfe/trunk/cmake/caches/Fuchsia-stage2.cmake (original)
+++ cfe/trunk/cmake/caches/Fuchsia-stage2.cmake Mon Apr 22 16:31:39 2019
@@ -142,12 +142,22 @@ if(FUCHSIA_SDK)
 
set(RUNTIMES_${target}-fuchsia_LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY OFF 
CACHE BOOL "")
 set(RUNTIMES_${target}-fuchsia_LIBCXX_ABI_VERSION 2 CACHE STRING "")
 
+set(RUNTIMES_${target}-fuchsia+asan_LLVM_BUILD_COMPILER_RT OFF CACHE BOOL 
"")
+set(RUNTIMES_${target}-fuchsia+asan_LLVM_USE_SANITIZER "Address" CACHE 
STRING "")
+
set(RUNTIMES_${target}-fuchsia+asan_LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF 
CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia+asan_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS 
OFF CACHE BOOL "")
+
+set(RUNTIMES_${target}-fuchsia+noexcept_LLVM_BUILD_COMPILER_RT OFF CACHE 
BOOL "")
+set(RUNTIMES_${target}-fuchsia+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS OFF 
CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia+noexcept_LIBCXX_ENABLE_EXCEPTIONS OFF CACHE 
BOOL "")
+
 # Use .build-id link.
 list(APPEND RUNTIME_BUILD_ID_LINK "${target}-fuchsia")
   endforeach()
 
-  set(LLVM_RUNTIME_SANITIZERS "Address" CACHE STRING "")
-  set(LLVM_RUNTIME_SANITIZER_Address_TARGETS "x86_64-fuchsia;aarch64-fuchsia" 
CACHE STRING "")
+  set(LLVM_RUNTIME_MULTILIBS "asan;noexcept" CACHE STRING "")
+  set(LLVM_RUNTIME_MULTILIB_asan_TARGETS "x86_64-fuchsia;aarch64-fuchsia" 
CACHE STRING "")
+  set(LLVM_RUNTIME_MULTILIB_noexcept_TARGETS "x86_64-fuchsia;aarch64-fuchsia" 
CACHE STRING "")
 endif()
 
 set(LLVM_BUILTIN_TARGETS "${BUILTIN_TARGETS}" CACHE STRING "")


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


[PATCH] D58537: lib/Header: Simplify CMakeLists.txt

2019-04-22 Thread Tom Stellard via Phabricator via cfe-commits
tstellar marked an inline comment as done.
tstellar added inline comments.



Comment at: cfe/trunk/lib/Headers/CMakeLists.txt:168
 install(
-  FILES ${cuda_wrapper_files}
-  COMPONENT clang-headers
-  PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
-  DESTINATION 
lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include/cuda_wrappers)
+  DIRECTORY ${output_dir}
+  DESTINATION ${header_install_dir}

vzakhari wrote:
> This change results in a use of CMAKE_CFG_INTDIR, which expands to 
> $(Configuration) inside cmake_install.cmake, when using Visual Studio 
> generator. CMake cannot reasonably expand $(Configuration), so Visual Studio 
> builds are broken for me after this change-set.
> 
> Can we revert to installation from FILES relative to the current source dir?  
> This will require keeping a separate list of source files in 
> copy_header_to_output_dir(), and using this list in the install() command.
> 
> I do understand that the intention was, probably, to copy headers files into 
> output_dir along with creating some structure inside output_dir, and then 
> installing the whole output_dir verbatim to the install dir.  It will be hard 
> to achieve this with the change I suggest, but can we fix Visual Studio 
> builds in any other way?
> 
> FWIW, vcproj invokes the installation with the following command: cmake 
> -DBUILD_TYPE=$(Configuration) -P cmake_install.cmake
> CMake could have expanded CMAKE_CFG_INTDIR as ${BUILD_TYPE} instead of 
> $(Configuration) inside cmake_install.cmake.
> This change results in a use of CMAKE_CFG_INTDIR, which expands to 
> $(Configuration) inside cmake_install.cmake, when using Visual Studio 
> generator. CMake cannot reasonably expand $(Configuration), so Visual Studio 
> builds are broken for me after this change-set.

Prior to this change we were installing the arm generated files from 
${CMAKE_CURRENT_BINARY_DIR}.  Do we really need to use 
${LLVM_LIBRARY_OUTPUT_INTDIR} as the base for output_dir?  Could we use 
${CMAKE_CURRENT_BINARY_DIR} instead?  That seems like it would fix this issue.

> FWIW, vcproj invokes the installation with the following command: cmake 
> -DBUILD_TYPE=$(Configuration) -P cmake_install.cmake
CMake could have expanded CMAKE_CFG_INTDIR as ${BUILD_TYPE} instead of 
$(Configuration) inside cmake_install.cmake.

Are the vc project files part of the LLVM source tree?







Repository:
  rL LLVM

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

https://reviews.llvm.org/D58537



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


[PATCH] D60985: Fix compatability for cuda sm_75

2019-04-22 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

FYI, I have almost-ready set of patches to implement missing bits of sm_75 
support, including this change:
https://reviews.llvm.org/D60279

I expect to land them some time this week.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60985



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


[PATCH] D60899: [analyzer] Unbreak body farms in presence of multiple declarations.

2019-04-22 Thread Aleksei Sidorin via Phabricator via cfe-commits
a_sidorin added a comment.

> Mmm, what are the pros and cons?

This is how we do it in the ASTImporter. It allows us to correctly handle 
redeclarations with and without bodies - the declarations in the current AST 
remain unchanged but a new declaration appears.  But it can be a kind of a 
professional deformation :) BodyFarm is a much lighter facility and I won't 
argue that my approach is better - just an idea.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60899



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


[PATCH] D60926: [CMake] Replace the sanitizer support in runtimes build with multilib

2019-04-22 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL358935: [CMake] Replace the sanitizer support in runtimes 
build with multilib (authored by phosek, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D60926?vs=195934&id=196159#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D60926

Files:
  cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
  llvm/trunk/runtimes/CMakeLists.txt

Index: cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
===
--- cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
+++ cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
@@ -142,12 +142,22 @@
 set(RUNTIMES_${target}-fuchsia_LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY OFF CACHE BOOL "")
 set(RUNTIMES_${target}-fuchsia_LIBCXX_ABI_VERSION 2 CACHE STRING "")
 
+set(RUNTIMES_${target}-fuchsia+asan_LLVM_BUILD_COMPILER_RT OFF CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia+asan_LLVM_USE_SANITIZER "Address" CACHE STRING "")
+set(RUNTIMES_${target}-fuchsia+asan_LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia+asan_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
+
+set(RUNTIMES_${target}-fuchsia+noexcept_LLVM_BUILD_COMPILER_RT OFF CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia+noexcept_LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
+
 # Use .build-id link.
 list(APPEND RUNTIME_BUILD_ID_LINK "${target}-fuchsia")
   endforeach()
 
-  set(LLVM_RUNTIME_SANITIZERS "Address" CACHE STRING "")
-  set(LLVM_RUNTIME_SANITIZER_Address_TARGETS "x86_64-fuchsia;aarch64-fuchsia" CACHE STRING "")
+  set(LLVM_RUNTIME_MULTILIBS "asan;noexcept" CACHE STRING "")
+  set(LLVM_RUNTIME_MULTILIB_asan_TARGETS "x86_64-fuchsia;aarch64-fuchsia" CACHE STRING "")
+  set(LLVM_RUNTIME_MULTILIB_noexcept_TARGETS "x86_64-fuchsia;aarch64-fuchsia" CACHE STRING "")
 endif()
 
 set(LLVM_BUILTIN_TARGETS "${BUILTIN_TARGETS}" CACHE STRING "")
Index: llvm/trunk/runtimes/CMakeLists.txt
===
--- llvm/trunk/runtimes/CMakeLists.txt
+++ llvm/trunk/runtimes/CMakeLists.txt
@@ -70,7 +70,7 @@
   get_compiler_rt_path(compiler_rt_path)
   if(compiler_rt_path)
 list(REMOVE_ITEM runtimes ${compiler_rt_path})
-if(NOT LLVM_BUILD_COMPILER_RT)
+if(NOT DEFINED LLVM_BUILD_COMPILER_RT OR LLVM_BUILD_COMPILER_RT)
   list(INSERT runtimes 0 ${compiler_rt_path})
 endif()
   endif()
@@ -242,7 +242,8 @@
 
 get_cmake_property(variableNames VARIABLES)
 foreach(variableName ${variableNames})
-  if(variableName MATCHES "^BUILTINS_${target}")
+  string(FIND "${variableName}" "BUILTINS_${target}" out)
+  if("${out}" EQUAL 0)
 string(REPLACE "BUILTINS_${target}_" "" new_name ${variableName})
 list(APPEND ${target}_extra_args "-D${new_name}=${${variableName}}")
   endif()
@@ -425,10 +426,13 @@
 
 get_cmake_property(variableNames VARIABLES)
 foreach(variableName ${variableNames})
-  if(variableName MATCHES "^RUNTIMES_${name}")
+  string(FIND "${variableName}" "RUNTIMES_${name}_" out)
+  if("${out}" EQUAL 0)
 string(REPLACE "RUNTIMES_${name}_" "" new_name ${variableName})
 list(APPEND ${name}_extra_args "-D${new_name}=${${variableName}}")
-  elseif(variableName MATCHES "^RUNTIMES_${target}")
+  endif()
+  string(FIND "${variableName}" "RUNTIMES_${target}_" out)
+  if("${out}" EQUAL 0)
 string(REPLACE "RUNTIMES_${target}_" "" new_name ${variableName})
 list(APPEND ${name}_extra_args "-D${new_name}=${${variableName}}")
   endif()
@@ -510,28 +514,16 @@
 endif()
   endforeach()
 
-  foreach(sanitizer ${LLVM_RUNTIME_SANITIZERS})
-if (sanitizer STREQUAL "Address")
-  set(sanitizer_name "asan")
-elseif (sanitizer STREQUAL "Memory")
-  set(sanitizer_name "msan")
-elseif (sanitizer STREQUAL "Thread")
-  set(sanitizer_name "tsan")
-elseif (sanitizer STREQUAL "Undefined")
-  set(sanitizer_name "ubsan")
-else()
-  message(FATAL_ERROR "Unsupported value of LLVM_RUNTIME_TARGET_SANITIZERS: ${sanitizers}")
-endif()
-foreach(name ${LLVM_RUNTIME_SANITIZER_${sanitizer}_TARGETS})
-  runtime_register_target(${name}-${sanitizer_name} ${name}
+  foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
+foreach(name ${LLVM_RUNTIME_MULTILIB_${multilib}_TARGETS})
+  runtime_register_target(${name}+${multilib} ${name}
 DEPENDS runtimes-${name}
-CMAKE_ARGS -DLLVM_USE_SANITIZER=${sanitizer}
-   -DLLVM_RUNTIMES_PREFIX=${name}/
-   -DLLVM_RUNTIMES_LIBDIR_SUFFIX=/${sanitizer_name})
-  add_dependencies(runtimes runtimes-${nam

[PATCH] D60943: Delay diagnosing "n" constraint until after inlining

2019-04-22 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

I don't like making the validity of an input depend on optimizations, but I 
presume this is necessary to build Linux or similar? I'd be more comfortable 
with this if we still did the eager check if the enclosing function doesn't 
have the `always_inline` attribute. Is that sufficient to satisfy the use cases?


Repository:
  rC Clang

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

https://reviews.llvm.org/D60943



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


[PATCH] D60925: [analyzer] Don't display implementation checkers under -analyzer-checker-help, but do under the new flag -analyzer-checker-help-hidden

2019-04-22 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Yup, that sounds useful!

> I intentionally chose not to hide alpha checkers, because they have a scary 
> enough name, in my opinion, to cause no surprise when they emit false 
> positives or cause crashes.

I've seen people yelling really loudly, like "look, your clang is crap, it 
crashes all over the place", after enabling all alpha checkers at once. It's 
fairly hard to explain to the wider audience that LLVM doesn't have feature 
branches, so we have to put all unfinished features into the released product 
with a kind notice of "please don't use them, they're not ready yet". Our 
development policy is fairly unusual in this regard. It's like selling a 
washing machine with 30 extra buttons and by pressing any of them you get a 
slight chance that it washes a bit better and also a slight chance that it 
explodes and covers your house with white soapy goop and pieces of underwear, 
and all it says about these buttons is that they're "alpha".


Repository:
  rC Clang

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

https://reviews.llvm.org/D60925



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


[PATCH] D59744: Fix i386 ABI "__m64" type bug

2019-04-22 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added subscribers: dexonsmith, rjmccall.
rnk added inline comments.



Comment at: lib/CodeGen/TargetInfo.cpp:919
 /// IsX86_MMXType - Return true if this is an MMX type.
 bool IsX86_MMXType(llvm::Type *IRType) {
-  // Return true if the type is an MMX type <2 x i32>, <4 x i16>, or <8 x i8>.

I think looking at the LLVM type to decide how something should be passed is a 
bad pattern to follow. We should look at the clang AST to decide how things 
will be passed, not LLVM types. Would that be complicated? Are there aggregate 
types that end up getting passed directly in MMX registers?



Comment at: lib/CodeGen/TargetInfo.cpp:9489
+  // System V i386 ABI requires __m64 value passing by MMX registers.
+  bool EnableMMX = getContext().getTargetInfo().getABI() != "no-mmx";
   return SetCGInfo(new X86_32TargetCodeGenInfo(

I think this needs to preserve existing behavior for Darwin and PS4 based on 
comments from @rjmccall and @dexonsmith in D60748.


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

https://reviews.llvm.org/D59744



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


[PATCH] D60418: inline asm: Don't copy llvm::MemoryBuffers when showing diagnostics

2019-04-22 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

> This is blocked on fixing PR41431.

I reviewed the code, but timed out while trying to understand PR41431. Maybe 
ping @rsmith about it again?


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

https://reviews.llvm.org/D60418



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


[PATCH] D55500: [Builtins] Implement __builtin_is_constant_evaluated for use in C++2a

2019-04-22 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.
Herald added a subscriber: dexonsmith.

LGTM, thanks!


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

https://reviews.llvm.org/D55500



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


[PATCH] D60943: Delay diagnosing "n" constraint until after inlining

2019-04-22 Thread Bill Wendling via Phabricator via cfe-commits
void added a comment.

Here's the motivating bug report: https://bugs.llvm.org/show_bug.cgi?id=41027

In general, I agree with you that diagnostics shouldn't depend on optimization 
levels, but inline assembly subverts this paradigm because it was originally a 
gcc extension. :-( That said, I don't know if looking at the `always_inline` 
attribute would work. I'll let @joerg and others comment on that.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60943



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


[PATCH] D60943: Delay diagnosing "n" constraint until after inlining

2019-04-22 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D60943#1474899 , @void wrote:

> Here's the motivating bug report: https://bugs.llvm.org/show_bug.cgi?id=41027


Thanks, that's illuminating. OK, if we want to support that code, then there's 
really not much validation we can do in the frontend for constraints that 
require immediate constants. Is `"n"` really special in this regard, or is it 
just the first one that we've encountered?

> In general, I agree with you that diagnostics shouldn't depend on 
> optimization levels, but inline assembly subverts this paradigm because it 
> was originally a gcc extension. :-(

There is a question of how much weird stuff we should accept in the name of GCC 
compatibility. In this case, the fact that the frontend rejects seems like the 
tip of an iceberg: the code in the PR is also relying on the control flow of 
the `&&` inside the `if` to be emitted in a very particular way (or to be 
optimized to that form), and for dead-code elimination to be considered and to 
actually fire, and probably more things besides. Do we at least still produce a 
nice diagnostic if the value ends up not being a constant?


Repository:
  rC Clang

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

https://reviews.llvm.org/D60943



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


[PATCH] D56571: [RFC prototype] Implementation of asm-goto support in clang

2019-04-22 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

@void, @jyknight  given that looks like a LLVM issue rather than a clang issue, 
can we file a bugzilla to track separately from this clang frontend patch?


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

https://reviews.llvm.org/D56571



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


[PATCH] D60988: [analyzer] Fix crash when returning C++ objects from ObjC messages-to-nil.

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

This is an Objective-C++ specific fix to a problem that's similar to D59573 
 and D59622  
(i.e., hitting the same assertion i added in D59054 
).

This time, surprisingly, the assertion is in fact incorrect: there is a 
cornercase in Objective-C++ in which a C++ object is not constructed with a 
constructor, but only zero-initialized. Namely, this happens when an 
Objective-C message is sent to a `nil` and it is supposed to return a C++ 
object.

I made sure that the assertion is only relaxed for Objective-C++ but it's hard 
to relax it in a more specific way with the amount of information that 
`RegionStore` receives. The alternative solution was to conjure a 
`LazyCompoundValue` specifically for this case instead, but implementing this 
cornercase in `SValBuilder::makeZeroVal()` is hard because there's no good 
region to use as the base of that `LazyCompoundVal`, and in the checker (this 
modeling currently belongs to CallAndMessageChecker) it's even uglier and is 
bad for checker APIs.


Repository:
  rC Clang

https://reviews.llvm.org/D60988

Files:
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/test/Analysis/nil-receiver.mm


Index: clang/test/Analysis/nil-receiver.mm
===
--- /dev/null
+++ clang/test/Analysis/nil-receiver.mm
@@ -0,0 +1,24 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection \
+// RUN:-verify %s
+
+#define nil ((id)0)
+
+void clang_analyzer_eval(int);
+
+struct S {
+  int x;
+  S();
+};
+
+@interface I
+@property S s;
+@end
+
+void foo() {
+  // This produces a zero-initialized structure.
+  // FIXME: This very fact does deserve the warning, because zero-initialized
+  // structures aren't always valid in C++. It's particularly bad when the
+  // object has a vtable.
+  S s = ((I *)nil).s;
+  clang_analyzer_eval(s.x == 0); // expected-warning{{TRUE}}
+}
Index: clang/lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -2361,7 +2361,14 @@
   // In C++17 aggregates may have base classes, handle those as well.
   // They appear before fields in the initializer list / compound value.
   if (const auto *CRD = dyn_cast(RD)) {
-assert(CRD->isAggregate() &&
+// If the object was constructed with a constructor, its value is a
+// LazyCompoundVal. If it's a raw CompoundVal, it means that we're
+// performing aggregate initialization. The only exception from this
+// rule is sending an Objective-C++ message that returns a C++ object
+// to a nil receiver; in this case the semantics is to return a
+// zero-initialized object even if it's a C++ object that doesn't have
+// this sort of constructor; the CompoundVal is empty in this case.
+assert((CRD->isAggregate() || (Ctx.getLangOpts().ObjC && VI == VE)) &&
"Non-aggregates are constructed with a constructor!");
 
 for (const auto &B : CRD->bases()) {


Index: clang/test/Analysis/nil-receiver.mm
===
--- /dev/null
+++ clang/test/Analysis/nil-receiver.mm
@@ -0,0 +1,24 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection \
+// RUN:-verify %s
+
+#define nil ((id)0)
+
+void clang_analyzer_eval(int);
+
+struct S {
+  int x;
+  S();
+};
+
+@interface I
+@property S s;
+@end
+
+void foo() {
+  // This produces a zero-initialized structure.
+  // FIXME: This very fact does deserve the warning, because zero-initialized
+  // structures aren't always valid in C++. It's particularly bad when the
+  // object has a vtable.
+  S s = ((I *)nil).s;
+  clang_analyzer_eval(s.x == 0); // expected-warning{{TRUE}}
+}
Index: clang/lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -2361,7 +2361,14 @@
   // In C++17 aggregates may have base classes, handle those as well.
   // They appear before fields in the initializer list / compound value.
   if (const auto *CRD = dyn_cast(RD)) {
-assert(CRD->isAggregate() &&
+// If the object was constructed with a constructor, its value is a
+// LazyCompoundVal. If it's a raw CompoundVal, it means that we're
+// performing aggregate initialization. The only exception from this
+// rule is sending an Objective-C++ message that returns a C++ object
+// to a nil receiver; in this case the semantics 

[PATCH] D60974: Clang IFSO driver action.

2019-04-22 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added a comment.

@jakehehrlich I think you are misunderstanding this.  The intent here is to 
provide a means to emit just the interfaces from a library into a stub that can 
be used for building.  However, rather than have the interfaces be defined 
elsewhere, having clang run through the sources and compute the public 
interfaces as written means that no matter how you write your interfaces, the 
same set of interfaces will always be emitted into the interface library.  The 
"linker" literally is a merge of all the public interfaces in each translation 
unit.  It is important to understand that there are interfaces which may be 
declared in sources (yes, that is terrible, but not all software is well 
designed or well written unfortunately).  This means that you need to do a 
syntactic pass of the sources (along with the flags that you are building with) 
to ensure that all the public interfaces are made visible.  You can do this by 
a separate step of consuming the compilation database and running through each 
of the target's TUs, this is just a slightly different approach to that.  Once 
you have enumerated the public interfaces, you just emit a stub containing that 
set of interfaces (preserving whether it is a text or data symbol).

I'm not sure how modules play into this at all.  Yes, C++ modules could let you 
control some of the interfaces, but that is orthogonal to what this is meant to 
do.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-22 Thread Jake Ehrlich via Phabricator via cfe-commits
jakehehrlich added a comment.

I'm not misunderstanding, please seem my post on llvm-dev where I layout the 
different issues involved. You're underestimating the complexities involved 
here I think. Trivializing what the linker does to "the linker just merges 
these" is a gross oversimplification that doesn't account for symbol consuming 
vs exporting, size, alignment, visibility, linkage, symbol type, symbol 
versioning (which is impossible to handle here without consuming version 
scripts as was pointed out by someone else), which symbols are untimely 
exported/consumed or even intermediate operations on .o files via tools like 
objcopy (which is uncommon and shouldn't be a hard blocker here but something 
to think about). Also all linkers behave just a bit differently with respect to 
these issues so 1) the reality is that the thing that merges these will behave 
just a bit differently than any existing linker but 2) even if it trys to match 
one linker it will fail to match the other so it will only be compaitable in 
all cases with atmost one linker (but probably none when edge cases are 
considered. I also already pointed out the issue with having to search all 
source files on the tree. I agree that if you were to use the linker to 
accomplish this that would would have to look at all source files. Further more 
many flags passed to the linker untimely affect these things making matters 
more complicated. The "linker" you describe for these cases is far from "cat".

For reference when I say "module" in this context I mean the output of the 
linker. "DSO" is synonymous. A DSO/module can be an executable or shared object 
but we can consider both here. I was not referring to C++ modules.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60974



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


[PATCH] D60990: [Driver] Support priority for multilibs

2019-04-22 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
phosek added reviewers: jroelofs, bkramer.
Herald added subscribers: cfe-commits, mgrang.
Herald added a project: clang.

When more than one multilib flag matches, try to select the best
possible match based on priority. When two different multilibs with
the same same priority match, we still throw an error matching the
existing behavior.


Repository:
  rC Clang

https://reviews.llvm.org/D60990

Files:
  clang/include/clang/Driver/Multilib.h
  clang/lib/Driver/Multilib.cpp


Index: clang/lib/Driver/Multilib.cpp
===
--- clang/lib/Driver/Multilib.cpp
+++ clang/lib/Driver/Multilib.cpp
@@ -19,6 +19,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
+#include 
 #include 
 
 using namespace clang;
@@ -51,8 +52,9 @@
 }
 
 Multilib::Multilib(StringRef GCCSuffix, StringRef OSSuffix,
-   StringRef IncludeSuffix)
-: GCCSuffix(GCCSuffix), OSSuffix(OSSuffix), IncludeSuffix(IncludeSuffix) {
+   StringRef IncludeSuffix, int Priority)
+: GCCSuffix(GCCSuffix), OSSuffix(OSSuffix), IncludeSuffix(IncludeSuffix),
+  Priority(Priority) {
   normalizePathSegment(this->GCCSuffix);
   normalizePathSegment(this->OSSuffix);
   normalizePathSegment(this->IncludeSuffix);
@@ -265,8 +267,19 @@
 return true;
   }
 
-  // TODO: pick the "best" multlib when more than one is suitable
-  assert(false);
+  // Sort multilibs by priority and select the one with the highest priority.
+  std::sort(Filtered.begin(), Filtered.end(),
+[](const Multilib &a, const Multilib &b) -> bool {
+  return a.priority() > b.priority();
+});
+
+  if (Filtered[0].priority() <= Filtered[1].priority()) {
+M = Filtered[0];
+return true;
+  }
+
+  // TODO: We should consider returning llvm::Error rather than aborting.
+  assert(false && "More than one multilib with the same priority");
   return false;
 }
 
Index: clang/include/clang/Driver/Multilib.h
===
--- clang/include/clang/Driver/Multilib.h
+++ clang/include/clang/Driver/Multilib.h
@@ -34,10 +34,11 @@
   std::string OSSuffix;
   std::string IncludeSuffix;
   flags_list Flags;
+  int Priority;
 
 public:
   Multilib(StringRef GCCSuffix = {}, StringRef OSSuffix = {},
-   StringRef IncludeSuffix = {});
+   StringRef IncludeSuffix = {}, int Priority = 0);
 
   /// Get the detected GCC installation path suffix for the multi-arch
   /// target variant. Always starts with a '/', unless empty
@@ -77,6 +78,9 @@
   const flags_list &flags() const { return Flags; }
   flags_list &flags() { return Flags; }
 
+  /// Returns the multilib priority.
+  int priority() const { return Priority; }
+
   /// Add a flag to the flags list
   /// \p Flag must be a flag accepted by the driver with its leading '-' 
removed,
   /// and replaced with either:


Index: clang/lib/Driver/Multilib.cpp
===
--- clang/lib/Driver/Multilib.cpp
+++ clang/lib/Driver/Multilib.cpp
@@ -19,6 +19,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
+#include 
 #include 
 
 using namespace clang;
@@ -51,8 +52,9 @@
 }
 
 Multilib::Multilib(StringRef GCCSuffix, StringRef OSSuffix,
-   StringRef IncludeSuffix)
-: GCCSuffix(GCCSuffix), OSSuffix(OSSuffix), IncludeSuffix(IncludeSuffix) {
+   StringRef IncludeSuffix, int Priority)
+: GCCSuffix(GCCSuffix), OSSuffix(OSSuffix), IncludeSuffix(IncludeSuffix),
+  Priority(Priority) {
   normalizePathSegment(this->GCCSuffix);
   normalizePathSegment(this->OSSuffix);
   normalizePathSegment(this->IncludeSuffix);
@@ -265,8 +267,19 @@
 return true;
   }
 
-  // TODO: pick the "best" multlib when more than one is suitable
-  assert(false);
+  // Sort multilibs by priority and select the one with the highest priority.
+  std::sort(Filtered.begin(), Filtered.end(),
+[](const Multilib &a, const Multilib &b) -> bool {
+  return a.priority() > b.priority();
+});
+
+  if (Filtered[0].priority() <= Filtered[1].priority()) {
+M = Filtered[0];
+return true;
+  }
+
+  // TODO: We should consider returning llvm::Error rather than aborting.
+  assert(false && "More than one multilib with the same priority");
   return false;
 }
 
Index: clang/include/clang/Driver/Multilib.h
===
--- clang/include/clang/Driver/Multilib.h
+++ clang/include/clang/Driver/Multilib.h
@@ -34,10 +34,11 @@
   std::string OSSuffix;
   std::string IncludeSuffix;
   flags_list Flags;
+  int Priority;
 
 public:
   Multilib(StringRef GCCSuffix = {}, StringRef OSSuffix = {},
-   StringRef IncludeSuffix = {});
+   StringRef IncludeSuffix = {}, int Priority = 0);
 
   /// Get the detected GCC installation path suffix for the multi-arch
   /// tar

[PATCH] D60974: Clang IFSO driver action.

2019-04-22 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added a comment.

I'm well versed in the complexities of a linker - I've worked extensively on 
the GNU linkers as well as with lld.  The visibility of the symbols is actually 
computed by the compiler - the STV_* flags associated with the symtab entry 
give you that information which is actually tracked through the frontend to the 
backend.  Yes, each linker behaves differently - including lld which completely 
changes the semantics of Unix/ELF linking guarantees.  In fact every single 
attribute that you mentioned is something which is emitted from the compiler - 
which we have access to here given that we are in clang itself.  I think that 
this can be made to work properly, though will probably require some iteration 
to get all the corner cases, and that you may be slightly dismissive of this 
approach.

Ah, okay, I didn't pick up that you were using module as the actual module from 
the context since normally the module doesn't control what it exposes itself.

Note that I am not advocating that this change go in as is - I think that this 
is far from something which would be useful, and until it can produce something 
meaningful, this shouldn't really be merged (i.e. generate something which 
obj2yaml or some other tool can consume to generate the barest ELF stub).


Repository:
  rC Clang

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

https://reviews.llvm.org/D60974



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


[PATCH] D60991: [analyzer] RetainCount: Allow offsets in return values.

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

Because RetainCountChecker has custom "local" reasoning about escapes, it has a 
separate facility to deal with tracked symbols at end of analysis and check 
them for leaks regardless of whether they're dead or not. This facility 
iterates over the list of tracked symbols and reports them as leaks, but it 
needs to treat the return value specially.

Some custom allocators tend to return the value with an offset, storing extra 
metadata at the beginning of the buffer. In this case the return value would be 
a non-base region. In order to avoid false positives, we still need to find the 
original symbol within the return value, otherwise it'll be unable to match it 
to the item in the list of tracked symbols.

I don't really understand how this whole facility works in general. In 
particular, i don't understand why doesn't it take the function's contract into 
account (i.e., should this function generally return at +0 or at +1?), but the 
fix still seems to make sense to me.


Repository:
  rC Clang

https://reviews.llvm.org/D60991

Files:
  clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
  clang/test/Analysis/retain-release.mm


Index: clang/test/Analysis/retain-release.mm
===
--- clang/test/Analysis/retain-release.mm
+++ clang/test/Analysis/retain-release.mm
@@ -515,3 +515,35 @@
 }
 
 }
+
+namespace reinterpret_casts {
+
+void *foo() {
+  void *p = const_cast(
+  reinterpret_cast(CFArrayCreate(0, 0, 0, 0)));
+  void *q = reinterpret_cast(
+  reinterpret_cast(p) + 1);
+  // FIXME: Should warn about a leak here. The function should return at +0,
+  // but it returns at +1 instead.
+  return q;
+}
+
+void *fooCreate() {
+  void *p = const_cast(
+  reinterpret_cast(CFArrayCreate(0, 0, 0, 0)));
+  void *q = reinterpret_cast(
+  reinterpret_cast(p) + 1);
+  // The function follows the Create Rule.
+  return q; // no-warning
+}
+
+void *fooBar() CF_RETURNS_RETAINED {
+  void *p = const_cast(
+  reinterpret_cast(CFArrayCreate(0, 0, 0, 0)));
+  void *q = reinterpret_cast(
+  reinterpret_cast(p) + 1);
+  // The function follows the Create Rule.
+  return q; // no-warning
+}
+
+}
Index: 
clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
@@ -970,8 +970,10 @@
 return Pred;
 
   ProgramStateRef state = C.getState();
-  SymbolRef Sym =
-state->getSValAsScalarOrLoc(RetE, C.getLocationContext()).getAsLocSymbol();
+  // We need to dig down to the symbolic base here because various
+  // custom allocators do sometimes return the symbol with an offset.
+  SymbolRef Sym = state->getSValAsScalarOrLoc(RetE, C.getLocationContext())
+  .getAsLocSymbol(/*IncludeBaseRegions=*/true);
   if (!Sym)
 return Pred;
 


Index: clang/test/Analysis/retain-release.mm
===
--- clang/test/Analysis/retain-release.mm
+++ clang/test/Analysis/retain-release.mm
@@ -515,3 +515,35 @@
 }
 
 }
+
+namespace reinterpret_casts {
+
+void *foo() {
+  void *p = const_cast(
+  reinterpret_cast(CFArrayCreate(0, 0, 0, 0)));
+  void *q = reinterpret_cast(
+  reinterpret_cast(p) + 1);
+  // FIXME: Should warn about a leak here. The function should return at +0,
+  // but it returns at +1 instead.
+  return q;
+}
+
+void *fooCreate() {
+  void *p = const_cast(
+  reinterpret_cast(CFArrayCreate(0, 0, 0, 0)));
+  void *q = reinterpret_cast(
+  reinterpret_cast(p) + 1);
+  // The function follows the Create Rule.
+  return q; // no-warning
+}
+
+void *fooBar() CF_RETURNS_RETAINED {
+  void *p = const_cast(
+  reinterpret_cast(CFArrayCreate(0, 0, 0, 0)));
+  void *q = reinterpret_cast(
+  reinterpret_cast(p) + 1);
+  // The function follows the Create Rule.
+  return q; // no-warning
+}
+
+}
Index: clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
@@ -970,8 +970,10 @@
 return Pred;
 
   ProgramStateRef state = C.getState();
-  SymbolRef Sym =
-state->getSValAsScalarOrLoc(RetE, C.getLocationContext()).getAsLocSymbol();
+  // We need to dig down to the symbolic base here because various
+  // custom allocators do sometimes return the symbol with an offset.
+  SymbolRef Sym = state->getSValAsScalarOr

r358944 - [analyzer] PR41269: Add a bit of C++ smart pointer modeling.

2019-04-22 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Apr 22 19:45:42 2019
New Revision: 358944

URL: http://llvm.org/viewvc/llvm-project?rev=358944&view=rev
Log:
[analyzer] PR41269: Add a bit of C++ smart pointer modeling.

Implement cplusplus.SmartPtrModeling, a new checker that doesn't
emit any warnings but models methods of smart pointers more precisely.

For now the only thing it does is make `(bool) P` return false when `P`
is a freshly moved pointer. This addresses a false positive in the
use-after-move-checker.

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

Added:
cfe/trunk/lib/StaticAnalyzer/Checkers/Move.h
cfe/trunk/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
cfe/trunk/test/Analysis/smart-ptr.cpp
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h
cfe/trunk/test/Analysis/use-after-move.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td?rev=358944&r1=358943&r2=358944&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Mon Apr 22 
19:45:42 2019
@@ -464,6 +464,10 @@ def CXXSelfAssignmentChecker : Checker<"
   HelpText<"Checks C++ copy and move assignment operators for self 
assignment">,
   Documentation;
 
+def SmartPtrModeling: Checker<"SmartPtr">,
+  HelpText<"Model behavior of C++ smart pointers">,
+  Documentation;
+
 def MoveChecker: Checker<"Move">,
   HelpText<"Find use-after-move bugs in C++">,
   CheckerOptions<[

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt?rev=358944&r1=358943&r2=358944&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt Mon Apr 22 19:45:42 
2019
@@ -84,6 +84,7 @@ add_clang_library(clangStaticAnalyzerChe
   ReturnUndefChecker.cpp
   RunLoopAutoreleaseLeakChecker.cpp
   SimpleStreamChecker.cpp
+  SmartPtrModeling.cpp
   StackAddrEscapeChecker.cpp
   StdLibraryFunctionsChecker.cpp
   StreamChecker.cpp

Added: cfe/trunk/lib/StaticAnalyzer/Checkers/Move.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/Move.h?rev=358944&view=auto
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/Move.h (added)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/Move.h Mon Apr 22 19:45:42 2019
@@ -0,0 +1,30 @@
+//=== Move.h - Tracking moved-from objects. *- C++ 
-*-//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Defines inter-checker API for the use-after-move checker. It allows
+// dependent checkers to figure out if an object is in a moved-from state.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_MOVE_H
+#define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_MOVE_H
+
+#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
+
+namespace clang {
+namespace ento {
+namespace move {
+
+/// Returns true if the object is known to have been recently std::moved.
+bool isMovedFrom(ProgramStateRef State, const MemRegion *Region);
+
+} // namespace move
+} // namespace ento
+} // namespace clang
+
+#endif // LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_MOVE_H

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp?rev=358944&r1=358943&r2=358944&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp Mon Apr 22 19:45:42 
2019
@@ -227,6 +227,18 @@ private:
 
 REGISTER_MAP_WITH_PROGRAMSTATE(TrackedRegionMap, const MemRegion *, 
RegionState)
 
+// Define the inter-checker API.
+namespace clang {
+namespace ento {
+namespace move {
+bool isMovedFrom(ProgramStateRef State, const MemRegion *Region) {
+  const RegionState *RS = State->get(Region);
+  return RS && (RS->isMoved() || RS->isReported());
+}
+} // namespace move
+} // namespace ento
+} // namespace clang
+
 // If a region is removed all of the subregions needs to be r

r358945 - [analyzer] PR41335: Fix crash when no-store event is in a body-farmed function.

2019-04-22 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Apr 22 19:50:38 2019
New Revision: 358945

URL: http://llvm.org/viewvc/llvm-project?rev=358945&view=rev
Log:
[analyzer] PR41335: Fix crash when no-store event is in a body-farmed function.

Stuffing invalid source locations (such as those in functions produced by
body farms) into path diagnostics causes crashes.

Fix a typo in a nearby function name.

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

Added:
cfe/trunk/test/Analysis/OSAtomic_mac.c
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h?rev=358945&r1=358944&r2=358945&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h 
Mon Apr 22 19:50:38 2019
@@ -313,6 +313,8 @@ public:
 
   bool hasRange() const { return K == StmtK || K == RangeK || K == DeclK; }
 
+  bool hasValidLocation() const { return asLocation().isValid(); }
+
   void invalidate() {
 *this = PathDiagnosticLocation();
   }
@@ -468,7 +470,7 @@ public:
   PathDiagnosticPiece::Kind k,
   bool addPosRange = true)
   : PathDiagnosticPiece(s, k), Pos(pos) {
-assert(Pos.isValid() && Pos.asLocation().isValid() &&
+assert(Pos.isValid() && Pos.hasValidLocation() &&
"PathDiagnosticSpotPiece's must have a valid location.");
 if (addPosRange && Pos.hasRange()) addRange(Pos.asRange());
   }

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=358945&r1=358944&r2=358945&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Mon Apr 22 
19:50:38 2019
@@ -335,7 +335,7 @@ public:
 if (RegionOfInterest->isSubRegionOf(SelfRegion) &&
 potentiallyWritesIntoIvar(Call->getRuntimeDefinition().getDecl(),
   IvarR->getDecl()))
-  return maybeEmitNode(R, *Call, N, {}, SelfRegion, "self",
+  return maybeEmitNote(R, *Call, N, {}, SelfRegion, "self",
/*FirstIsReferenceType=*/false, 1);
   }
 }
@@ -344,7 +344,7 @@ public:
   const MemRegion *ThisR = CCall->getCXXThisVal().getAsRegion();
   if (RegionOfInterest->isSubRegionOf(ThisR)
   && !CCall->getDecl()->isImplicit())
-return maybeEmitNode(R, *Call, N, {}, ThisR, "this",
+return maybeEmitNote(R, *Call, N, {}, ThisR, "this",
  /*FirstIsReferenceType=*/false, 1);
 
   // Do not generate diagnostics for not modified parameters in
@@ -363,7 +363,7 @@ public:
   QualType T = PVD->getType();
   while (const MemRegion *MR = V.getAsRegion()) {
 if (RegionOfInterest->isSubRegionOf(MR) && !isPointerToConst(T))
-  return maybeEmitNode(R, *Call, N, {}, MR, ParamName,
+  return maybeEmitNote(R, *Call, N, {}, MR, ParamName,
ParamIsReferenceType, IndirectionLevel);
 
 QualType PT = T->getPointeeType();
@@ -371,7 +371,7 @@ public:
 
 if (const RecordDecl *RD = PT->getAsRecordDecl())
   if (auto P = findRegionOfInterestInRecord(RD, State, MR))
-return maybeEmitNode(R, *Call, N, *P, RegionOfInterest, ParamName,
+return maybeEmitNote(R, *Call, N, *P, RegionOfInterest, ParamName,
  ParamIsReferenceType, IndirectionLevel);
 
 V = State->getSVal(MR, PT);
@@ -549,7 +549,7 @@ private:
   /// \return Diagnostics piece for region not modified in the current 
function,
   /// if it decides to emit one.
   std::shared_ptr
-  maybeEmitNode(BugReport &R, const CallEvent &Call, const ExplodedNode *N,
+  maybeEmitNote(BugReport &R, const CallEvent &Call, const ExplodedNode *N,
 const RegionVector &FieldChain, const MemRegion *MatchedRegion,
 StringRef FirstElement, bool FirstIsReferenceType,
 unsigned IndirectionLevel) {
@@ -579,6 +579,9 @@ private:
 PathDiagnosticLocation L =
 PathDiagnosticLocation::create(N->getLocation(), SM);
 
+if (!L.hasValidLocation())
+  return nullptr;
+
 SmallString<256> sbuf;
 llvm::raw_svector_ostream os(sbuf);
 os << "Returning without writing to '";

Added: cfe/trunk/test/Analysis/OSAtomic_mac.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/OSAtomic_mac.c?rev

[PATCH] D60808: [analyzer] pr41335: NoStoreFuncVisitor: Fix crash when no-store event is in a body-farmed function.

2019-04-22 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC358945: [analyzer] PR41335: Fix crash when no-store event is 
in a body-farmed function. (authored by dergachev, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D60808?vs=195851&id=196175#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D60808

Files:
  include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
  lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  test/Analysis/OSAtomic_mac.c

Index: include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
===
--- include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
+++ include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
@@ -313,6 +313,8 @@
 
   bool hasRange() const { return K == StmtK || K == RangeK || K == DeclK; }
 
+  bool hasValidLocation() const { return asLocation().isValid(); }
+
   void invalidate() {
 *this = PathDiagnosticLocation();
   }
@@ -468,7 +470,7 @@
   PathDiagnosticPiece::Kind k,
   bool addPosRange = true)
   : PathDiagnosticPiece(s, k), Pos(pos) {
-assert(Pos.isValid() && Pos.asLocation().isValid() &&
+assert(Pos.isValid() && Pos.hasValidLocation() &&
"PathDiagnosticSpotPiece's must have a valid location.");
 if (addPosRange && Pos.hasRange()) addRange(Pos.asRange());
   }
Index: test/Analysis/OSAtomic_mac.c
===
--- test/Analysis/OSAtomic_mac.c
+++ test/Analysis/OSAtomic_mac.c
@@ -0,0 +1,20 @@
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,debug.ExprInspection \
+// RUN:-analyzer-output=text -verify %s
+
+int OSAtomicCompareAndSwapPtrBarrier(*, *, **);
+int OSAtomicCompareAndSwapPtrBarrier() {
+  // There is some body in the actual header,
+  // but we should trust our BodyFarm instead.
+}
+
+int *invalidSLocOnRedecl() {
+  int *b; // expected-note{{'b' declared without an initial value}}
+
+  OSAtomicCompareAndSwapPtrBarrier(0, 0, &b); // no-crash
+  // FIXME: We don't really need these notes.
+  // expected-note@-2{{Calling 'OSAtomicCompareAndSwapPtrBarrier'}}
+  // expected-note@-3{{Returning from 'OSAtomicCompareAndSwapPtrBarrier'}}
+
+  return b; // expected-warning{{Undefined or garbage value returned to caller}}
+// expected-note@-1{{Undefined or garbage value returned to caller}}
+}
Index: lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -335,7 +335,7 @@
 if (RegionOfInterest->isSubRegionOf(SelfRegion) &&
 potentiallyWritesIntoIvar(Call->getRuntimeDefinition().getDecl(),
   IvarR->getDecl()))
-  return maybeEmitNode(R, *Call, N, {}, SelfRegion, "self",
+  return maybeEmitNote(R, *Call, N, {}, SelfRegion, "self",
/*FirstIsReferenceType=*/false, 1);
   }
 }
@@ -344,7 +344,7 @@
   const MemRegion *ThisR = CCall->getCXXThisVal().getAsRegion();
   if (RegionOfInterest->isSubRegionOf(ThisR)
   && !CCall->getDecl()->isImplicit())
-return maybeEmitNode(R, *Call, N, {}, ThisR, "this",
+return maybeEmitNote(R, *Call, N, {}, ThisR, "this",
  /*FirstIsReferenceType=*/false, 1);
 
   // Do not generate diagnostics for not modified parameters in
@@ -363,7 +363,7 @@
   QualType T = PVD->getType();
   while (const MemRegion *MR = V.getAsRegion()) {
 if (RegionOfInterest->isSubRegionOf(MR) && !isPointerToConst(T))
-  return maybeEmitNode(R, *Call, N, {}, MR, ParamName,
+  return maybeEmitNote(R, *Call, N, {}, MR, ParamName,
ParamIsReferenceType, IndirectionLevel);
 
 QualType PT = T->getPointeeType();
@@ -371,7 +371,7 @@
 
 if (const RecordDecl *RD = PT->getAsRecordDecl())
   if (auto P = findRegionOfInterestInRecord(RD, State, MR))
-return maybeEmitNode(R, *Call, N, *P, RegionOfInterest, ParamName,
+return maybeEmitNote(R, *Call, N, *P, RegionOfInterest, ParamName,
  ParamIsReferenceType, IndirectionLevel);
 
 V = State->getSVal(MR, PT);
@@ -549,7 +549,7 @@
   /// \return Diagnostics piece for region not modified in the current function,
   /// if it decides to emit one.
   std::shared_ptr
-  maybeEmitNode(BugReport &R, const CallEvent &Call, const ExplodedNode *N,
+  maybeEmitNote(BugReport &R, const CallEvent &Call, const ExplodedNode *N,
 const RegionVector &FieldChain, const MemRegion *MatchedRegion,
 StringRef FirstElement, bool FirstIsReferenceType,
 

r358946 - [analyzer] Unbreak body farms in presence of multiple declarations.

2019-04-22 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Apr 22 19:56:00 2019
New Revision: 358946

URL: http://llvm.org/viewvc/llvm-project?rev=358946&view=rev
Log:
[analyzer] Unbreak body farms in presence of multiple declarations.

When growing a body on a body farm, it's essential to use the same redeclaration
of the function that's going to be used during analysis. Otherwise our
ParmVarDecls won't match the ones that are used to identify argument regions.

This boils down to trusting the reasoning in AnalysisDeclContext. We shouldn't
canonicalize the declaration before farming the body because it makes us not
obey the sophisticated decision-making process of AnalysisDeclContext.

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

Modified:
cfe/trunk/lib/Analysis/BodyFarm.cpp
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/OSAtomic_mac.c

Modified: cfe/trunk/lib/Analysis/BodyFarm.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BodyFarm.cpp?rev=358946&r1=358945&r2=358946&view=diff
==
--- cfe/trunk/lib/Analysis/BodyFarm.cpp (original)
+++ cfe/trunk/lib/Analysis/BodyFarm.cpp Mon Apr 22 19:56:00 2019
@@ -665,8 +665,6 @@ static Stmt *create_OSAtomicCompareAndSw
 }
 
 Stmt *BodyFarm::getBody(const FunctionDecl *D) {
-  D = D->getCanonicalDecl();
-
   Optional &Val = Bodies[D];
   if (Val.hasValue())
 return Val.getValue();

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=358946&r1=358945&r2=358946&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Mon Apr 22 
19:56:00 2019
@@ -579,6 +579,9 @@ private:
 PathDiagnosticLocation L =
 PathDiagnosticLocation::create(N->getLocation(), SM);
 
+// For now this shouldn't trigger, but once it does (as we add more
+// functions to the body farm), we'll need to decide if these reports
+// are worth suppressing as well.
 if (!L.hasValidLocation())
   return nullptr;
 

Modified: cfe/trunk/test/Analysis/OSAtomic_mac.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/OSAtomic_mac.c?rev=358946&r1=358945&r2=358946&view=diff
==
--- cfe/trunk/test/Analysis/OSAtomic_mac.c (original)
+++ cfe/trunk/test/Analysis/OSAtomic_mac.c Mon Apr 22 19:56:00 2019
@@ -8,13 +8,20 @@ int OSAtomicCompareAndSwapPtrBarrier() {
 }
 
 int *invalidSLocOnRedecl() {
-  int *b; // expected-note{{'b' declared without an initial value}}
-
+  // Was crashing when trying to throw a report about returning an 
uninitialized
+  // value to the caller. FIXME: We should probably still throw that report,
+  // something like "The "compare" part of CompareAndSwap depends on an
+  // undefined value".
+  int *b;
   OSAtomicCompareAndSwapPtrBarrier(0, 0, &b); // no-crash
-  // FIXME: We don't really need these notes.
-  // expected-note@-2{{Calling 'OSAtomicCompareAndSwapPtrBarrier'}}
-  // expected-note@-3{{Returning from 'OSAtomicCompareAndSwapPtrBarrier'}}
+  return b;
+}
 
-  return b; // expected-warning{{Undefined or garbage value returned to 
caller}}
-// expected-note@-1{{Undefined or garbage value returned to 
caller}}
+void testThatItActuallyWorks() {
+  void *x = 0;
+  int res = OSAtomicCompareAndSwapPtrBarrier(0, &x, &x);
+  clang_analyzer_eval(res); // expected-warning{{TRUE}}
+// expected-note@-1{{TRUE}}
+  clang_analyzer_eval(x == &x); // expected-warning{{TRUE}}
+// expected-note@-1{{TRUE}}
 }


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


[PATCH] D60899: [analyzer] Unbreak body farms in presence of multiple declarations.

2019-04-22 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL358946: [analyzer] Unbreak body farms in presence of 
multiple declarations. (authored by dergachev, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D60899?vs=195852&id=196176#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D60899

Files:
  cfe/trunk/lib/Analysis/BodyFarm.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  cfe/trunk/test/Analysis/OSAtomic_mac.c


Index: cfe/trunk/test/Analysis/OSAtomic_mac.c
===
--- cfe/trunk/test/Analysis/OSAtomic_mac.c
+++ cfe/trunk/test/Analysis/OSAtomic_mac.c
@@ -8,13 +8,20 @@
 }
 
 int *invalidSLocOnRedecl() {
-  int *b; // expected-note{{'b' declared without an initial value}}
-
+  // Was crashing when trying to throw a report about returning an 
uninitialized
+  // value to the caller. FIXME: We should probably still throw that report,
+  // something like "The "compare" part of CompareAndSwap depends on an
+  // undefined value".
+  int *b;
   OSAtomicCompareAndSwapPtrBarrier(0, 0, &b); // no-crash
-  // FIXME: We don't really need these notes.
-  // expected-note@-2{{Calling 'OSAtomicCompareAndSwapPtrBarrier'}}
-  // expected-note@-3{{Returning from 'OSAtomicCompareAndSwapPtrBarrier'}}
+  return b;
+}
 
-  return b; // expected-warning{{Undefined or garbage value returned to 
caller}}
-// expected-note@-1{{Undefined or garbage value returned to 
caller}}
+void testThatItActuallyWorks() {
+  void *x = 0;
+  int res = OSAtomicCompareAndSwapPtrBarrier(0, &x, &x);
+  clang_analyzer_eval(res); // expected-warning{{TRUE}}
+// expected-note@-1{{TRUE}}
+  clang_analyzer_eval(x == &x); // expected-warning{{TRUE}}
+// expected-note@-1{{TRUE}}
 }
Index: cfe/trunk/lib/Analysis/BodyFarm.cpp
===
--- cfe/trunk/lib/Analysis/BodyFarm.cpp
+++ cfe/trunk/lib/Analysis/BodyFarm.cpp
@@ -665,8 +665,6 @@
 }
 
 Stmt *BodyFarm::getBody(const FunctionDecl *D) {
-  D = D->getCanonicalDecl();
-
   Optional &Val = Bodies[D];
   if (Val.hasValue())
 return Val.getValue();
Index: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -579,6 +579,9 @@
 PathDiagnosticLocation L =
 PathDiagnosticLocation::create(N->getLocation(), SM);
 
+// For now this shouldn't trigger, but once it does (as we add more
+// functions to the body farm), we'll need to decide if these reports
+// are worth suppressing as well.
 if (!L.hasValidLocation())
   return nullptr;
 


Index: cfe/trunk/test/Analysis/OSAtomic_mac.c
===
--- cfe/trunk/test/Analysis/OSAtomic_mac.c
+++ cfe/trunk/test/Analysis/OSAtomic_mac.c
@@ -8,13 +8,20 @@
 }
 
 int *invalidSLocOnRedecl() {
-  int *b; // expected-note{{'b' declared without an initial value}}
-
+  // Was crashing when trying to throw a report about returning an uninitialized
+  // value to the caller. FIXME: We should probably still throw that report,
+  // something like "The "compare" part of CompareAndSwap depends on an
+  // undefined value".
+  int *b;
   OSAtomicCompareAndSwapPtrBarrier(0, 0, &b); // no-crash
-  // FIXME: We don't really need these notes.
-  // expected-note@-2{{Calling 'OSAtomicCompareAndSwapPtrBarrier'}}
-  // expected-note@-3{{Returning from 'OSAtomicCompareAndSwapPtrBarrier'}}
+  return b;
+}
 
-  return b; // expected-warning{{Undefined or garbage value returned to caller}}
-// expected-note@-1{{Undefined or garbage value returned to caller}}
+void testThatItActuallyWorks() {
+  void *x = 0;
+  int res = OSAtomicCompareAndSwapPtrBarrier(0, &x, &x);
+  clang_analyzer_eval(res); // expected-warning{{TRUE}}
+// expected-note@-1{{TRUE}}
+  clang_analyzer_eval(x == &x); // expected-warning{{TRUE}}
+// expected-note@-1{{TRUE}}
 }
Index: cfe/trunk/lib/Analysis/BodyFarm.cpp
===
--- cfe/trunk/lib/Analysis/BodyFarm.cpp
+++ cfe/trunk/lib/Analysis/BodyFarm.cpp
@@ -665,8 +665,6 @@
 }
 
 Stmt *BodyFarm::getBody(const FunctionDecl *D) {
-  D = D->getCanonicalDecl();
-
   Optional &Val = Bodies[D];
   if (Val.hasValue())
 return Val.getValue();
Index: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugRe

[PATCH] D60899: [analyzer] Unbreak body farms in presence of multiple declarations.

2019-04-22 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

With body farms, i think, the current declaration also remains unchanged, we're 
just getting a shining new `CompoundStmt` as a body in the middle of nowhere, 
i.e., `ADC->getDecl()->getBody()` isn't the same as `ADC->getBody()`. Which is, 
yeah, still weird :)


Repository:
  rC Clang

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

https://reviews.llvm.org/D60899



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


[PATCH] D60943: Delay diagnosing "n" constraint until after inlining

2019-04-22 Thread Bill Wendling via Phabricator via cfe-commits
void added a comment.

In D60943#1474926 , @rsmith wrote:

> In D60943#1474899 , @void wrote:
>
> > Here's the motivating bug report: 
> > https://bugs.llvm.org/show_bug.cgi?id=41027
>
>
> Thanks, that's illuminating. OK, if we want to support that code, then 
> there's really not much validation we can do in the frontend for constraints 
> that require immediate constants. Is `"n"` really special in this regard, or 
> is it just the first one that we've encountered?


I think it's just the first one we've encountered. There could be other 
constraints which require immediates, but they're probably target-specific. 
E.g. `e` and `K` for x86.

>> In general, I agree with you that diagnostics shouldn't depend on 
>> optimization levels, but inline assembly subverts this paradigm because it 
>> was originally a gcc extension. :-(
> 
> There is a question of how much weird stuff we should accept in the name of 
> GCC compatibility. In this case, the fact that the frontend rejects seems 
> like the tip of an iceberg: the code in the PR is also relying on the control 
> flow of the `&&` inside the `if` to be emitted in a very particular way (or 
> to be optimized to that form), and for dead-code elimination to be considered 
> and to actually fire, and probably more things besides. Do we at least still 
> produce a nice diagnostic if the value ends up not being a constant?

It does, but for the wrong line:

  [morbo@fawn:llvm] cat bad.c
  static __attribute__((always_inline)) void outl(unsigned port, unsigned data) 
{
asm volatile("outl %0,%w1" : : "a"(data), "n"(port));
  }
  
  void f(unsigned port) {
outl(port, 1);
  }
  [morbo@fawn:llvm] ./llvm.opt.install/bin/clang -c bad.c
  bad.c:2:16: error: constraint 'n' expects an integer constant expression
asm volatile("outl %0,%w1" : : "a"(data), "n"(port));
 ^
  1 error generated.

I'll need to modify the LLVM patch to output the correct location.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60943



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


[PATCH] D60408: [LibTooling] Extend Transformer to support multiple simultaneous changes.

2019-04-22 Thread Tianle Liu via Phabricator via cfe-commits
liutianle added a comment.

In D60408#1474100 , @ymandel wrote:

> In D60408#1473370 , @liutianle wrote:
>
> > hi ymandel,
> >  When I run "check-all", there are some warning/error in 
> > TransformerTest.cpp as follow. My version is llvm:0ee120077 and 
> > clang:d87ee8e678. Could you please have a fix or guild me how to fix it?
> >
> >  
> > ---
> >
> > In file included from 
> > myLLVM/llvm/utils/unittest/googlemock/include/gmock/internal/gmock-internal-utils.h:47:0,
> >
> >   from 
> > myLLVM/llvm/utils/unittest/googlemock/include/gmock/gmock-actions.h:46,
> >   from myLLVM/llvm/utils/unittest/googlemock/include/gmock/gmock.h:58,
> >   from myLLVM/llvm/tools/clang/unittests/Tooling/TransformerTest.cpp:13:
> >
> > myLLVM/llvm/utils/unittest/googletest/include/gtest/gtest.h: In 
> > instantiation of 'testing::AssertionResult 
> > testing::internal::CmpHelperEQ(const char*, const char*, const T1&, const 
> > T2&) [with T1 = long unsigned int; T2 = int]':
> >  myLLVM/llvm/utils/unittest/googletest/include/gtest/gtest.h:1421:23:   
> > required from 'static testing::AssertionResult 
> > testing::internal::EqHelper::Compare(const char*, 
> > const char*, const T1&, const T2&) [with T1 = long unsigned int; T2 = int; 
> > bool lhs_is_null_literal = false]'
> >  myLLVM/llvm/tools/clang/unittests/Tooling/TransformerTest.cpp:372:3:   
> > required from here
> >  myLLVM/llvm/utils/unittest/googletest/include/gtest/gtest.h:1392:11: 
> > warning: comparison between signed and unsigned integer expressions 
> > [-Wsign-compare]
> >
> >   if (lhs == rhs) {
> >   ^
> >
> >  
> > --
>
>
> Sorry about that. Have you sync'd to head? I thought that was fixed with 
> r358745 (from Bjorn Pettersson).


I see. Thank you very much!


Repository:
  rL LLVM

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

https://reviews.llvm.org/D60408



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


[PATCH] D58321: [WIP] Support for relative vtables

2019-04-22 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 196180.
leonardchan added a subscriber: mcgrathr.
leonardchan added a comment.
Herald added a subscriber: hiraditya.

Uploading my latest version of this patch and reporting some results. Will 
proceed with formatting and cleanup and ask for official reviews later.

___

After toying around with this for a bit, just enabling this flag on all c++ 
code in zircon shows about a 1% size increase in the final image (x64.zbi), but 
does its job of moving many vtables from .data.rel.ro to rodata. For each 
shared library that's included in the image, some of them decrease while most 
increase in size. These changes though are pretty small and rounded up align to 
page sizes (4kB), resulting in the overall 1% increase. This is mostly from 
extra instructions and extra PLT entries, through we have an idea for how we 
could reduce the PLT size.

We still get the benefits of moving vtables into rodata and having them shared 
between processes. Below is the section dump for one of our shared libraries 
(omitting the debug sections):

Without relative ABI

  Section Headers:
[Nr] Name  TypeAddress  OffSize   ES 
Flg Lk Inf Al
[ 0]   NULL 00 00 00
  0   0  0
[ 1] .note.gnu.build-id NOTE0270 000270 18 00   
A  0   0  4
[ 2] .dynsym   DYNSYM  0288 000288 000540 18   
A  5   1  8
[ 3] .gnu.hash GNU_HASH07c8 0007c8 50 00   
A  2   0  8
[ 4] .dynamic  DYNAMIC 0818 000818 000170 10   
A  5   0  8
[ 5] .dynstr   STRTAB  0988 000988 000424 00   
A  0   0  1
[ 6] .rela.dyn RELA0db0 000db0 a8 18   
A  2   0  8  # missing
[ 7] .relr.dyn 0013:  0e58 000e58 80 
08   A  0   0  8
[ 8] .rela.plt RELA0ed8 000ed8 000468 18   
A  2  15  8
[ 9] .rodata   PROGBITS1340 001340 0025c8 00 
AMS  0   0 16
[10] .eh_frame_hdr PROGBITS3908 003908 000a1c 00   
A  0   0  4
[11] .eh_frame PROGBITS4328 004328 0032cc 00   
A  0   0  8
[12] .text PROGBITS8000 008000 014c1b 00  
AX  0   0 16
[13] .plt  PROGBITS0001cc20 01cc20 000300 00  
AX  0   0 16
[14] .data.rel.ro  PROGBITS0001d000 01d000 001948 00  
WA  0   0 16
[15] .got.plt  PROGBITS0001e948 01e948 000190 00  
WA  0   0  8

With relative ABI

  Section Headers:
[Nr] Name  TypeAddress  OffSize   ES 
Flg Lk Inf Al
[ 0]   NULL 00 00 00
  0   0  0
[ 1] .note.gnu.build-id NOTE0270 000270 18 00   
A  0   0  4
[ 2] .dynsym   DYNSYM  0288 000288 000540 18   
A  5   1  8
[ 3] .gnu.hash GNU_HASH07c8 0007c8 50 00   
A  2   0  8
[ 4] .dynamic  DYNAMIC 0818 000818 000140 10   
A  5   0  8
[ 5] .dynstr   STRTAB  0958 000958 000424 00   
A  0   0  1
[ 6] .relr.dyn 0013:  0d80 000d80 68 
08   A  0   0  8
[ 7] .rela.plt RELA0de8 000de8 000480 18   
A  2  14  8
[ 8] .rodata   PROGBITS1270 001270 002990 00 
AMS  0   0 16
[ 9] .eh_frame_hdr PROGBITS3c00 003c00 000a1c 00   
A  0   0  4
[10] .eh_frame PROGBITS4620 004620 0032cc 00   
A  0   0  8
[11] .text PROGBITS8000 008000 014ffb 00  
AX  0   0 16
[12] .plt  PROGBITS0001d000 01d000 000310 00  
AX  0   0 16
[13] .data.rel.ro  PROGBITS0001e000 01e000 0012d0 00  
WA  0   0 16
[14] .got.plt  PROGBITS0001f2d0 01f2d0 000198 00  
WA  0   0  8
[15] .data PROGBITS0002 02 38 00  
WA  0   0 16
[16] .bss  NOBITS  00020038 020038 000100 00  
WA  0   0  8

We were also able to build libc++ with relative ABI and got ~2% decrease in 
size for the final shared library.

Other stuff in this patch:

- Remove any LTO related code
- Ensure `needsRelocation()` catches the relative offset function pointers


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58321

Files:
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/VTableBuilder.h
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/DeclCXX.cp

[PATCH] D59924: [PowerPC] [Clang] Port MMX intrinsics and basic test cases to Power

2019-04-22 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC358949: [PowerPC] [Clang] Port MMX intrinsics and basic test 
cases to Power (authored by chaofan, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D59924?vs=194446&id=196182#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D59924

Files:
  lib/Driver/CMakeLists.txt
  lib/Driver/Driver.cpp
  lib/Driver/ToolChains/PPCLinux.cpp
  lib/Driver/ToolChains/PPCLinux.h
  lib/Headers/CMakeLists.txt
  lib/Headers/ppc_wrappers/mmintrin.h
  test/CodeGen/ppc-mmintrin.c
  test/Headers/ppc-intrinsics.c

Index: test/CodeGen/ppc-mmintrin.c
===
--- test/CodeGen/ppc-mmintrin.c
+++ test/CodeGen/ppc-mmintrin.c
@@ -0,0 +1,60 @@
+// REQUIRES: powerpc-registered-target
+
+// RUN: %clang -S -emit-llvm -DNO_WARN_X86_INTRINSICS -mcpu=pwr8 -target powerpc64-gnu-linux %s \
+// RUN:-mllvm -disable-llvm-optzns -o - | llvm-cxxfilt | FileCheck %s --check-prefixes=CHECK,CHECK-BE
+// RUN: %clang -S -emit-llvm -DNO_WARN_X86_INTRINSICS -mcpu=pwr8 -target powerpc64le-gnu-linux %s \
+// RUN:-mllvm -disable-llvm-optzns -o - | llvm-cxxfilt | FileCheck %s --check-prefixes=CHECK,CHECK-LE
+
+#include 
+
+unsigned long long int ull1, ull2;
+__m64 m1, m2, res;
+
+void __attribute__((noinline))
+test_packs() {
+  res = _mm_packs_pu16((__m64)ull1, (__m64)ull2);
+  res = _mm_packs_pi16((__m64)ull1, (__m64)ull2);
+  res = _mm_packs_pi32((__m64)ull1, (__m64)ull2);
+}
+
+// CHECK-LABEL: @test_packs
+
+// CHECK: define available_externally i64 @_mm_packs_pu16(i64 [[REG1:[0-9a-zA-Z_%.]+]], i64 [[REG2:[0-9a-zA-Z_%.]+]])
+// CHECK: store i64 [[REG1]], i64* [[REG3:[0-9a-zA-Z_%.]+]], align 8
+// CHECK-NEXT: store i64 [[REG2]], i64* [[REG4:[0-9a-zA-Z_%.]+]], align 8
+// CHECK-LE: load i64, i64* [[REG3]], align 8
+// CHECK: load i64, i64* [[REG4]], align 8
+// CHECK-BE: load i64, i64* [[REG3]], align 8
+// CHECK: [[REG5:[0-9a-zA-Z_%.]+]] = call <8 x i16> @vec_cmplt
+// CHECK-NEXT: store <8 x i16> [[REG5]], <8 x i16>* [[REG6:[0-9a-zA-Z_%.]+]], align 16
+// CHECK-NEXT: [[REG7:[0-9a-zA-Z_%.]+]] = load <8 x i16>, <8 x i16>* [[REG8:[0-9a-zA-Z_%.]+]], align 16
+// CHECK-NEXT: [[REG9:[0-9a-zA-Z_%.]+]] = load <8 x i16>, <8 x i16>* [[REG8]], align 16
+// CHECK-NEXT: [[REG10:[0-9a-zA-Z_%.]+]] = call <16 x i8> @vec_packs(unsigned short vector[8], unsigned short vector[8])(<8 x i16> [[REG7]], <8 x i16> [[REG9]])
+// CHECK-NEXT: store <16 x i8> [[REG10]], <16 x i8>* [[REG11:[0-9a-zA-Z_%.]+]], align 16
+// CHECK-NEXT: [[REG12:[0-9a-zA-Z_%.]+]] = load <8 x i16>, <8 x i16>* [[REG6]], align 16
+// CHECK-NEXT: [[REG13:[0-9a-zA-Z_%.]+]] = load <8 x i16>, <8 x i16>* [[REG6]], align 16
+// CHECK-NEXT: [[REG14:[0-9a-zA-Z_%.]+]] = call <16 x i8> @vec_pack(bool vector[8], bool vector[8])(<8 x i16> [[REG12]], <8 x i16> [[REG13]])
+// CHECK-NEXT: store <16 x i8> [[REG14]], <16 x i8>* [[REG15:[0-9a-zA-Z_%.]+]], align 16
+// CHECK-NEXT: [[REG16:[0-9a-zA-Z_%.]+]] = load <16 x i8>, <16 x i8>* [[REG11]], align 16
+// CHECK-NEXT: [[REG17:[0-9a-zA-Z_%.]+]] = load <16 x i8>, <16 x i8>* [[REG15]], align 16
+// CHECK-NEXT: call <16 x i8> @vec_sel(unsigned char vector[16], unsigned char vector[16], bool vector[16])(<16 x i8> [[REG16]], <16 x i8> zeroinitializer, <16 x i8> [[REG17]])
+
+// CHECK: define available_externally i64 @_mm_packs_pi16(i64 [[REG18:[0-9a-zA-Z_%.]+]], i64 [[REG19:[0-9a-zA-Z_%.]+]])
+// CHECK: store i64 [[REG18]], i64* [[REG20:[0-9a-zA-Z_%.]+]], align 8
+// CHECK-NEXT: store i64 [[REG19]], i64* [[REG21:[0-9a-zA-Z_%.]+]], align 8
+// CHECK-LE: load i64, i64* [[REG20]], align 8
+// CHECK: load i64, i64* [[REG21]], align 8
+// CHECK-BE: load i64, i64* [[REG20]], align 8
+// CHECK: [[REG22:[0-9a-zA-Z_%.]+]] = load <8 x i16>, <8 x i16>* [[REG23:[0-9a-zA-Z_%.]+]], align 16
+// CHECK-NEXT: [[REG24:[0-9a-zA-Z_%.]+]] = load <8 x i16>, <8 x i16>* [[REG23]], align 16
+// CHECK-NEXT: call <16 x i8> @vec_packs(short vector[8], short vector[8])(<8 x i16> [[REG22]], <8 x i16> [[REG24]])
+
+// CHECK: define available_externally i64 @_mm_packs_pi32(i64 [[REG25:[0-9a-zA-Z_%.]+]], i64 [[REG26:[0-9a-zA-Z_%.]+]])
+// CHECK: store i64 [[REG25]], i64* [[REG27:[0-9a-zA-Z_%.]+]], align 8
+// CHECK-NEXT: store i64 [[REG26]], i64* [[REG28:[0-9a-zA-Z_%.]+]], align 8
+// CHECK-LE: load i64, i64* [[REG27]], align 8
+// CHECK: load i64, i64* [[REG28]], align 8
+// CHECK-BE: load i64, i64* [[REG27]], align 8
+// CHECK: [[REG29:[0-9a-zA-Z_%.]+]] = load <4 x i32>, <4 x i32>* [[REG30:[0-9a-zA-Z_%.]+]], align 16
+// CHECK-NEXT: [[REG31:[0-9a-zA-Z_%.]+]] = load <4 x i32>, <4 x i32>* [[REG30]], align 16
+// CHECK-NEXT: call <8 x i16> @vec_packs(int vector[4], int vector[4])(<4 x i32> [[REG29]], <4 x i32> [[REG31]])
Index: test/Headers/ppc-intrinsics.c
===
--- test/Headers/ppc-intrinsics.c
+++ test