[PATCH] D54565: Introduce `-Wctad` as a subgroup of `-Wc++14-compat`

2018-12-20 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

@rsmith ping! It's been a week since the last ping...


Repository:
  rC Clang

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

https://reviews.llvm.org/D54565



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


[PATCH] D47757: [Sema] Produce diagnostics when unavailable aligned allocation/deallocation functions are called

2018-12-20 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349890: [Sema] Produce diagnostics when C++17 aligned 
allocation/deallocation (authored by ahatanak, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D47757?vs=179195=179244#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D47757

Files:
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/Sema/SemaDeclCXX.cpp
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/lib/Sema/SemaExprCXX.cpp
  cfe/trunk/test/CXX/drs/dr2xx.cpp
  cfe/trunk/test/SemaCXX/unavailable_aligned_allocation.cpp

Index: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
===
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp
@@ -8288,6 +8288,7 @@
 }
   }
 
+  DiagnoseUseOfDecl(OperatorDelete, Loc);
   MarkFunctionReferenced(Loc, OperatorDelete);
   Destructor->setOperatorDelete(OperatorDelete, ThisArg);
 }
Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -66,6 +66,12 @@
 if (getLangOpts().CPlusPlus14 && FD->getReturnType()->isUndeducedType() &&
 DeduceReturnType(FD, SourceLocation(), /*Diagnose*/ false))
   return false;
+
+// See if this is an aligned allocation/deallocation function that is
+// unavailable.
+if (TreatUnavailableAsInvalid &&
+isUnavailableAlignedAllocationFunction(*FD))
+  return false;
   }
 
   // See if this function is unavailable.
@@ -228,6 +234,8 @@
 //   The function 'main' shall not be used within a program.
 if (cast(D)->isMain())
   Diag(Loc, diag::ext_main_used);
+
+diagnoseUnavailableAlignedAllocation(*cast(D), Loc);
   }
 
   // See if this is an auto-typed variable whose initializer we are parsing.
Index: cfe/trunk/lib/Sema/SemaExprCXX.cpp
===
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp
@@ -1744,28 +1744,33 @@
   return false;
 }
 
-// Emit a diagnostic if an aligned allocation/deallocation function that is not
-// implemented in the standard library is selected.
-static void diagnoseUnavailableAlignedAllocation(const FunctionDecl ,
- SourceLocation Loc, bool IsDelete,
- Sema ) {
-  if (!S.getLangOpts().AlignedAllocationUnavailable)
-return;
-
-  // Return if there is a definition.
+bool
+Sema::isUnavailableAlignedAllocationFunction(const FunctionDecl ) const {
+  if (!getLangOpts().AlignedAllocationUnavailable)
+return false;
   if (FD.isDefined())
-return;
-
+return false;
   bool IsAligned = false;
-  if (FD.isReplaceableGlobalAllocationFunction() && IsAligned) {
-const llvm::Triple  = S.getASTContext().getTargetInfo().getTriple();
+  if (FD.isReplaceableGlobalAllocationFunction() && IsAligned)
+return true;
+  return false;
+}
+
+// Emit a diagnostic if an aligned allocation/deallocation function that is not
+// implemented in the standard library is selected.
+void Sema::diagnoseUnavailableAlignedAllocation(const FunctionDecl ,
+SourceLocation Loc) {
+  if (isUnavailableAlignedAllocationFunction(FD)) {
+const llvm::Triple  = getASTContext().getTargetInfo().getTriple();
 StringRef OSName = AvailabilityAttr::getPlatformNameSourceSpelling(
-S.getASTContext().getTargetInfo().getPlatformName());
+getASTContext().getTargetInfo().getPlatformName());
 
-S.Diag(Loc, diag::err_aligned_allocation_unavailable)
+OverloadedOperatorKind Kind = FD.getDeclName().getCXXOverloadedOperator();
+bool IsDelete = Kind == OO_Delete || Kind == OO_Array_Delete;
+Diag(Loc, diag::err_aligned_allocation_unavailable)
 << IsDelete << FD.getType().getAsString() << OSName
 << alignedAllocMinVersion(T.getOS()).getAsString();
-S.Diag(Loc, diag::note_silence_aligned_allocation_unavailable);
+Diag(Loc, diag::note_silence_aligned_allocation_unavailable);
   }
 }
 
@@ -2149,13 +2154,11 @@
 if (DiagnoseUseOfDecl(OperatorNew, StartLoc))
   return ExprError();
 MarkFunctionReferenced(StartLoc, OperatorNew);
-diagnoseUnavailableAlignedAllocation(*OperatorNew, StartLoc, false, *this);
   }
   if (OperatorDelete) {
 if (DiagnoseUseOfDecl(OperatorDelete, StartLoc))
   return ExprError();
 MarkFunctionReferenced(StartLoc, OperatorDelete);
-diagnoseUnavailableAlignedAllocation(*OperatorDelete, StartLoc, true, *this);
   }
 
   // C++0x [expr.new]p17:
@@ -3405,8 +3408,7 @@
   }
 }
 
-diagnoseUnavailableAlignedAllocation(*OperatorDelete, StartLoc, true,
-   

r349890 - [Sema] Produce diagnostics when C++17 aligned allocation/deallocation

2018-12-20 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Dec 20 23:05:36 2018
New Revision: 349890

URL: http://llvm.org/viewvc/llvm-project?rev=349890=rev
Log:
[Sema] Produce diagnostics when C++17 aligned allocation/deallocation
functions that are unavailable on Darwin are explicitly called or called
from deleting destructors.

rdar://problem/40736230

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

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/CXX/drs/dr2xx.cpp
cfe/trunk/test/SemaCXX/unavailable_aligned_allocation.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=349890=349889=349890=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Dec 20 23:05:36 2018
@@ -5202,6 +5202,15 @@ public:
  SourceRange DirectInitRange,
  Expr *Initializer);
 
+  /// Determine whether \p FD is an aligned allocation or deallocation
+  /// function that is unavailable.
+  bool isUnavailableAlignedAllocationFunction(const FunctionDecl ) const;
+
+  /// Produce diagnostics if \p FD is an aligned allocation or deallocation
+  /// function that is unavailable.
+  void diagnoseUnavailableAlignedAllocation(const FunctionDecl ,
+SourceLocation Loc);
+
   bool CheckAllocatedType(QualType AllocType, SourceLocation Loc,
   SourceRange R);
 

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=349890=349889=349890=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Dec 20 23:05:36 2018
@@ -8288,6 +8288,7 @@ bool Sema::CheckDestructor(CXXDestructor
 }
   }
 
+  DiagnoseUseOfDecl(OperatorDelete, Loc);
   MarkFunctionReferenced(Loc, OperatorDelete);
   Destructor->setOperatorDelete(OperatorDelete, ThisArg);
 }

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=349890=349889=349890=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Dec 20 23:05:36 2018
@@ -66,6 +66,12 @@ bool Sema::CanUseDecl(NamedDecl *D, bool
 if (getLangOpts().CPlusPlus14 && FD->getReturnType()->isUndeducedType() &&
 DeduceReturnType(FD, SourceLocation(), /*Diagnose*/ false))
   return false;
+
+// See if this is an aligned allocation/deallocation function that is
+// unavailable.
+if (TreatUnavailableAsInvalid &&
+isUnavailableAlignedAllocationFunction(*FD))
+  return false;
   }
 
   // See if this function is unavailable.
@@ -228,6 +234,8 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *
 //   The function 'main' shall not be used within a program.
 if (cast(D)->isMain())
   Diag(Loc, diag::ext_main_used);
+
+diagnoseUnavailableAlignedAllocation(*cast(D), Loc);
   }
 
   // See if this is an auto-typed variable whose initializer we are parsing.

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=349890=349889=349890=diff
==
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Thu Dec 20 23:05:36 2018
@@ -1744,28 +1744,33 @@ static bool isLegalArrayNewInitializer(C
   return false;
 }
 
-// Emit a diagnostic if an aligned allocation/deallocation function that is not
-// implemented in the standard library is selected.
-static void diagnoseUnavailableAlignedAllocation(const FunctionDecl ,
- SourceLocation Loc, bool 
IsDelete,
- Sema ) {
-  if (!S.getLangOpts().AlignedAllocationUnavailable)
-return;
-
-  // Return if there is a definition.
+bool
+Sema::isUnavailableAlignedAllocationFunction(const FunctionDecl ) const {
+  if (!getLangOpts().AlignedAllocationUnavailable)
+return false;
   if (FD.isDefined())
-return;
-
+return false;
   bool IsAligned = false;
-  if (FD.isReplaceableGlobalAllocationFunction() && IsAligned) {
-const llvm::Triple  = S.getASTContext().getTargetInfo().getTriple();
+  if (FD.isReplaceableGlobalAllocationFunction() && IsAligned)
+return true;
+  return false;
+}
+
+// Emit a diagnostic if an aligned allocation/deallocation function that is not
+// implemented in the standard library is selected.
+void 

[PATCH] D55662: [Sema][ObjC] Do not warn about repeated uses of weak variables when the variables are accessed in an unevaluated context.

2018-12-20 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

In D55662#1337141 , @rjmccall wrote:

> In D55662#1336835 , @ahatanak wrote:
>
> > In D55662#1335773 , @rjmccall 
> > wrote:
> >
> > > Okay.  You may need to push an unevaluated context when doing that.
> >
> >
> > Since I'm just moving the call to `CheckPlaceholderExpr` to the call site, 
> > I don't think I have to push an unevaluated context there?
>
>
> Hmm.  Right, for the `auto` inference specifically it's fine because the 
> expression is in fact evaluated: we're not just eliminating placeholders in 
> order to resolve `decltype`, we're eliminating placeholders to actually 
> figure out what's going on with the initialization.


clang currently diagnose the repeated use of weak in the following case (with 
or without this patch):

  auto __weak wp = b.weakProp; 

I find this counterintuitive, but I guess this is the expected behavior?


Repository:
  rC Clang

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

https://reviews.llvm.org/D55662



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


[PATCH] D55640: [clang-tidy] Implement a check for large Objective-C type encodings 

2018-12-20 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore added a comment.

In D55640#1329390 , @theraven wrote:

> I wonder if we want to have an option to elide ObjC type info for all non-POD 
> C++ types.  Nothing that you do with the type encoding is likely to be 
> correct (for example, you can see the pointer field in a `std::shared_ptr`, 
> but you can't see that changes to it need to update reference counts) so it 
> probably does more harm than good.


I think it's worth investigating some kind of option for eliding Objective-C 
type information though I think that investigation is likely beyond the scope 
of this proposal. Eliding Objective-C type information could change runtime 
behavior of a variety of systems that rely on this information. This could 
include systems embedded in Apple's libraries as well as systems implemented in 
third party or open source libraries. I imagine that an investigation into such 
a feature would probably need to be quite thorough.




Comment at: clang-tidy/objc/TypeEncodingSizeCheck.cpp:36
+  objcPropertyDecl(unless(isExpansionInSystemHeader()),
+   
anyOf(hasAncestor(objcInterfaceDecl().bind("interface")),
+ hasAncestor(objcCategoryDecl().bind("category"

hokein wrote:
> `hasAncestor` is an expensive matcher, does `hasDeclContext` meet your use 
> cases?
I started looking into using `hasDeclContext` but encountered some unexpected 
behavior when adding relevant test cases—which should have been added from the 
beginning—to verify. I am going to continue investigating whether 
`hasDeclContext` is satisfactory here and try to resolve the unexpected 
behavior that I encountered.



Comment at: clang-tidy/objc/TypeEncodingSizeCheck.cpp:63
+  std::string TypeEncoding;
+  if (const auto *IvarDecl = dyn_cast(EncodedDecl)) {
+IvarDecl->getASTContext().getObjCEncodingForType(IvarDecl->getType(),

hokein wrote:
> Do you forget to register the matcher for `ObjCIvarDecl`? In the matcher you 
> register it for `ObjCPropertyDecl`, and `ObjCInterfaceDecl`, so this branch 
> will never be executed.
On line 32 in this diff is where I register the matcher for `ObjCIvarDecl`. The 
matching is functioning as I expect it should. Let me know if you want me to 
reorganize the matching logic.



Comment at: docs/clang-tidy/checks/objc-type-encoding-size.rst:6
+
+Finds Objective-C type encodings that exceed a configured threshold.
+

Eugene.Zelenko wrote:
> Please synchronize with Release Notes.
I changed the check description to match the release notes. Let me know if I 
misunderstood the requested change.


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

https://reviews.llvm.org/D55640



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


[PATCH] D55640: [clang-tidy] Implement a check for large Objective-C type encodings 

2018-12-20 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore updated this revision to Diff 179239.
stephanemoore marked 6 inline comments as done.
stephanemoore added a comment.

Changes:
• Assert on `EncodedDecl`.
• Mention default value in objc-type-encoding-size check notes.

Outstanding action items:
• Evaluate using `hasDeclContext` instead of `hasAncestor`.
• Include type encoding size information in diagnostic messages.


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

https://reviews.llvm.org/D55640

Files:
  clang-tidy/objc/CMakeLists.txt
  clang-tidy/objc/ObjCTidyModule.cpp
  clang-tidy/objc/TypeEncodingSizeCheck.cpp
  clang-tidy/objc/TypeEncodingSizeCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/objc-type-encoding-size.rst
  test/clang-tidy/objc-type-encoding-size.m

Index: test/clang-tidy/objc-type-encoding-size.m
===
--- /dev/null
+++ test/clang-tidy/objc-type-encoding-size.m
@@ -0,0 +1,69 @@
+// RUN: %check_clang_tidy %s objc-type-encoding-size %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: objc-type-encoding-size.Threshold, value: 15}]}' \
+// RUN: -- -fblocks
+
+typedef struct {
+  int a1;
+  int a2;
+  int a3;
+  int a4;
+  int a5;
+  int a6;
+  int a7;
+  int a8;
+  int a9;
+  int a10;
+  int a11;
+  int a12;
+} SixteenCharStruct;
+
+typedef struct {
+  int a1;
+} FiveCharStruct;
+
+typedef void (^BlockType)(SixteenCharStruct);
+
+@interface Foo {
+  SixteenCharStruct _someStruct;
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: Objective-C type encoding for
+  // '_someStruct' exceeds 15 characters [objc-type-encoding-size]
+
+  int _anInteger;
+}
+
+@property(nonatomic) SixteenCharStruct anotherStruct;
+// CHECK-MESSAGES: :[[@LINE-1]]:40: warning: Objective-C type encoding for
+// 'anotherStruct' exceeds 15 characters [objc-type-encoding-size]
+// CHECK-MESSAGES: :[[@LINE-3]]:40: warning: Objective-C type encoding for
+// 'setAnotherStruct:' exceeds 15 characters [objc-type-encoding-size]
+
+@property(nonatomic, setter=setAsparagus:) FiveCharStruct bananas;
+// CHECK-MESSAGES: :[[@LINE-1]]:59: warning: Objective-C type encoding for
+// 'bananas' exceeds 15 characters [objc-type-encoding-size]
+
+@end
+
+@implementation Foo
+
+- (void)bar:(SixteenCharStruct)a {
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: Objective-C type encoding for 'bar:'
+// exceeds 15 characters [objc-type-encoding-size]
+}
+
+- (int)doThing {
+  int (^block)(SixteenCharStruct) = ^(SixteenCharStruct a) {
+// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: Objective-C type encoding for
+// block expression exceeds 15 characters [objc-type-encoding-size]
+return a.a4 + 5;
+  };
+
+  return block(_someStruct);
+}
+
+- (const char *)str {
+  // We should not flag explicit encoding statements.
+  return @encode(SixteenCharStruct);
+}
+
+@end
Index: docs/clang-tidy/checks/objc-type-encoding-size.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/objc-type-encoding-size.rst
@@ -0,0 +1,14 @@
+.. title:: clang-tidy - objc-type-encoding-size
+
+objc-type-encoding-size
+===
+
+Detects Objective-C type encodings that exceed a configured threshold.
+
+Options
+---
+
+.. option:: Threshold
+
+   Flag Objective-C type encodings that exceed this number of bytes. The
+   default is `2000`.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -218,6 +218,7 @@
objc-avoid-spinlock
objc-forbidden-subclassing
objc-property-declaration
+   objc-type-encoding-size
performance-faster-string-find
performance-for-range-copy
performance-implicit-conversion-in-loop
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -174,6 +174,11 @@
   Detects usage of the deprecated member types of ``std::ios_base`` and replaces
   those that have a non-deprecated equivalent.
 
+- New :doc:`objc-type-encoding-size
+  ` check.
+
+  Detects Objective-C type encodings that exceed a configured threshold.
+
 - New :doc:`readability-isolate-decl
   ` check.
 
Index: clang-tidy/objc/TypeEncodingSizeCheck.h
===
--- /dev/null
+++ clang-tidy/objc/TypeEncodingSizeCheck.h
@@ -0,0 +1,34 @@
+//===--- TypeEncodingSizeCheck.h - clang-tidy -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "llvm/ADT/StringRef.h"
+
+namespace clang {
+namespace tidy {
+namespace objc {
+
+/// Finds Objective-C type 

[PATCH] D55984: [gn build] Embed __TEXT __info_plist section into clang binary on macOS

2018-12-20 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: phosek.

Verified by comparing the output of `otool -P bin/clang` between the GN and the 
CMake build.


https://reviews.llvm.org/D55984

Files:
  llvm/utils/gn/secondary/clang/tools/driver/BUILD.gn


Index: llvm/utils/gn/secondary/clang/tools/driver/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/tools/driver/BUILD.gn
+++ llvm/utils/gn/secondary/clang/tools/driver/BUILD.gn
@@ -1,4 +1,5 @@
 import("//llvm/utils/gn/build/symlink_or_copy.gni")
+import("//llvm/version.gni")
 
 symlinks = [
   # target_name, symlink_target pairs: GN doesn't support '+' in rule names.
@@ -33,6 +34,29 @@
   }
 }
 
+if (host_os == "mac") {
+  action("write_info_plist") {
+script = "//llvm/utils/gn/build/write_cmake_config.py"
+sources = [
+  "Info.plist.in",
+]
+outputs = [
+  "$target_gen_dir/Info.plist",
+]
+
+args = [
+  "-o",
+  rebase_path(outputs[0], root_out_dir),
+  rebase_path(sources[0], root_out_dir),
+
+  "TOOL_INFO_BUILD_VERSION=$llvm_version_major.$llvm_version_minor",
+  "TOOL_INFO_NAME=clang",
+  "TOOL_INFO_UTI=org.llvm.clang",
+  "TOOL_INFO_VERSION=$llvm_version",
+]
+  }
+}
+
 executable("clang") {
   configs += [ "//llvm/utils/gn/build:clang_code" ]
   deps = [
@@ -61,12 +85,16 @@
 "//llvm/lib/Transforms/Utils",
 "//llvm/lib/Transforms/Vectorize",
   ]
+  if (host_os == "mac") {
+deps += [ ":write_info_plist" ]
+plist = get_target_outputs(":write_info_plist")
+ldflags = [ "-Wl,-sectcreate,__TEXT,__info_plist," +
+rebase_path(plist[0], root_out_dir) ]
+  }
   sources = [
 "cc1_main.cpp",
 "cc1as_main.cpp",
 "cc1gen_reproducer_main.cpp",
 "driver.cpp",
   ]
-
-  # FIXME: Info.plist embedding for mac builds.
 }


Index: llvm/utils/gn/secondary/clang/tools/driver/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/tools/driver/BUILD.gn
+++ llvm/utils/gn/secondary/clang/tools/driver/BUILD.gn
@@ -1,4 +1,5 @@
 import("//llvm/utils/gn/build/symlink_or_copy.gni")
+import("//llvm/version.gni")
 
 symlinks = [
   # target_name, symlink_target pairs: GN doesn't support '+' in rule names.
@@ -33,6 +34,29 @@
   }
 }
 
+if (host_os == "mac") {
+  action("write_info_plist") {
+script = "//llvm/utils/gn/build/write_cmake_config.py"
+sources = [
+  "Info.plist.in",
+]
+outputs = [
+  "$target_gen_dir/Info.plist",
+]
+
+args = [
+  "-o",
+  rebase_path(outputs[0], root_out_dir),
+  rebase_path(sources[0], root_out_dir),
+
+  "TOOL_INFO_BUILD_VERSION=$llvm_version_major.$llvm_version_minor",
+  "TOOL_INFO_NAME=clang",
+  "TOOL_INFO_UTI=org.llvm.clang",
+  "TOOL_INFO_VERSION=$llvm_version",
+]
+  }
+}
+
 executable("clang") {
   configs += [ "//llvm/utils/gn/build:clang_code" ]
   deps = [
@@ -61,12 +85,16 @@
 "//llvm/lib/Transforms/Utils",
 "//llvm/lib/Transforms/Vectorize",
   ]
+  if (host_os == "mac") {
+deps += [ ":write_info_plist" ]
+plist = get_target_outputs(":write_info_plist")
+ldflags = [ "-Wl,-sectcreate,__TEXT,__info_plist," +
+rebase_path(plist[0], root_out_dir) ]
+  }
   sources = [
 "cc1_main.cpp",
 "cc1as_main.cpp",
 "cc1gen_reproducer_main.cpp",
 "driver.cpp",
   ]
-
-  # FIXME: Info.plist embedding for mac builds.
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55982: [OPENMP] Add support for explicit mapping of classes using 'this' pointer

2018-12-20 Thread Patrick Lyster via Phabricator via cfe-commits
patricklyster created this revision.
patricklyster added reviewers: ABataev, Hahnfeld, RaviNarayanaswamy, mikerice, 
kkwli0, hfinkel, gtbercea.
patricklyster added projects: clang, OpenMP.
Herald added subscribers: cfe-commits, guansong.

Add support for explicit mapping of `this` pointer in OpenMP 5.0. Example use 
case:

  class S {
int a;
void foo() {
  #pragma omp target map (this[0])
a = 1;
}
  };


Repository:
  rC Clang

https://reviews.llvm.org/D55982

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/target_ast_print.cpp
  clang/test/OpenMP/target_codegen.cpp
  clang/test/OpenMP/target_messages.cpp

Index: clang/test/OpenMP/target_messages.cpp
===
--- clang/test/OpenMP/target_messages.cpp
+++ clang/test/OpenMP/target_messages.cpp
@@ -43,6 +43,18 @@
 void foo() {
 }
 
+class S {
+  public:
+  void zee() {
+#pragma omp target map(this[:2]) // expected-note {{expected length on mapping of 'this' array section expression to be '1'}} // expected-error {{invalid 'this' expression on 'map' clause}}
+  int a;
+#pragma omp target map(this[1:1]) // expected-note {{expected lower bound on mapping of 'this' array section expression to be '0' or null}} // expected-error {{invalid 'this' expression on 'map' clause}}
+  int b;
+#pragma omp target map(this[1]) // expected-note {{expected 'this' subscript expression on map clause to be 'this[0]'}} // expected-error {{invalid 'this' expression on 'map' clause}}
+  int c;
+  }
+};
+
 #pragma omp target // expected-error {{unexpected OpenMP directive '#pragma omp target'}}
 
 int main(int argc, char **argv) {
Index: clang/test/OpenMP/target_codegen.cpp
===
--- clang/test/OpenMP/target_codegen.cpp
+++ clang/test/OpenMP/target_codegen.cpp
@@ -40,6 +40,7 @@
 
 // CHECK-DAG: [[TT:%.+]] = type { i64, i8 }
 // CHECK-DAG: [[S1:%.+]] = type { double }
+// CHECK-DAG: [[S2:%.+]] = type { i32, i32, i32 }
 // CHECK-DAG: [[ENTTY:%.+]] = type { i8*, i8*, i[[SZ:32|64]], i32, i32 }
 // CHECK-DAG: [[DEVTY:%.+]] = type { i8*, i8*, [[ENTTY]]*, [[ENTTY]]* }
 // CHECK-DAG: [[DSCTY:%.+]] = type { i32, [[DEVTY]]*, [[ENTTY]]*, [[ENTTY]]* }
@@ -48,8 +49,8 @@
 
 // CHECK-DAG: $[[REGFN:\.omp_offloading\..+]] = comdat
 
-// We have 8 target regions, but only 7 that actually will generate offloading
-// code and have mapped arguments, and only 5 have all-constant map sizes.
+// We have 9 target regions, but only 8 that actually will generate offloading
+// code and have mapped arguments, and only 6 have all-constant map sizes.
 
 // CHECK-DAG: [[SIZET:@.+]] = private unnamed_addr constant [2 x i[[SZ]]] [i[[SZ]] 0, i[[SZ]] 4]
 // CHECK-DAG: [[MAPT:@.+]] = private unnamed_addr constant [2 x i64] [i64 544, i64 800]
@@ -63,6 +64,9 @@
 // CHECK-DAG: [[SIZET6:@.+]] = private unnamed_addr constant [4 x i[[SZ]]] [i[[SZ]] 4, i[[SZ]] 2, i[[SZ]] 1, i[[SZ]] 40]
 // CHECK-DAG: [[MAPT6:@.+]] = private unnamed_addr constant [4 x i64] [i64 800, i64 800, i64 800, i64 547]
 // CHECK-DAG: [[MAPT7:@.+]] = private unnamed_addr constant [6 x i64] [i64 32, i64 281474976711171, i64 800, i64 288, i64 288, i64 547]
+// CHECK-DAG: [[SIZET9:@.+]] = private unnamed_addr constant [1 x i[[SZ]]] [i[[SZ]] 12]
+// CHECK-DAG: [[MAPT10:@.+]] = private unnamed_addr constant [1 x i64] [i64 35]
+// CHECK-DAG: @{{.*}} = weak constant i8 0
 // CHECK-DAG: @{{.*}} = weak constant i8 0
 // CHECK-DAG: @{{.*}} = weak constant i8 0
 // CHECK-DAG: @{{.*}} = weak constant i8 0
@@ -80,6 +84,7 @@
 // TCHECK: @{{.+}} = weak constant [[ENTTY]]
 // TCHECK: @{{.+}} = weak constant [[ENTTY]]
 // TCHECK: @{{.+}} = weak constant [[ENTTY]]
+// TCHECK: @{{.+}} = weak constant [[ENTTY]]
 // TCHECK-NOT: @{{.+}} = weak constant [[ENTTY]]
 
 // Check if offloading descriptor is created.
@@ -691,6 +696,31 @@
 
 // CHECK:   [[IFEND]]
 
+// CHECK: define {{.*}}@{{.*}}zee{{.*}}
+
+// CHECK:   [[LOCAL_THIS:%.+]] = alloca [[S2]]*
+// CHECK:   [[BP:%.+]] = alloca [1 x i8*]
+// CHECK:   [[P:%.+]] = alloca [1 x i8*]
+// CHECK:   [[LOCAL_THIS1:%.+]] = load [[S2]]*, [[S2]]** [[LOCAL_THIS]]
+// CHECK:   [[ARR_IDX:%.+]] = getelementptr inbounds [[S2]], [[S2]]* [[LOCAL_THIS1]], i[[SZ]] 0
+// CHECK:   [[ARR_IDX2:%.+]] = getelementptr inbounds [[S2]], [[S2]]* [[LOCAL_THIS1]], i[[SZ]] 0
+
+// CHECK-DAG:   [[BPADDR0:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[BP]], i32 0, i32 0
+// CHECK-DAG:   [[PADDR0:%.+]] =  getelementptr inbounds [1 x i8*], [1 x i8*]* [[P]], i32 0, i32 0
+// CHECK-DAG:   [[CBPADDR0:%.+]] = bitcast i8** [[BPADDR0]] to [[S2]]**
+// CHECK-DAG:   [[CPADDR0:%.+]] = bitcast i8** [[PADDR0]] to [[S2]]**
+// CHECK-DAG:   store [[S2]]* [[ARR_IDX]], [[S2]]** [[CBPADDR0]]
+// CHECK-DAG:   store [[S2]]* [[ARR_IDX2]], [[S2]]** [[CPADDR0]]
+
+// CHECK:

[PATCH] D55981: [gn build] Add build files for clang, clang-offload-bundler, and clang/lib/Headers

2018-12-20 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: phosek.
Herald added a subscriber: jfb.
thakis added a parent revision: D55980: [gn build] Add build file for 
clang/lib/FrontendTool.

With this, the GN build can build clang!


https://reviews.llvm.org/D55981

Files:
  llvm/utils/gn/secondary/BUILD.gn
  llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
  llvm/utils/gn/secondary/clang/tools/clang-offload-bundler/BUILD.gn
  llvm/utils/gn/secondary/clang/tools/driver/BUILD.gn

Index: llvm/utils/gn/secondary/clang/tools/driver/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang/tools/driver/BUILD.gn
@@ -0,0 +1,72 @@
+import("//llvm/utils/gn/build/symlink_or_copy.gni")
+
+symlinks = [
+  # target_name, symlink_target pairs: GN doesn't support '+' in rule names.
+  [
+"clangxx",
+"clang++",
+  ],
+  [
+"clang-cl",
+"clang-cl",
+  ],
+  [
+"clang-cpp",
+"clang-cpp",
+  ],
+]
+foreach(target, symlinks) {
+  symlink_or_copy(target[0]) {
+deps = [
+  ":clang",
+]
+source = "clang"
+output = "$root_out_dir/bin/${target[1]}"
+  }
+}
+
+# //:clang depends on this symlink target, see comment in //BUILD.gn.
+group("symlinks") {
+  deps = []
+  foreach(target, symlinks) {
+deps += [ ":${target[0]}" ]
+  }
+}
+
+executable("clang") {
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/include/clang/Config",
+"//clang/lib/Basic",
+"//clang/lib/CodeGen",
+"//clang/lib/Driver",
+"//clang/lib/Frontend",
+"//clang/lib/FrontendTool",
+"//clang/lib/Headers",
+"//clang/tools/clang-offload-bundler",
+"//llvm/include/llvm/Config:llvm-config",
+"//llvm/lib/Analysis",
+"//llvm/lib/CodeGen",
+"//llvm/lib/IR",
+"//llvm/lib/MC",
+"//llvm/lib/MC/MCParser",
+"//llvm/lib/Option",
+"//llvm/lib/Support",
+"//llvm/lib/Target:TargetsToBuild",
+"//llvm/lib/Transforms/IPO",
+"//llvm/lib/Transforms/InstCombine",
+"//llvm/lib/Transforms/Instrumentation",
+"//llvm/lib/Transforms/ObjCARC",
+"//llvm/lib/Transforms/Scalar",
+"//llvm/lib/Transforms/Utils",
+"//llvm/lib/Transforms/Vectorize",
+  ]
+  sources = [
+"cc1_main.cpp",
+"cc1as_main.cpp",
+"cc1gen_reproducer_main.cpp",
+"driver.cpp",
+  ]
+
+  # FIXME: Info.plist embedding for mac builds.
+}
Index: llvm/utils/gn/secondary/clang/tools/clang-offload-bundler/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang/tools/clang-offload-bundler/BUILD.gn
@@ -0,0 +1,13 @@
+executable("clang-offload-bundler") {
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/lib/Basic",
+"//llvm/lib/Bitcode/Writer",
+"//llvm/lib/IR",
+"//llvm/lib/Object",
+"//llvm/lib/Support",
+  ]
+  sources = [
+"ClangOffloadBundler.cpp",
+  ]
+}
Index: llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
@@ -0,0 +1,161 @@
+import("//clang/utils/TableGen/clang_tablegen.gni")
+import("//llvm/version.gni")
+
+output_dir = "$root_out_dir/lib/clang/$llvm_version/include"
+
+files = [
+  "adxintrin.h",
+  "altivec.h",
+  "ammintrin.h",
+  "arm_acle.h",
+  "armintr.h",
+  "arm64intr.h",
+  "avx2intrin.h",
+  "avx512bwintrin.h",
+  "avx512bitalgintrin.h",
+  "avx512vlbitalgintrin.h",
+  "avx512cdintrin.h",
+  "avx512vpopcntdqintrin.h",
+  "avx512dqintrin.h",
+  "avx512erintrin.h",
+  "avx512fintrin.h",
+  "avx512ifmaintrin.h",
+  "avx512ifmavlintrin.h",
+  "avx512pfintrin.h",
+  "avx512vbmiintrin.h",
+  "avx512vbmivlintrin.h",
+  "avx512vbmi2intrin.h",
+  "avx512vlvbmi2intrin.h",
+  "avx512vlbwintrin.h",
+  "avx512vlcdintrin.h",
+  "avx512vldqintrin.h",
+  "avx512vlintrin.h",
+  "avx512vpopcntdqvlintrin.h",
+  "avx512vnniintrin.h",
+  "avx512vlvnniintrin.h",
+  "avxintrin.h",
+  "bmi2intrin.h",
+  "bmiintrin.h",
+  "__clang_cuda_builtin_vars.h",
+  "__clang_cuda_cmath.h",
+  "__clang_cuda_complex_builtins.h",
+  "__clang_cuda_device_functions.h",
+  "__clang_cuda_intrinsics.h",
+  "__clang_cuda_libdevice_declares.h",
+  "__clang_cuda_math_forward_declares.h",
+  "__clang_cuda_runtime_wrapper.h",
+  "cetintrin.h",
+  "cldemoteintrin.h",
+  "clzerointrin.h",
+  "cpuid.h",
+  "clflushoptintrin.h",
+  "clwbintrin.h",
+  "emmintrin.h",
+  "f16cintrin.h",
+  "float.h",
+  "fma4intrin.h",
+  "fmaintrin.h",
+  "fxsrintrin.h",
+  "gfniintrin.h",
+  "htmintrin.h",
+  "htmxlintrin.h",
+  "ia32intrin.h",
+  "immintrin.h",
+  "intrin.h",
+  "inttypes.h",
+  "invpcidintrin.h",
+  "iso646.h",
+  "limits.h",
+  "lwpintrin.h",
+  "lzcntintrin.h",
+  "mm3dnow.h",
+  "mmintrin.h",
+  "mm_malloc.h",
+  "module.modulemap",
+  "movdirintrin.h",
+  "msa.h",
+  "mwaitxintrin.h",
+  "nmmintrin.h",
+  "opencl-c.h",
+  "pconfigintrin.h",
+  "pkuintrin.h",
+  

[PATCH] D21856: [Driver][OpenMP] Add support to create jobs for bundling actions.

2018-12-20 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.
Herald added a subscriber: guansong.

Sorry about the years-later question, but what's the motivation for shelling 
out to an external command here? In general, LLVM tries to use a library-based 
approach, and LLVM went e.g. through great lengths do use an integrated 
assembler so clang doesn't have to shell out to one. Concretely, why isn't 
there a clang/lib/OffloadBundle library that clang and clang-offload-bundler 
both use? Does the bundling have to happen out-of-process? And if so, why isn't 
the process something like `clang -cc1bundle` instead of a separate executable? 
It seems weird to make clang depend on another executable next to it.

I apologize for the clueless question.


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

https://reviews.llvm.org/D21856



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


[PATCH] D55891: [compiler-rt] [xray] [tests] Detect and handle missing LLVMTestingSupport gracefully

2018-12-20 Thread Dean Michael Berris via Phabricator via cfe-commits
dberris accepted this revision.
dberris added a comment.
This revision is now accepted and ready to land.

LGTM

Thanks, @mgorny!


Repository:
  rCRT Compiler Runtime

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

https://reviews.llvm.org/D55891



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


[PATCH] D55978: [gn build] Add build files for clang/lib/{ASTMatchers, CrossTU}, clang/lib/StaticAnalyzer/{Checkers, Core, Frontend}

2018-12-20 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

In D55978#1338651 , @george.karpenkov 
wrote:

> Looks reasonable, what about linking with Z3? Or is your goal just to get a 
> minimally working functionality?


Sorry, forgot to reply to this. I don't use this, so I feel someone who does 
want to use Z3 + GN should probably add support for this.


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

https://reviews.llvm.org/D55978



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


[PATCH] D55978: [gn build] Add build files for clang/lib/{ASTMatchers, CrossTU}, clang/lib/StaticAnalyzer/{Checkers, Core, Frontend}

2018-12-20 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Thanks for taking a look!

In D55978#1338654 , @george.karpenkov 
wrote:

> > I might want to default to clang_enable_static_analyzer=false when I add 
> > the clang/lib/FrontendTool build file.
>
> I don't think that quite makes sense, since by default clang does have the 
> analyzer built in.


Two points about this:

1. The GN build's main point is developer productivity (see 
llvm/utils/gn/README.rst). My guess is that most people don't work on the 
static analyzer, so if turning it off might make sense for that reason. (If the 
GN build gets adopted by people working on the static analyzer and less so by 
other people, this wouldn't make sense of course.)

2. I believe there's general agreement that if clang-tidy had existed when the 
static analyzer was first written, it would've been in clang-tidy, not in 
clang. Because of that, I think it might make sense to eventually move to a 
world where by default the analyzer is in clang-tidy but not in clang (but 
still have toggles to change that), and where the checker tests run through 
clang-tidy. (I don't mean to propose this at the moment, and it has some 
dependencies: ARCMigrate depends on the static analyzer and I think ARCMigrate 
isn't hooked up in clang-tidy at all at the moment. But at some point in the 
future I think this would make sense) The case for this is is imho stronger 
after r284112 which added ASTMatchers to the Checkers deps; historically we've 
tried to keep ASTMatchers out of the clang binary.

In any case, at the moment clang_enable_static_analyzer does default to true in 
the GN build. If I'm getting serious about changing that default, I'll cc you 
on that patch :-)


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

https://reviews.llvm.org/D55978



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


[PATCH] D55980: [gn build] Add build file for clang/lib/FrontendTool

2018-12-20 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: phosek.

https://reviews.llvm.org/D55980

Files:
  llvm/utils/gn/secondary/BUILD.gn
  llvm/utils/gn/secondary/clang/lib/FrontendTool/BUILD.gn


Index: llvm/utils/gn/secondary/clang/lib/FrontendTool/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang/lib/FrontendTool/BUILD.gn
@@ -0,0 +1,29 @@
+import("//clang/lib/ARCMigrate/enable.gni")
+import("//clang/lib/StaticAnalyzer/Frontend/enable.gni")
+
+assert(clang_enable_static_analyzer || !clang_enable_arcmt,
+   "Cannot disable static analyzer while enabling ARCMT")
+
+static_library("FrontendTool") {
+  output_name = "clangFrontendTool"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/include/clang/Config",
+"//clang/lib/Basic",
+"//clang/lib/CodeGen",
+"//clang/lib/Driver",
+"//clang/lib/Frontend",
+"//clang/lib/Frontend/Rewrite",
+"//llvm/lib/Option",
+"//llvm/lib/Support",
+  ]
+  if (clang_enable_arcmt) {
+deps += [ "//clang/lib/ARCMigrate" ]
+  }
+  if (clang_enable_static_analyzer) {
+deps += [ "//clang/lib/StaticAnalyzer/Frontend" ]
+  }
+  sources = [
+"ExecuteCompilerInvocation.cpp",
+  ]
+}
Index: llvm/utils/gn/secondary/BUILD.gn
===
--- llvm/utils/gn/secondary/BUILD.gn
+++ llvm/utils/gn/secondary/BUILD.gn
@@ -8,6 +8,7 @@
 "//clang/lib/Driver",
 "//clang/lib/Frontend",
 "//clang/lib/Frontend/Rewrite",
+"//clang/lib/FrontendTool",
 "//clang/lib/Index",
 "//clang/lib/Parse",
 "//clang/lib/Serialization",


Index: llvm/utils/gn/secondary/clang/lib/FrontendTool/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang/lib/FrontendTool/BUILD.gn
@@ -0,0 +1,29 @@
+import("//clang/lib/ARCMigrate/enable.gni")
+import("//clang/lib/StaticAnalyzer/Frontend/enable.gni")
+
+assert(clang_enable_static_analyzer || !clang_enable_arcmt,
+   "Cannot disable static analyzer while enabling ARCMT")
+
+static_library("FrontendTool") {
+  output_name = "clangFrontendTool"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/include/clang/Config",
+"//clang/lib/Basic",
+"//clang/lib/CodeGen",
+"//clang/lib/Driver",
+"//clang/lib/Frontend",
+"//clang/lib/Frontend/Rewrite",
+"//llvm/lib/Option",
+"//llvm/lib/Support",
+  ]
+  if (clang_enable_arcmt) {
+deps += [ "//clang/lib/ARCMigrate" ]
+  }
+  if (clang_enable_static_analyzer) {
+deps += [ "//clang/lib/StaticAnalyzer/Frontend" ]
+  }
+  sources = [
+"ExecuteCompilerInvocation.cpp",
+  ]
+}
Index: llvm/utils/gn/secondary/BUILD.gn
===
--- llvm/utils/gn/secondary/BUILD.gn
+++ llvm/utils/gn/secondary/BUILD.gn
@@ -8,6 +8,7 @@
 "//clang/lib/Driver",
 "//clang/lib/Frontend",
 "//clang/lib/Frontend/Rewrite",
+"//clang/lib/FrontendTool",
 "//clang/lib/Index",
 "//clang/lib/Parse",
 "//clang/lib/Serialization",
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55979: [gn build] Add build file for clang/lib/ARCMigrate

2018-12-20 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: phosek.
thakis added a parent revision: D55978: [gn build] Add build files for 
clang/lib/{ASTMatchers,CrossTU}, 
clang/lib/StaticAnalyzer/{Checkers,Core,Frontend}.

https://reviews.llvm.org/D55979

Files:
  llvm/utils/gn/secondary/BUILD.gn
  llvm/utils/gn/secondary/clang/lib/ARCMigrate/BUILD.gn


Index: llvm/utils/gn/secondary/clang/lib/ARCMigrate/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang/lib/ARCMigrate/BUILD.gn
@@ -0,0 +1,39 @@
+static_library("ARCMigrate") {
+  output_name = "clangARCMigrate"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/lib/AST",
+"//clang/lib/Analysis",
+"//clang/lib/Basic",
+"//clang/lib/Edit",
+"//clang/lib/Frontend",
+"//clang/lib/Lex",
+"//clang/lib/Rewrite",
+"//clang/lib/Sema",
+"//clang/lib/Serialization",
+"//clang/lib/StaticAnalyzer/Checkers",
+"//llvm/lib/Support",
+  ]
+  sources = [
+"ARCMT.cpp",
+"ARCMTActions.cpp",
+"FileRemapper.cpp",
+"ObjCMT.cpp",
+"PlistReporter.cpp",
+"TransAPIUses.cpp",
+"TransARCAssign.cpp",
+"TransAutoreleasePool.cpp",
+"TransBlockObjCVariable.cpp",
+"TransEmptyStatementsAndDealloc.cpp",
+"TransGCAttrs.cpp",
+"TransGCCalls.cpp",
+"TransProperties.cpp",
+"TransProtectedScope.cpp",
+"TransRetainReleaseDealloc.cpp",
+"TransUnbridgedCasts.cpp",
+"TransUnusedInitDelegate.cpp",
+"TransZeroOutPropsInDealloc.cpp",
+"TransformActions.cpp",
+"Transforms.cpp",
+  ]
+}
Index: llvm/utils/gn/secondary/BUILD.gn
===
--- llvm/utils/gn/secondary/BUILD.gn
+++ llvm/utils/gn/secondary/BUILD.gn
@@ -1,5 +1,6 @@
 group("default") {
   deps = [
+"//clang/lib/ARCMigrate",
 "//clang/lib/AST",
 "//clang/lib/ASTMatchers",
 "//clang/lib/CodeGen",


Index: llvm/utils/gn/secondary/clang/lib/ARCMigrate/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang/lib/ARCMigrate/BUILD.gn
@@ -0,0 +1,39 @@
+static_library("ARCMigrate") {
+  output_name = "clangARCMigrate"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/lib/AST",
+"//clang/lib/Analysis",
+"//clang/lib/Basic",
+"//clang/lib/Edit",
+"//clang/lib/Frontend",
+"//clang/lib/Lex",
+"//clang/lib/Rewrite",
+"//clang/lib/Sema",
+"//clang/lib/Serialization",
+"//clang/lib/StaticAnalyzer/Checkers",
+"//llvm/lib/Support",
+  ]
+  sources = [
+"ARCMT.cpp",
+"ARCMTActions.cpp",
+"FileRemapper.cpp",
+"ObjCMT.cpp",
+"PlistReporter.cpp",
+"TransAPIUses.cpp",
+"TransARCAssign.cpp",
+"TransAutoreleasePool.cpp",
+"TransBlockObjCVariable.cpp",
+"TransEmptyStatementsAndDealloc.cpp",
+"TransGCAttrs.cpp",
+"TransGCCalls.cpp",
+"TransProperties.cpp",
+"TransProtectedScope.cpp",
+"TransRetainReleaseDealloc.cpp",
+"TransUnbridgedCasts.cpp",
+"TransUnusedInitDelegate.cpp",
+"TransZeroOutPropsInDealloc.cpp",
+"TransformActions.cpp",
+"Transforms.cpp",
+  ]
+}
Index: llvm/utils/gn/secondary/BUILD.gn
===
--- llvm/utils/gn/secondary/BUILD.gn
+++ llvm/utils/gn/secondary/BUILD.gn
@@ -1,5 +1,6 @@
 group("default") {
   deps = [
+"//clang/lib/ARCMigrate",
 "//clang/lib/AST",
 "//clang/lib/ASTMatchers",
 "//clang/lib/CodeGen",
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55875: [analyzer] pr38668: RegionStore: Do not attempt to cast loaded values of non-scalar types.

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

I'll test this more thoroughly. In case it's still wrong, here's a safer fix.


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

https://reviews.llvm.org/D55875

Files:
  lib/StaticAnalyzer/Core/Store.cpp
  test/Analysis/casts.c


Index: test/Analysis/casts.c
===
--- test/Analysis/casts.c
+++ test/Analysis/casts.c
@@ -213,3 +213,35 @@
 }
 
 #endif
+
+char no_crash_SymbolCast_of_float_type_aux(int *p) {
+  *p += 1;
+  return *p;
+}
+
+void no_crash_SymbolCast_of_float_type() {
+  extern float x;
+  char (*f)() = no_crash_SymbolCast_of_float_type_aux;
+  f();
+}
+
+double no_crash_reinterpret_double_as_int(double a) {
+  *(int *) = 1;
+  return a * a;
+}
+
+double no_crash_reinterpret_double_as_ptr(double a) {
+  *(void **) = 0;
+  return a * a;
+}
+
+double no_crash_reinterpret_double_as_sym_int(double a, int b) {
+  *(int *) = b;
+  return a * a;
+}
+
+double no_crash_reinterpret_double_as_sym_ptr(double a, void * b) {
+  *(void **) = b;
+  return a * a;
+}
+
Index: lib/StaticAnalyzer/Core/Store.cpp
===
--- lib/StaticAnalyzer/Core/Store.cpp
+++ lib/StaticAnalyzer/Core/Store.cpp
@@ -402,6 +402,12 @@
   if (castTy.isNull() || V.isUnknownOrUndef())
 return V;
 
+  if (castTy->isFloatingType()) {
+SymbolRef Sym = V.getAsSymbol();
+if (Sym && !Sym->getType()->isFloatingType())
+  return UnknownVal();
+  }
+
   // When retrieving symbolic pointer and expecting a non-void pointer,
   // wrap them into element regions of the expected type if necessary.
   // SValBuilder::dispatchCast() doesn't do that, but it is necessary to


Index: test/Analysis/casts.c
===
--- test/Analysis/casts.c
+++ test/Analysis/casts.c
@@ -213,3 +213,35 @@
 }
 
 #endif
+
+char no_crash_SymbolCast_of_float_type_aux(int *p) {
+  *p += 1;
+  return *p;
+}
+
+void no_crash_SymbolCast_of_float_type() {
+  extern float x;
+  char (*f)() = no_crash_SymbolCast_of_float_type_aux;
+  f();
+}
+
+double no_crash_reinterpret_double_as_int(double a) {
+  *(int *) = 1;
+  return a * a;
+}
+
+double no_crash_reinterpret_double_as_ptr(double a) {
+  *(void **) = 0;
+  return a * a;
+}
+
+double no_crash_reinterpret_double_as_sym_int(double a, int b) {
+  *(int *) = b;
+  return a * a;
+}
+
+double no_crash_reinterpret_double_as_sym_ptr(double a, void * b) {
+  *(void **) = b;
+  return a * a;
+}
+
Index: lib/StaticAnalyzer/Core/Store.cpp
===
--- lib/StaticAnalyzer/Core/Store.cpp
+++ lib/StaticAnalyzer/Core/Store.cpp
@@ -402,6 +402,12 @@
   if (castTy.isNull() || V.isUnknownOrUndef())
 return V;
 
+  if (castTy->isFloatingType()) {
+SymbolRef Sym = V.getAsSymbol();
+if (Sym && !Sym->getType()->isFloatingType())
+  return UnknownVal();
+  }
+
   // When retrieving symbolic pointer and expecting a non-void pointer,
   // wrap them into element regions of the expected type if necessary.
   // SValBuilder::dispatchCast() doesn't do that, but it is necessary to
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55875: [analyzer] pr38668: RegionStore: Do not attempt to cast loaded values of non-scalar types.

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

Add a few more tests, just in case.


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

https://reviews.llvm.org/D55875

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
  lib/StaticAnalyzer/Core/SVals.cpp
  lib/StaticAnalyzer/Core/Store.cpp
  test/Analysis/casts.c

Index: test/Analysis/casts.c
===
--- test/Analysis/casts.c
+++ test/Analysis/casts.c
@@ -213,3 +213,35 @@
 }
 
 #endif
+
+char no_crash_SymbolCast_of_float_type_aux(int *p) {
+  *p += 1;
+  return *p;
+}
+
+void no_crash_SymbolCast_of_float_type() {
+  extern float x;
+  char (*f)() = no_crash_SymbolCast_of_float_type_aux;
+  f();
+}
+
+double no_crash_reinterpret_double_as_int(double a) {
+  *(int *) = 1;
+  return a * a;
+}
+
+double no_crash_reinterpret_double_as_ptr(double a) {
+  *(void **) = 0;
+  return a * a;
+}
+
+double no_crash_reinterpret_double_as_sym_int(double a, int b) {
+  *(int *) = b;
+  return a * a;
+}
+
+double no_crash_reinterpret_double_as_sym_ptr(double a, void * b) {
+  *(void **) = b;
+  return a * a;
+}
+
Index: lib/StaticAnalyzer/Core/Store.cpp
===
--- lib/StaticAnalyzer/Core/Store.cpp
+++ lib/StaticAnalyzer/Core/Store.cpp
@@ -394,14 +394,29 @@
   return UnknownVal();
 }
 
+static bool isScalarEnoughToAttemptACast(QualType T) {
+  return T->isIntegralOrEnumerationType() || Loc::isLocType(T);
+}
+
 /// CastRetrievedVal - Used by subclasses of StoreManager to implement
 ///  implicit casts that arise from loads from regions that are reinterpreted
 ///  as another region.
 SVal StoreManager::CastRetrievedVal(SVal V, const TypedValueRegion *R,
-QualType castTy) {
-  if (castTy.isNull() || V.isUnknownOrUndef())
+QualType CastTy) {
+  if (CastTy.isNull() || V.isUnknownOrUndef())
+return V;
+
+  QualType OrigTy = V.detectType(StateMgr.getContext());
+  if (OrigTy.isNull())
 return V;
 
+  if (!isScalarEnoughToAttemptACast(OrigTy) ||
+  !isScalarEnoughToAttemptACast(CastTy)) {
+if (OrigTy.getUnqualifiedType() == CastTy.getUnqualifiedType())
+  return V;
+return UnknownVal();
+  }
+
   // When retrieving symbolic pointer and expecting a non-void pointer,
   // wrap them into element regions of the expected type if necessary.
   // SValBuilder::dispatchCast() doesn't do that, but it is necessary to
@@ -410,13 +425,13 @@
   // We might need to do that for non-void pointers as well.
   // FIXME: We really need a single good function to perform casts for us
   // correctly every time we need it.
-  if (castTy->isPointerType() && !castTy->isVoidPointerType())
+  if (CastTy->isPointerType() && !CastTy->isVoidPointerType())
 if (const auto *SR = dyn_cast_or_null(V.getAsRegion()))
   if (SR->getSymbol()->getType().getCanonicalType() !=
-  castTy.getCanonicalType())
-return loc::MemRegionVal(castRegion(SR, castTy));
+  CastTy.getCanonicalType())
+return loc::MemRegionVal(castRegion(SR, CastTy));
 
-  return svalBuilder.dispatchCast(V, castTy);
+  return svalBuilder.dispatchCast(V, CastTy);
 }
 
 SVal StoreManager::getLValueFieldOrIvar(const Decl *D, SVal Base) {
Index: lib/StaticAnalyzer/Core/SVals.cpp
===
--- lib/StaticAnalyzer/Core/SVals.cpp
+++ lib/StaticAnalyzer/Core/SVals.cpp
@@ -21,6 +21,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SValVisitor.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
 #include "llvm/ADT/Optional.h"
@@ -185,6 +186,59 @@
   return DD;
 }
 
+namespace {
+class TypeDetector : public SValVisitor {
+  ASTContext 
+
+public:
+  TypeDetector(ASTContext ): ACtx(ACtx) {}
+
+  QualType VisitSVal(SVal V) { return QualType(); }
+
+  QualType VisitNonLocSymbolVal(nonloc::SymbolVal V) {
+return V.getSymbol()->getType();
+  }
+
+  QualType VisitLocMemRegionVal(loc::MemRegionVal V) {
+if (const auto *TR = dyn_cast(V.getRegion()))
+  return TR->getLocationType();
+else
+  return ACtx.VoidPtrTy;
+  }
+
+  QualType VisitNonLocConcreteInt(nonloc::ConcreteInt V) {
+const llvm::APSInt  = V.getValue();
+return ACtx.getIntTypeForBitwidth(I.getBitWidth(), I.isSigned());
+  }
+
+  QualType VisitLocConcreteInt(loc::ConcreteInt V) {
+return ACtx.VoidPtrTy;
+  }
+
+  QualType VisitNonLocLocAsInteger(nonloc::LocAsInteger V) {
+// FIXME: This returns an unsigned type because LocAsInteger
+// does not remember what is 

[PATCH] D55978: [gn build] Add build files for clang/lib/{ASTMatchers, CrossTU}, clang/lib/StaticAnalyzer/{Checkers, Core, Frontend}

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

> I might want to default to clang_enable_static_analyzer=false when I add the 
> clang/lib/FrontendTool build file.

I don't think that quite makes sense, since by default clang does have the 
analyzer built in.


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

https://reviews.llvm.org/D55978



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


[PATCH] D55978: [gn build] Add build files for clang/lib/{ASTMatchers, CrossTU}, clang/lib/StaticAnalyzer/{Checkers, Core, Frontend}

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

Looks reasonable, what about linking with Z3? Or is your goal just to get a 
minimally working functionality?


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

https://reviews.llvm.org/D55978



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


r349876 - [analyzer] Perform escaping in RetainCountChecker on type mismatch even for inlined functions

2018-12-20 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Thu Dec 20 18:16:36 2018
New Revision: 349876

URL: http://llvm.org/viewvc/llvm-project?rev=349876=rev
Log:
[analyzer] Perform escaping in RetainCountChecker on type mismatch even for 
inlined functions

The fix done in D55465 did not previously apply when the function was inlined.

rdar://46889541

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

Modified:

cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
cfe/trunk/test/Analysis/osobject-retain-release.cpp

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp?rev=349876=349875=349876=diff
==
--- 
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp 
(original)
+++ 
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp 
Thu Dec 20 18:16:36 2018
@@ -502,6 +502,25 @@ static Optional refValFromRetEff
   return None;
 }
 
+static bool isPointerToObject(QualType QT) {
+  QualType PT = QT->getPointeeType();
+  if (!PT.isNull())
+if (PT->getAsCXXRecordDecl())
+  return true;
+  return false;
+}
+
+/// Whether the tracked value should be escaped on a given call.
+/// OSObjects are escaped when passed to void * / etc.
+static bool shouldEscapeArgumentOnCall(const CallEvent , unsigned ArgIdx,
+   const RefVal *TrackedValue) {
+  if (TrackedValue->getObjKind() != RetEffect::OS)
+return false;
+  if (ArgIdx >= CE.parameters().size())
+return false;
+  return !isPointerToObject(CE.parameters()[ArgIdx]->getType());
+}
+
 // We don't always get the exact modeling of the function with regards to the
 // retain count checker even when the function is inlined. For example, we need
 // to stop tracking the symbols which were marked with StopTrackingHard.
@@ -512,11 +531,16 @@ void RetainCountChecker::processSummaryO
 
   // Evaluate the effect of the arguments.
   for (unsigned idx = 0, e = CallOrMsg.getNumArgs(); idx != e; ++idx) {
-if (Summ.getArg(idx) == StopTrackingHard) {
-  SVal V = CallOrMsg.getArgSVal(idx);
-  if (SymbolRef Sym = V.getAsLocSymbol()) {
+SVal V = CallOrMsg.getArgSVal(idx);
+
+if (SymbolRef Sym = V.getAsLocSymbol()) {
+  bool ShouldRemoveBinding = Summ.getArg(idx) == StopTrackingHard;
+  if (const RefVal *T = getRefBinding(state, Sym))
+if (shouldEscapeArgumentOnCall(CallOrMsg, idx, T))
+  ShouldRemoveBinding = true;
+
+  if (ShouldRemoveBinding)
 state = removeRefBinding(state, Sym);
-  }
 }
   }
 
@@ -574,25 +598,6 @@ static ProgramStateRef updateOutParamete
   return State;
 }
 
-static bool isPointerToObject(QualType QT) {
-  QualType PT = QT->getPointeeType();
-  if (!PT.isNull())
-if (PT->getAsCXXRecordDecl())
-  return true;
-  return false;
-}
-
-/// Whether the tracked value should be escaped on a given call.
-/// OSObjects are escaped when passed to void * / etc.
-static bool shouldEscapeArgumentOnCall(const CallEvent , unsigned ArgIdx,
-   const RefVal *TrackedValue) {
-  if (TrackedValue->getObjKind() != RetEffect::OS)
-return false;
-  if (ArgIdx >= CE.parameters().size())
-return false;
-  return !isPointerToObject(CE.parameters()[ArgIdx]->getType());
-}
-
 void RetainCountChecker::checkSummary(const RetainSummary ,
   const CallEvent ,
   CheckerContext ) const {

Modified: cfe/trunk/test/Analysis/osobject-retain-release.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/osobject-retain-release.cpp?rev=349876=349875=349876=diff
==
--- cfe/trunk/test/Analysis/osobject-retain-release.cpp (original)
+++ cfe/trunk/test/Analysis/osobject-retain-release.cpp Thu Dec 20 18:16:36 2018
@@ -90,7 +90,10 @@ struct OSMetaClassBase {
   static OSObject *safeMetaCast(const OSObject *inst, const OSMetaClass *meta);
 };
 
+typedef unsigned long MYTYPE;
+
 void escape(void *);
+void escape_with_source(MYTYPE p) {}
 bool coin();
 
 bool os_consume_violation_two_args(OS_CONSUME OSObject *obj, bool extra) {
@@ -139,6 +142,13 @@ void test_escaping_into_voidstar() {
   escape(obj);
 }
 
+void test_escape_has_source() {
+  OSObject *obj = new OSObject;
+  if (obj)
+escape_with_source((MYTYPE)obj);
+  return;
+}
+
 void test_no_infinite_check_recursion(MyArray *arr) {
   OSObject *input = new OSObject;
   OSObject *o = arr->generateObject(input);


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


[PATCH] D55978: [gn build] Add build files for clang/lib/{ASTMatchers, CrossTU}, clang/lib/StaticAnalyzer/{Checkers, Core, Frontend}

2018-12-20 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: phosek.
Herald added subscribers: dkrupp, donat.nagy, jfb, Szelethus, arphaman, 
a.sidorin, baloghadamsoftware.
Herald added a reviewer: george.karpenkov.

The intent is to add the build file for clang/lib/StaticAnalyzer/Frontend; 
everything else is pulled in by that.

It's close to 200 TUs; I might want to default to 
clang_enable_static_analyzer=false when I add the clang/lib/FrontendTool build 
file.


https://reviews.llvm.org/D55978

Files:
  llvm/utils/gn/secondary/BUILD.gn
  llvm/utils/gn/secondary/clang/lib/ASTMatchers/BUILD.gn
  llvm/utils/gn/secondary/clang/lib/CrossTU/BUILD.gn
  llvm/utils/gn/secondary/clang/lib/Index/BUILD.gn
  llvm/utils/gn/secondary/clang/lib/StaticAnalyzer/Checkers/BUILD.gn
  llvm/utils/gn/secondary/clang/lib/StaticAnalyzer/Core/BUILD.gn
  llvm/utils/gn/secondary/clang/lib/StaticAnalyzer/Frontend/BUILD.gn

Index: llvm/utils/gn/secondary/clang/lib/StaticAnalyzer/Frontend/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang/lib/StaticAnalyzer/Frontend/BUILD.gn
@@ -0,0 +1,23 @@
+static_library("Frontend") {
+  output_name = "clangStaticAnalyzerFrontend"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/lib/AST",
+"//clang/lib/Analysis",
+"//clang/lib/Basic",
+"//clang/lib/CrossTU",
+"//clang/lib/Frontend",
+"//clang/lib/Lex",
+"//clang/lib/StaticAnalyzer/Checkers",
+"//clang/lib/StaticAnalyzer/Core",
+"//llvm/lib/Support",
+  ]
+  sources = [
+"AnalysisConsumer.cpp",
+"CheckerRegistration.cpp",
+"CheckerRegistry.cpp",
+"FrontendActions.cpp",
+"ModelConsumer.cpp",
+"ModelInjector.cpp",
+  ]
+}
Index: llvm/utils/gn/secondary/clang/lib/StaticAnalyzer/Core/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang/lib/StaticAnalyzer/Core/BUILD.gn
@@ -0,0 +1,67 @@
+static_library("Core") {
+  output_name = "clangStaticAnalyzerCore"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/include/clang/Config",
+"//clang/lib/AST",
+"//clang/lib/ASTMatchers",
+"//clang/lib/Analysis",
+"//clang/lib/Basic",
+"//clang/lib/CrossTU",
+"//clang/lib/Lex",
+"//clang/lib/Rewrite",
+"//llvm/lib/Support",
+  ]
+  sources = [
+"APSIntType.cpp",
+"AnalysisManager.cpp",
+"AnalyzerOptions.cpp",
+"BasicValueFactory.cpp",
+"BlockCounter.cpp",
+"BugReporter.cpp",
+"BugReporterVisitors.cpp",
+"CallEvent.cpp",
+"Checker.cpp",
+"CheckerContext.cpp",
+"CheckerHelpers.cpp",
+"CheckerManager.cpp",
+"CommonBugCategories.cpp",
+"ConstraintManager.cpp",
+"CoreEngine.cpp",
+"DynamicTypeMap.cpp",
+"Environment.cpp",
+"ExplodedGraph.cpp",
+"ExprEngine.cpp",
+"ExprEngineC.cpp",
+"ExprEngineCXX.cpp",
+"ExprEngineCallAndReturn.cpp",
+"ExprEngineObjC.cpp",
+"FunctionSummary.cpp",
+"HTMLDiagnostics.cpp",
+"IssueHash.cpp",
+"LoopUnrolling.cpp",
+"LoopWidening.cpp",
+"MemRegion.cpp",
+"PathDiagnostic.cpp",
+"PlistDiagnostics.cpp",
+"ProgramState.cpp",
+"RangeConstraintManager.cpp",
+"RangedConstraintManager.cpp",
+"RegionStore.cpp",
+"RetainSummaryManager.cpp",
+"SValBuilder.cpp",
+"SVals.cpp",
+"SarifDiagnostics.cpp",
+"SimpleConstraintManager.cpp",
+"SimpleSValBuilder.cpp",
+"Store.cpp",
+"SubEngine.cpp",
+"SymbolManager.cpp",
+"TaintManager.cpp",
+"WorkList.cpp",
+"Z3ConstraintManager.cpp",
+  ]
+
+  # FIXME: clang/Config/BUILD.gn currently always sets CLANG_ANALYZER_WITH_Z3
+  # to false. If that changes we need to link to Z3 libs here.
+}
Index: llvm/utils/gn/secondary/clang/lib/StaticAnalyzer/Checkers/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang/lib/StaticAnalyzer/Checkers/BUILD.gn
@@ -0,0 +1,114 @@
+static_library("Checkers") {
+  output_name = "clangStaticAnalyzerCheckers"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/include/clang/StaticAnalyzer/Checkers",
+"//clang/lib/AST",
+"//clang/lib/ASTMatchers",
+"//clang/lib/Analysis",
+"//clang/lib/Basic",
+"//clang/lib/Lex",
+"//clang/lib/StaticAnalyzer/Core",
+"//llvm/lib/Support",
+  ]
+  sources = [
+"AnalysisOrderChecker.cpp",
+"AnalyzerStatsChecker.cpp",
+"ArrayBoundChecker.cpp",
+"ArrayBoundCheckerV2.cpp",
+"BasicObjCFoundationChecks.cpp",
+"BlockInCriticalSectionChecker.cpp",
+"BoolAssignmentChecker.cpp",
+"BuiltinFunctionChecker.cpp",
+"CStringChecker.cpp",
+"CStringSyntaxChecker.cpp",
+"CXXSelfAssignmentChecker.cpp",
+"CallAndMessageChecker.cpp",
+"CastSizeChecker.cpp",
+"CastToStructChecker.cpp",
+"CheckObjCDealloc.cpp",
+

[PATCH] D55976: [analyzer] Perform escaping in RetainCountChecker on type mismatch even for inlined functions

2018-12-20 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC349876: [analyzer] Perform escaping in RetainCountChecker on 
type mismatch even for… (authored by george.karpenkov, committed by ).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55976?vs=179220=179227#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D55976

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

Index: test/Analysis/osobject-retain-release.cpp
===
--- test/Analysis/osobject-retain-release.cpp
+++ test/Analysis/osobject-retain-release.cpp
@@ -90,7 +90,10 @@
   static OSObject *safeMetaCast(const OSObject *inst, const OSMetaClass *meta);
 };
 
+typedef unsigned long MYTYPE;
+
 void escape(void *);
+void escape_with_source(MYTYPE p) {}
 bool coin();
 
 bool os_consume_violation_two_args(OS_CONSUME OSObject *obj, bool extra) {
@@ -139,6 +142,13 @@
   escape(obj);
 }
 
+void test_escape_has_source() {
+  OSObject *obj = new OSObject;
+  if (obj)
+escape_with_source((MYTYPE)obj);
+  return;
+}
+
 void test_no_infinite_check_recursion(MyArray *arr) {
   OSObject *input = new OSObject;
   OSObject *o = arr->generateObject(input);
Index: lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
+++ lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
@@ -502,6 +502,25 @@
   return None;
 }
 
+static bool isPointerToObject(QualType QT) {
+  QualType PT = QT->getPointeeType();
+  if (!PT.isNull())
+if (PT->getAsCXXRecordDecl())
+  return true;
+  return false;
+}
+
+/// Whether the tracked value should be escaped on a given call.
+/// OSObjects are escaped when passed to void * / etc.
+static bool shouldEscapeArgumentOnCall(const CallEvent , unsigned ArgIdx,
+   const RefVal *TrackedValue) {
+  if (TrackedValue->getObjKind() != RetEffect::OS)
+return false;
+  if (ArgIdx >= CE.parameters().size())
+return false;
+  return !isPointerToObject(CE.parameters()[ArgIdx]->getType());
+}
+
 // We don't always get the exact modeling of the function with regards to the
 // retain count checker even when the function is inlined. For example, we need
 // to stop tracking the symbols which were marked with StopTrackingHard.
@@ -512,11 +531,16 @@
 
   // Evaluate the effect of the arguments.
   for (unsigned idx = 0, e = CallOrMsg.getNumArgs(); idx != e; ++idx) {
-if (Summ.getArg(idx) == StopTrackingHard) {
-  SVal V = CallOrMsg.getArgSVal(idx);
-  if (SymbolRef Sym = V.getAsLocSymbol()) {
+SVal V = CallOrMsg.getArgSVal(idx);
+
+if (SymbolRef Sym = V.getAsLocSymbol()) {
+  bool ShouldRemoveBinding = Summ.getArg(idx) == StopTrackingHard;
+  if (const RefVal *T = getRefBinding(state, Sym))
+if (shouldEscapeArgumentOnCall(CallOrMsg, idx, T))
+  ShouldRemoveBinding = true;
+
+  if (ShouldRemoveBinding)
 state = removeRefBinding(state, Sym);
-  }
 }
   }
 
@@ -574,25 +598,6 @@
   return State;
 }
 
-static bool isPointerToObject(QualType QT) {
-  QualType PT = QT->getPointeeType();
-  if (!PT.isNull())
-if (PT->getAsCXXRecordDecl())
-  return true;
-  return false;
-}
-
-/// Whether the tracked value should be escaped on a given call.
-/// OSObjects are escaped when passed to void * / etc.
-static bool shouldEscapeArgumentOnCall(const CallEvent , unsigned ArgIdx,
-   const RefVal *TrackedValue) {
-  if (TrackedValue->getObjKind() != RetEffect::OS)
-return false;
-  if (ArgIdx >= CE.parameters().size())
-return false;
-  return !isPointerToObject(CE.parameters()[ArgIdx]->getType());
-}
-
 void RetainCountChecker::checkSummary(const RetainSummary ,
   const CallEvent ,
   CheckerContext ) const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r349875 - [analyzer] Fix a bug in RetainCountDiagnostics while printing a note on mismatched summary in inlined functions

2018-12-20 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Thu Dec 20 18:16:23 2018
New Revision: 349875

URL: http://llvm.org/viewvc/llvm-project?rev=349875=rev
Log:
[analyzer] Fix a bug in RetainCountDiagnostics while printing a note on 
mismatched summary in inlined functions

Previously, we were not printing a note at all if at least one of the 
parameters was not annotated.

rdar://46888422

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

Modified:

cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
cfe/trunk/test/Analysis/osobject-retain-release.cpp

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp?rev=349875=349874=349875=diff
==
--- 
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
 (original)
+++ 
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
 Thu Dec 20 18:16:23 2018
@@ -268,7 +268,7 @@ annotateConsumedSummaryMismatch(const Ex
 const ParmVarDecl *PVD = Parameters[I];
 
 if (!PVD->hasAttr())
-  return nullptr;
+  continue;
 
 if (SymbolRef SR = Call->getArgSVal(I).getAsLocSymbol()) {
   const RefVal *CountBeforeCall = getRefBinding(CN->getState(), SR);
@@ -311,10 +311,9 @@ CFRefReportVisitor::VisitNode(const Expl
   BugReporterContext , BugReport ) {
   const SourceManager  = BRC.getSourceManager();
   CallEventManager  = BRC.getStateManager().getCallEventManager();
-  if (auto CE = N->getLocationAs()) {
+  if (auto CE = N->getLocationAs())
 if (auto PD = annotateConsumedSummaryMismatch(N, *CE, SM, CEMgr))
   return PD;
-  }
 
   // FIXME: We will eventually need to handle non-statement-based events
   // (__attribute__((cleanup))).

Modified: cfe/trunk/test/Analysis/osobject-retain-release.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/osobject-retain-release.cpp?rev=349875=349874=349875=diff
==
--- cfe/trunk/test/Analysis/osobject-retain-release.cpp (original)
+++ cfe/trunk/test/Analysis/osobject-retain-release.cpp Thu Dec 20 18:16:23 2018
@@ -93,6 +93,15 @@ struct OSMetaClassBase {
 void escape(void *);
 bool coin();
 
+bool os_consume_violation_two_args(OS_CONSUME OSObject *obj, bool extra) {
+  if (coin()) { // expected-note{{Assuming the condition is false}}
+// expected-note@-1{{Taking false branch}}
+escape(obj);
+return true;
+  }
+  return false; // expected-note{{Parameter 'obj' is marked as consuming, but 
the function does not consume the reference}}
+}
+
 bool os_consume_violation(OS_CONSUME OSObject *obj) {
   if (coin()) { // expected-note{{Assuming the condition is false}}
 // expected-note@-1{{Taking false branch}}
@@ -113,6 +122,13 @@ void use_os_consume_violation() {
 } // expected-note{{Object leaked: object allocated and stored into 'obj' is 
not referenced later in this execution path and has a retain count of +1}}
   // expected-warning@-1{{Potential leak of an object stored into 'obj'}}
 
+void use_os_consume_violation_two_args() {
+  OSObject *obj = new OSObject; // expected-note{{Operator 'new' returns an 
OSObject of type OSObject with a +1 retain count}}
+  os_consume_violation_two_args(obj, coin()); // expected-note{{Calling 
'os_consume_violation_two_args'}}
+ // expected-note@-1{{Returning from 
'os_consume_violation_two_args'}}
+} // expected-note{{Object leaked: object allocated and stored into 'obj' is 
not referenced later in this execution path and has a retain count of +1}}
+  // expected-warning@-1{{Potential leak of an object stored into 'obj'}}
+
 void use_os_consume_ok() {
   OSObject *obj = new OSObject;
   os_consume_ok(obj);


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


[PATCH] D55875: [analyzer] pr38668: RegionStore: Do not attempt to cast loaded values of non-scalar types.

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

Attempt to define the notion of "type of `SVal`".


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

https://reviews.llvm.org/D55875

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
  lib/StaticAnalyzer/Core/SVals.cpp
  lib/StaticAnalyzer/Core/Store.cpp
  test/Analysis/casts.c

Index: test/Analysis/casts.c
===
--- test/Analysis/casts.c
+++ test/Analysis/casts.c
@@ -213,3 +213,19 @@
 }
 
 #endif
+
+char no_crash_SymbolCast_of_float_type_aux(int *p) {
+  *p += 1;
+  return *p;
+}
+
+void no_crash_SymbolCast_of_float_type() {
+  extern float x;
+  char (*f)() = no_crash_SymbolCast_of_float_type_aux;
+  f();
+}
+
+double no_crash_reinterpret_double_as_int(double a) {
+  *(int *) = 1;
+  return a * a;
+}
Index: lib/StaticAnalyzer/Core/Store.cpp
===
--- lib/StaticAnalyzer/Core/Store.cpp
+++ lib/StaticAnalyzer/Core/Store.cpp
@@ -394,14 +394,29 @@
   return UnknownVal();
 }
 
+static bool isScalarEnoughToAttemptACast(QualType T) {
+  return T->isIntegralOrEnumerationType() || Loc::isLocType(T);
+}
+
 /// CastRetrievedVal - Used by subclasses of StoreManager to implement
 ///  implicit casts that arise from loads from regions that are reinterpreted
 ///  as another region.
 SVal StoreManager::CastRetrievedVal(SVal V, const TypedValueRegion *R,
-QualType castTy) {
-  if (castTy.isNull() || V.isUnknownOrUndef())
+QualType CastTy) {
+  if (CastTy.isNull() || V.isUnknownOrUndef())
+return V;
+
+  QualType OrigTy = V.detectType(StateMgr.getContext());
+  if (OrigTy.isNull())
 return V;
 
+  if (!isScalarEnoughToAttemptACast(OrigTy) ||
+  !isScalarEnoughToAttemptACast(CastTy)) {
+if (OrigTy.getUnqualifiedType() == CastTy.getUnqualifiedType())
+  return V;
+return UnknownVal();
+  }
+
   // When retrieving symbolic pointer and expecting a non-void pointer,
   // wrap them into element regions of the expected type if necessary.
   // SValBuilder::dispatchCast() doesn't do that, but it is necessary to
@@ -410,13 +425,13 @@
   // We might need to do that for non-void pointers as well.
   // FIXME: We really need a single good function to perform casts for us
   // correctly every time we need it.
-  if (castTy->isPointerType() && !castTy->isVoidPointerType())
+  if (CastTy->isPointerType() && !CastTy->isVoidPointerType())
 if (const auto *SR = dyn_cast_or_null(V.getAsRegion()))
   if (SR->getSymbol()->getType().getCanonicalType() !=
-  castTy.getCanonicalType())
-return loc::MemRegionVal(castRegion(SR, castTy));
+  CastTy.getCanonicalType())
+return loc::MemRegionVal(castRegion(SR, CastTy));
 
-  return svalBuilder.dispatchCast(V, castTy);
+  return svalBuilder.dispatchCast(V, CastTy);
 }
 
 SVal StoreManager::getLValueFieldOrIvar(const Decl *D, SVal Base) {
Index: lib/StaticAnalyzer/Core/SVals.cpp
===
--- lib/StaticAnalyzer/Core/SVals.cpp
+++ lib/StaticAnalyzer/Core/SVals.cpp
@@ -21,6 +21,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SValVisitor.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
 #include "llvm/ADT/Optional.h"
@@ -185,6 +186,59 @@
   return DD;
 }
 
+namespace {
+class TypeDetector : public SValVisitor {
+  ASTContext 
+
+public:
+  TypeDetector(ASTContext ): ACtx(ACtx) {}
+
+  QualType VisitSVal(SVal V) { return QualType(); }
+
+  QualType VisitNonLocSymbolVal(nonloc::SymbolVal V) {
+return V.getSymbol()->getType();
+  }
+
+  QualType VisitLocMemRegionVal(loc::MemRegionVal V) {
+if (const auto *TR = dyn_cast(V.getRegion()))
+  return TR->getLocationType();
+else
+  return ACtx.VoidPtrTy;
+  }
+
+  QualType VisitNonLocConcreteInt(nonloc::ConcreteInt V) {
+const llvm::APSInt  = V.getValue();
+return ACtx.getIntTypeForBitwidth(I.getBitWidth(), I.isSigned());
+  }
+
+  QualType VisitLocConcreteInt(loc::ConcreteInt V) {
+return ACtx.VoidPtrTy;
+  }
+
+  QualType VisitNonLocLocAsInteger(nonloc::LocAsInteger V) {
+// FIXME: This returns an unsigned type because LocAsInteger
+// does not remember what is the correct type.
+return ACtx.getIntTypeForBitwidth(V.getNumBits(), false);
+  }
+
+  QualType VisitNonLocCompoundVal(nonloc::CompoundVal V) {
+return V.getValue()->getType();
+  }
+
+  QualType VisitNonLocLazyCompoundVal(nonloc::LazyCompoundVal V) {
+if (const auto *TVR = 

r349872 - [mingw] Don't mangle thiscall like fastcall etc

2018-12-20 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Thu Dec 20 17:40:29 2018
New Revision: 349872

URL: http://llvm.org/viewvc/llvm-project?rev=349872=rev
Log:
[mingw] Don't mangle thiscall like fastcall etc

GCC does not mangle it when it is not explicit in the source.  The
mangler as currently written cannot differentiate between explicit and
implicit calling conventions, so we can't match GCC. Explicit thiscall
conventions are rare, so mangle as if the convention was implicit to be
as ABI compatible as possible.

Also fixes some tests using %itanium_abi_triple in some configurations
as a side effect.

Fixes PR40107.

Modified:
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp

Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=349872=349871=349872=diff
==
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Thu Dec 20 17:40:29 2018
@@ -2662,12 +2662,18 @@ StringRef CXXNameMangler::getCallingConv
 // FIXME: we should be mangling all of the above.
 return "";
 
+  case CC_X86ThisCall:
+// FIXME: To match mingw GCC, thiscall should only be mangled in when it is
+// used explicitly. At this point, we don't have that much information in
+// the AST, since clang tends to bake the convention into the canonical
+// function type. thiscall only rarely used explicitly, so don't mangle it
+// for now.
+return "";
+
   case CC_X86StdCall:
 return "stdcall";
   case CC_X86FastCall:
 return "fastcall";
-  case CC_X86ThisCall:
-return "thiscall";
   case CC_X86_64SysV:
 return "sysv_abi";
   case CC_Win64:

Modified: cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp?rev=349872=349871=349872=diff
==
--- cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-win-ccs.cpp Thu Dec 20 17:40:29 2018
@@ -17,7 +17,6 @@ void __attribute__((thiscall)) f_thiscal
 int as_cdecl() { return func_as_ptr(f_cdecl); }
 int as_stdcall() { return func_as_ptr(f_stdcall); }
 int as_fastcall() { return func_as_ptr(f_fastcall); }
-int as_thiscall() { return func_as_ptr(f_thiscall); }
 
 // CHECK: define dso_local i32 @_Z8as_cdeclv()
 // CHECK:   call i32 @_ZL11func_as_ptrIPFviiEEiT_(void (i32, i32)* 
@_Z7f_cdeclii)
@@ -28,16 +27,26 @@ int as_thiscall() { return func_as_ptr(f
 // CHECK: define dso_local i32 @_Z11as_fastcallv()
 // CHECK:   call i32 @_ZL11func_as_ptrIPU8fastcallFviiEEiT_(void (i32, i32)* 
@"\01@_Z10f_fastcallii@8")
 
-// CHECK: define dso_local i32 @_Z11as_thiscallv()
-// CHECK:   call i32 @_ZL11func_as_ptrIPU8thiscallFviiEEiT_(void (i32, i32)* 
@_Z10f_thiscallii)
+// PR40107: We should mangle thiscall here but we don't because we can't
+// disambiguate it from the member pointer case below where it shouldn't be
+// mangled.
+//int as_thiscall() { return func_as_ptr(f_thiscall); }
+// CHECKX: define dso_local i32 @_Z11as_thiscallv()
+// CHECKX:   call i32 @_ZL11func_as_ptrIPU8thiscallFviiEEiT_(void (i32, i32)* 
@_Z10f_thiscallii)
 
 // CHECK: define dso_local void @_Z11funcRefTypeRU8fastcallFviiE(void (i32, 
i32)* %fr)
 void funcRefType(void(__attribute__((fastcall)) & fr)(int, int)) {
   fr(1, 2);
 }
 
-// CHECK: define dso_local void 
@_Z12memptrCCTypeR3FooMS_U8fastcallFviiE(%struct.Foo* {{.*}}, { i32, i32 }* 
byval{{.*}})
 struct Foo { void bar(int, int); };
+
+// PR40107: In this case, the member function pointer uses the thiscall
+// convention, but GCC doesn't mangle it, so we don't either.
+// CHECK: define dso_local void @_Z15memptr_thiscallP3FooMS_FvvE(%struct.Foo* 
{{.*}})
+void memptr_thiscall(Foo *o, void (Foo::*mp)()) { (o->*mp)(); }
+
+// CHECK: define dso_local void 
@_Z12memptrCCTypeR3FooMS_U8fastcallFviiE(%struct.Foo* {{.*}}, { i32, i32 }* 
byval{{.*}})
 void memptrCCType(Foo , void (__attribute__((fastcall)) Foo::*mp)(int, int)) 
{
   (o.*mp)(1, 2);
 }


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


[PATCH] D37035: Implement __builtin_LINE() et. al. to support source location capture.

2018-12-20 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 179211.
EricWF added a comment.
Herald added a reviewer: shafik.

Merge with upstream.


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

https://reviews.llvm.org/D37035

Files:
  docs/LanguageExtensions.rst
  include/clang/AST/ASTContext.h
  include/clang/AST/CurrentSourceLocExprScope.h
  include/clang/AST/Expr.h
  include/clang/AST/ExprCXX.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/AST/Stmt.h
  include/clang/Basic/StmtNodes.td
  include/clang/Basic/TokenKinds.def
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTContext.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/Expr.cpp
  lib/AST/ExprCXX.cpp
  lib/AST/ExprClassification.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/StmtPrinter.cpp
  lib/AST/StmtProfile.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGExprComplex.cpp
  lib/CodeGen/CGExprConstant.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Parse/ParseExpr.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExceptionSpec.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/CodeGenCXX/builtin-source-location.cpp
  test/CodeGenCXX/builtin_FUNCTION.cpp
  test/CodeGenCXX/builtin_LINE.cpp
  test/CodeGenCXX/debug-info-line.cpp
  test/Parser/builtin_source_location.c
  test/Sema/source_location.c
  test/SemaCXX/Inputs/source-location-file.h
  test/SemaCXX/source_location.cpp

Index: test/SemaCXX/source_location.cpp
===
--- /dev/null
+++ test/SemaCXX/source_location.cpp
@@ -0,0 +1,590 @@
+// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify %s
+// expected-no-diagnostics
+
+#define assert(...) ((__VA_ARGS__) ? ((void)0) : throw 42)
+#define CURRENT_FROM_MACRO() SL::current()
+#define FORWARD(...) __VA_ARGS__
+
+template 
+struct Printer;
+
+namespace std {
+namespace experimental {
+struct source_location {
+private:
+  unsigned int __m_line = 0;
+  unsigned int __m_col = 0;
+  const char *__m_file = nullptr;
+  const char *__m_func = nullptr;
+public:
+  static constexpr source_location current(
+  const char *__file = __builtin_FILE(),
+  const char *__func = __builtin_FUNCTION(),
+  unsigned int __line = __builtin_LINE(),
+  unsigned int __col = __builtin_COLUMN()) noexcept {
+source_location __loc;
+__loc.__m_line = __line;
+__loc.__m_col = __col;
+__loc.__m_file = __file;
+__loc.__m_func = __func;
+return __loc;
+  }
+  constexpr source_location() = default;
+  constexpr source_location(source_location const &) = default;
+  constexpr unsigned int line() const noexcept { return __m_line; }
+  constexpr unsigned int column() const noexcept { return __m_col; }
+  constexpr const char *file() const noexcept { return __m_file; }
+  constexpr const char *function() const noexcept { return __m_func; }
+};
+} // namespace experimental
+} // namespace std
+
+using SL = std::experimental::source_location;
+
+#include "Inputs/source-location-file.h"
+namespace SLF = source_location_file;
+
+constexpr bool is_equal(const char *LHS, const char *RHS) {
+  while (*LHS != 0 && *RHS != 0) {
+if (*LHS != *RHS)
+  return false;
+++LHS;
+++RHS;
+  }
+  return *LHS == 0 && *RHS == 0;
+}
+
+template 
+constexpr T identity(T t) {
+  return t;
+}
+
+template 
+struct Pair {
+  T first;
+  U second;
+};
+
+template 
+constexpr bool is_same = false;
+template 
+constexpr bool is_same = true;
+
+// test types
+static_assert(is_same);
+static_assert(is_same);
+static_assert(is_same);
+static_assert(is_same);
+
+// test noexcept
+static_assert(noexcept(__builtin_LINE()));
+static_assert(noexcept(__builtin_COLUMN()));
+static_assert(noexcept(__builtin_FILE()));
+static_assert(noexcept(__builtin_FUNCTION()));
+
+//===--===//
+//__builtin_LINE()
+//===--===//
+
+namespace test_line {
+static_assert(SL::current().line() == __LINE__);
+static_assert(SL::current().line() == CURRENT_FROM_MACRO().line());
+
+static constexpr SL GlobalS = SL::current();
+
+static_assert(GlobalS.line() == __LINE__ - 2);
+
+// clang-format off
+constexpr bool test_line_fn() {
+  constexpr SL S = SL::current();
+  static_assert(S.line() == (__LINE__ - 1), "");
+  // The start of the call expression to `current()` begins at the token `SL`
+  constexpr int ExpectLine = __LINE__ + 3;
+  constexpr SL S2
+  =
+  SL // Call expression starts here
+  ::
+  current
+  (
+
+  )
+  ;
+  static_assert(S2.line() == ExpectLine, "");
+
+  static_assert(
+  FORWARD(
+ __builtin_LINE
+(
+)
+  )
+== __LINE__ - 1, "");
+  static_assert(\
+\

r349866 - [driver] [analyzer] Fix --analyze -Xanalyzer after r349863.

2018-12-20 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Thu Dec 20 17:11:21 2018
New Revision: 349866

URL: http://llvm.org/viewvc/llvm-project?rev=349866=rev
Log:
[driver] [analyzer] Fix --analyze -Xanalyzer after r349863.

If an -analyzer-config is passed through -Xanalyzer, it is not found while
looking for -Xclang.

Additionally, don't emit -analyzer-config-compatibility-mode for *every*
-analyzer-config flag we encounter; one is enough.

https://reviews.llvm.org/D55823

rdar://problem/46504165

Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
cfe/trunk/test/Analysis/invalid-analyzer-config-value.c

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=349866=349865=349866=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Thu Dec 20 17:11:21 2018
@@ -3738,9 +3738,20 @@ void Clang::ConstructJob(Compilation ,
   // Enable compatilibily mode to avoid analyzer-config related errors.
   // Since we can't access frontend flags through hasArg, let's manually 
iterate
   // through them.
+  bool FoundAnalyzerConfig = false;
   for (auto Arg : Args.filtered(options::OPT_Xclang))
-if (StringRef(Arg->getValue()) == "-analyzer-config")
-  CmdArgs.push_back("-analyzer-config-compatibility-mode=true");
+if (StringRef(Arg->getValue()) == "-analyzer-config") {
+  FoundAnalyzerConfig = true;
+  break;
+}
+  if (!FoundAnalyzerConfig)
+for (auto Arg : Args.filtered(options::OPT_Xanalyzer))
+  if (StringRef(Arg->getValue()) == "-analyzer-config") {
+FoundAnalyzerConfig = true;
+break;
+  }
+  if (FoundAnalyzerConfig)
+CmdArgs.push_back("-analyzer-config-compatibility-mode=true");
 
   CheckCodeGenerationOptions(D, Args);
 

Modified: cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c?rev=349866=349865=349866=diff
==
--- cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c (original)
+++ cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c Thu Dec 20 
17:11:21 2018
@@ -74,6 +74,10 @@
 // even if -analyze isn't specified.
 // RUN: %clang -fsyntax-only -Xclang -analyzer-config\
 // RUN:  -Xclang remember=TheVasa %s
+// RUN: %clang -fsyntax-only -Xanalyzer -analyzer-config\
+// RUN:  -Xanalyzer remember=TheVasa %s
+// RUN: %clang --analyze -Xanalyzer -analyzer-config\
+// RUN:  -Xanalyzer remember=TheVasa %s
 
 // expected-no-diagnostics
 

Modified: cfe/trunk/test/Analysis/invalid-analyzer-config-value.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/invalid-analyzer-config-value.c?rev=349866=349865=349866=diff
==
--- cfe/trunk/test/Analysis/invalid-analyzer-config-value.c (original)
+++ cfe/trunk/test/Analysis/invalid-analyzer-config-value.c Thu Dec 20 17:11:21 
2018
@@ -70,6 +70,10 @@
 // even if -analyze isn't specified.
 // RUN: %clang -fsyntax-only -Xclang -analyzer-config\
 // RUN:  -Xclang remember=TheVasa %s
+// RUN: %clang -fsyntax-only -Xanalyzer -analyzer-config\
+// RUN:  -Xanalyzer remember=TheVasa %s
+// RUN: %clang --analyze -Xanalyzer -analyzer-config\
+// RUN:  -Xanalyzer remember=TheVasa %s
 
 // expected-no-diagnostics
 


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


[PATCH] D47757: [Sema] Produce diagnostics when unavailable aligned allocation/deallocation functions are called

2018-12-20 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai accepted this revision.
vsapsai added a comment.

The change itself looks correct. Cannot really tell if you need to make changes 
in other places. For that I rely on Richard's opinion.


Repository:
  rC Clang

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

https://reviews.llvm.org/D47757



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


[PATCH] D55775: [Driver] Don't override '-march' when using '-arch x86_64h'

2018-12-20 Thread Quentin Colombet via Phabricator via cfe-commits
qcolombet added a comment.

Should we emit an error if we request x86_64h with an arch older than haswell?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D55775



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


[PATCH] D55823: [analyzer] Fix backward compatibility issue after D53280 'Emit an error for invalid -analyzer-config inputs'

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

George committed this as rC349863 . Before 
that happened, we kinda figured out how it works: `-analyzer-config` is not a 
flag, it's an argument of the `-Xclang` flag, so we should look for `-Xclang` 
and see what value does the argument have.

Now, there's also `-Xanalyzer`. But `-Xanalyzer` is automatically not consumed 
during compilation, so any `-analyzer-config` flags passed through it would be 
ignored during compilation.

However, `--analyze -Xanalyzer -analyzer-config ...` is now broken :/


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

https://reviews.llvm.org/D55823



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


r349863 - Revert "Revert "[driver] [analyzer] Fix a backward compatibility issue after r348038.""

2018-12-20 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Thu Dec 20 16:26:19 2018
New Revision: 349863

URL: http://llvm.org/viewvc/llvm-project?rev=349863=rev
Log:
Revert "Revert "[driver] [analyzer] Fix a backward compatibility issue after 
r348038.""

This reverts commit 144927939587b790c0536f4ff08245043fc8d733.

Fixes the bug in the original commit.

Added:
cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Analysis/invalid-analyzer-config-value.c

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=349863=349862=349863=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Thu Dec 20 16:26:19 2018
@@ -2360,9 +2360,6 @@ static void RenderAnalyzerOptions(const
   // Treat blocks as analysis entry points.
   CmdArgs.push_back("-analyzer-opt-analyze-nested-blocks");
 
-  // Enable compatilibily mode to avoid analyzer-config related errors.
-  CmdArgs.push_back("-analyzer-config-compatibility-mode=true");
-
   // Add default argument set.
   if (!Args.hasArg(options::OPT__analyzer_no_default_checks)) {
 CmdArgs.push_back("-analyzer-checker=core");
@@ -3738,6 +3735,13 @@ void Clang::ConstructJob(Compilation ,
   if (isa(JA))
 RenderAnalyzerOptions(Args, CmdArgs, Triple, Input);
 
+  // Enable compatilibily mode to avoid analyzer-config related errors.
+  // Since we can't access frontend flags through hasArg, let's manually 
iterate
+  // through them.
+  for (auto Arg : Args.filtered(options::OPT_Xclang))
+if (StringRef(Arg->getValue()) == "-analyzer-config")
+  CmdArgs.push_back("-analyzer-config-compatibility-mode=true");
+
   CheckCodeGenerationOptions(D, Args);
 
   unsigned FunctionAlignment = ParseFunctionAlignment(TC, Args);

Added: cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c?rev=349863=auto
==
--- cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c (added)
+++ cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c Thu Dec 20 
16:26:19 2018
@@ -0,0 +1,80 @@
+// Same as invalid-analyzer-config-value.c but without -analyzer-config
+// in the file name, so that argument string pattern matching
+// didn't accidentally match it.
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config notes-as-events=yesplease \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-BOOL-INPUT
+
+// CHECK-BOOL-INPUT: (frontend): invalid input for analyzer-config option
+// CHECK-BOOL-INPUT-SAME:'notes-as-events', that expects a boolean 
value
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config notes-as-events=yesplease
+
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config max-inlinable-size=400km/h \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-UINT-INPUT
+
+// CHECK-UINT-INPUT: (frontend): invalid input for analyzer-config option
+// CHECK-UINT-INPUT-SAME:'max-inlinable-size', that expects an unsigned
+// CHECK-UINT-INPUT-SAME:value
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config max-inlinable-size=400km/h
+
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config ctu-dir=0123012301230123 \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-FILENAME-INPUT
+
+// CHECK-FILENAME-INPUT: (frontend): invalid input for analyzer-config option
+// CHECK-FILENAME-INPUT-SAME:'ctu-dir', that expects a filename
+// CHECK-FILENAME-INPUT-SAME:value
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config ctu-dir=0123012301230123
+
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config no-false-positives=true \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-UNKNOWN-CFG
+
+// CHECK-UNKNOWN-CFG: (frontend): unknown analyzer-config 'no-false-positives'
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config no-false-positives=true
+
+
+// Test the driver properly using "analyzer-config-compatibility-mode=true",
+// no longer causing an error on input error.
+// RUN: %clang --analyze %s
+
+// RUN: not %clang --analyze %s \
+// RUN:   -Xclang 

[PATCH] D55907: [analyzer] RetainCount: Bluntly suppress the CFRetain detection heuristic on a couple of CM functions.

2018-12-20 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC349862: [analyzer] RetainCount: Suppress retain detection 
heuristic on some CM methods. (authored by dergachev, committed by ).

Repository:
  rC Clang

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

https://reviews.llvm.org/D55907

Files:
  lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
  test/Analysis/retain-release.m


Index: test/Analysis/retain-release.m
===
--- test/Analysis/retain-release.m
+++ test/Analysis/retain-release.m
@@ -1,9 +1,20 @@
 // RUN: rm -f %t.objc.plist %t.objcpp.plist
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 
-analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease,osx.cocoa.RetainCount
 -analyzer-store=region -fblocks -verify -Wno-objc-root-class %s 
-analyzer-output=plist -o %t.objc.plist
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 
-analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease,osx.cocoa.RetainCount
 -analyzer-store=region -fblocks -verify -x objective-c++ -std=gnu++98 
-Wno-objc-root-class %s -analyzer-output=plist -o %t.objcpp.plist
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10\
+// RUN: -analyzer-checker=core,osx.coreFoundation.CFRetainRelease\
+// RUN: -analyzer-checker=osx.cocoa.ClassRelease,osx.cocoa.RetainCount\
+// RUN: -analyzer-checker=debug.ExprInspection -fblocks -verify %s\
+// RUN: -Wno-objc-root-class -analyzer-output=plist -o %t.objcpp.plist
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10\
+// RUN: -analyzer-checker=core,osx.coreFoundation.CFRetainRelease\
+// RUN: -analyzer-checker=osx.cocoa.ClassRelease,osx.cocoa.RetainCount\
+// RUN: -analyzer-checker=debug.ExprInspection -fblocks -verify %s\
+// RUN: -Wno-objc-root-class -analyzer-output=plist -o %t.objcpp.plist\
+// RUN: -x objective-c++ -std=gnu++98
 // FIXLATER: cat %t.objc.plist ; FileCheck --input-file=%t.objc.plist %s
 // FIXLATER: cat %t.objcpp.plist ; FileCheck --input-file=%t.objcpp.plist %s
 
+void clang_analyzer_eval(int);
+
 #if __has_feature(attribute_ns_returns_retained)
 #define NS_RETURNS_RETAINED __attribute__((ns_returns_retained))
 #endif
@@ -495,6 +506,21 @@
   // status is returned.
 }
 
+typedef CFTypeRef CMBufferRef;
+
+typedef CFTypeRef *CMBufferQueueRef;
+
+CMBufferRef CMBufferQueueDequeueAndRetain(CMBufferQueueRef);
+
+void testCMBufferQueueDequeueAndRetain(CMBufferQueueRef queue) {
+  CMBufferRef buffer = CMBufferQueueDequeueAndRetain(queue); // 
expected-warning{{Potential leak of an object stored into 'buffer'}}
+  // There's a state split due to the eagerly-assume behavior.
+  // The point here is that we don't treat CMBufferQueueDequeueAndRetain
+  // as some sort of CFRetain() that returns its argument.
+  clang_analyzer_eval((CMFooRef)buffer == (CMFooRef)queue); // 
expected-warning{{TRUE}}
+// 
expected-warning@-1{{FALSE}}
+}
+
 // Test retain/release checker with CFString and CFMutableArray.
 void f11() {
   // Create the array.
Index: lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
===
--- lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
+++ lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
@@ -204,6 +204,11 @@
 AllowAnnotations = false;
 return RetTy->isObjCIdType() ? getUnarySummary(FT, cfmakecollectable)
  : getPersistentStopSummary();
+  } else if (FName == "CMBufferQueueDequeueAndRetain" ||
+ FName == "CMBufferQueueDequeueIfDataReadyAndRetain") {
+// Part of: .
+return getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF), DoNothing,
+DoNothing);
   } else if (FName == "CFPlugInInstanceCreate") {
 return getPersistentSummary(RetEffect::MakeNoRet());
   } else if (FName == "IORegistryEntrySearchCFProperty" ||
@@ -591,6 +596,12 @@
 // Handle: (CF|CG|CV)Retain
 // CFAutorelease
 // It's okay to be a little sloppy here.
+if (FName == "CMBufferQueueDequeueAndRetain" ||
+FName == "CMBufferQueueDequeueIfDataReadyAndRetain") {
+  // Part of: .
+  // These are not retain. They just return something and retain it.
+  return None;
+}
 if (cocoa::isRefType(ResultTy, "CF", FName) ||
 cocoa::isRefType(ResultTy, "CG", FName) ||
 cocoa::isRefType(ResultTy, "CV", FName))


Index: test/Analysis/retain-release.m
===
--- test/Analysis/retain-release.m
+++ test/Analysis/retain-release.m
@@ -1,9 +1,20 @@
 // RUN: rm -f %t.objc.plist %t.objcpp.plist
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease,osx.cocoa.RetainCount 

r349862 - [analyzer] RetainCount: Suppress retain detection heuristic on some CM methods.

2018-12-20 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Thu Dec 20 16:18:58 2018
New Revision: 349862

URL: http://llvm.org/viewvc/llvm-project?rev=349862=rev
Log:
[analyzer] RetainCount: Suppress retain detection heuristic on some CM methods.

If it ends with "Retain" like CFRetain and returns a CFTypeRef like CFRetain,
then it is not necessarily a CFRetain. But it is indeed true that these two
return something retained.

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

rdar://problem/39390714

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
cfe/trunk/test/Analysis/retain-release.m

Modified: cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp?rev=349862=349861=349862=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp Thu Dec 20 
16:18:58 2018
@@ -204,6 +204,11 @@ const RetainSummary *RetainSummaryManage
 AllowAnnotations = false;
 return RetTy->isObjCIdType() ? getUnarySummary(FT, cfmakecollectable)
  : getPersistentStopSummary();
+  } else if (FName == "CMBufferQueueDequeueAndRetain" ||
+ FName == "CMBufferQueueDequeueIfDataReadyAndRetain") {
+// Part of: .
+return getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF), DoNothing,
+DoNothing);
   } else if (FName == "CFPlugInInstanceCreate") {
 return getPersistentSummary(RetEffect::MakeNoRet());
   } else if (FName == "IORegistryEntrySearchCFProperty" ||
@@ -591,6 +596,12 @@ RetainSummaryManager::canEval(const Call
 // Handle: (CF|CG|CV)Retain
 // CFAutorelease
 // It's okay to be a little sloppy here.
+if (FName == "CMBufferQueueDequeueAndRetain" ||
+FName == "CMBufferQueueDequeueIfDataReadyAndRetain") {
+  // Part of: .
+  // These are not retain. They just return something and retain it.
+  return None;
+}
 if (cocoa::isRefType(ResultTy, "CF", FName) ||
 cocoa::isRefType(ResultTy, "CG", FName) ||
 cocoa::isRefType(ResultTy, "CV", FName))

Modified: cfe/trunk/test/Analysis/retain-release.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.m?rev=349862=349861=349862=diff
==
--- cfe/trunk/test/Analysis/retain-release.m (original)
+++ cfe/trunk/test/Analysis/retain-release.m Thu Dec 20 16:18:58 2018
@@ -1,9 +1,20 @@
 // RUN: rm -f %t.objc.plist %t.objcpp.plist
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 
-analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease,osx.cocoa.RetainCount
 -analyzer-store=region -fblocks -verify -Wno-objc-root-class %s 
-analyzer-output=plist -o %t.objc.plist
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 
-analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease,osx.cocoa.RetainCount
 -analyzer-store=region -fblocks -verify -x objective-c++ -std=gnu++98 
-Wno-objc-root-class %s -analyzer-output=plist -o %t.objcpp.plist
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10\
+// RUN: -analyzer-checker=core,osx.coreFoundation.CFRetainRelease\
+// RUN: -analyzer-checker=osx.cocoa.ClassRelease,osx.cocoa.RetainCount\
+// RUN: -analyzer-checker=debug.ExprInspection -fblocks -verify %s\
+// RUN: -Wno-objc-root-class -analyzer-output=plist -o %t.objcpp.plist
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10\
+// RUN: -analyzer-checker=core,osx.coreFoundation.CFRetainRelease\
+// RUN: -analyzer-checker=osx.cocoa.ClassRelease,osx.cocoa.RetainCount\
+// RUN: -analyzer-checker=debug.ExprInspection -fblocks -verify %s\
+// RUN: -Wno-objc-root-class -analyzer-output=plist -o %t.objcpp.plist\
+// RUN: -x objective-c++ -std=gnu++98
 // FIXLATER: cat %t.objc.plist ; FileCheck --input-file=%t.objc.plist %s
 // FIXLATER: cat %t.objcpp.plist ; FileCheck --input-file=%t.objcpp.plist %s
 
+void clang_analyzer_eval(int);
+
 #if __has_feature(attribute_ns_returns_retained)
 #define NS_RETURNS_RETAINED __attribute__((ns_returns_retained))
 #endif
@@ -495,6 +506,21 @@ void testLeakWithReturnsRetainedOutParam
   // status is returned.
 }
 
+typedef CFTypeRef CMBufferRef;
+
+typedef CFTypeRef *CMBufferQueueRef;
+
+CMBufferRef CMBufferQueueDequeueAndRetain(CMBufferQueueRef);
+
+void testCMBufferQueueDequeueAndRetain(CMBufferQueueRef queue) {
+  CMBufferRef buffer = CMBufferQueueDequeueAndRetain(queue); // 
expected-warning{{Potential leak of an object stored into 'buffer'}}
+  // There's a state split due to the eagerly-assume behavior.
+  // The point here is that we don't treat CMBufferQueueDequeueAndRetain
+  // as some sort of CFRetain() that returns its argument.
+  

[PATCH] D55865: [ObjC] Add a new attribute to opt-out of implicit callee retain/release in ARC

2018-12-20 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington updated this revision to Diff 179196.
erik.pilkington marked 5 inline comments as done.
erik.pilkington added a comment.

Add some more Sema tests as per Aaron's comments.


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

https://reviews.llvm.org/D55865

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/CodeGenObjC/externally-retained.m
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaObjC/externally-retained-no-arc.m
  clang/test/SemaObjC/externally-retained.m

Index: clang/test/SemaObjC/externally-retained.m
===
--- /dev/null
+++ clang/test/SemaObjC/externally-retained.m
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fobjc-runtime=macosx-10.13.0 -fblocks -fobjc-arc %s -verify
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fobjc-runtime=macosx-10.13.0 -fblocks -fobjc-arc -xobjective-c++ %s -verify
+
+#define EXT_RET __attribute__((objc_externally_retained))
+
+@interface ObjCTy
+@end
+
+void test1() {
+  EXT_RET int a; // expected-warning{{'objc_externally_retained' can only be applied to}}
+  EXT_RET __weak ObjCTy *b; // expected-warning{{'objc_externally_retained' can only be applied to}}
+  EXT_RET __weak int (^c)(); // expected-warning{{'objc_externally_retained' can only be applied to}}
+
+  EXT_RET int (^d)() = ^{return 0;};
+  EXT_RET ObjCTy *e = 0;
+  EXT_RET __strong ObjCTy *f = 0;
+
+  e = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
+  f = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
+  d = ^{ return 0; }; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
+}
+
+void test2(ObjCTy *a);
+
+void test2(EXT_RET ObjCTy *a) {
+  a = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
+}
+
+EXT_RET ObjCTy *test3; // expected-warning{{'objc_externally_retained' can only be applied to}}
+
+@interface X // expected-warning{{defined without specifying a base class}} expected-note{{add a super class}}
+-(void)m: (ObjCTy *) p;
+@end
+@implementation X
+-(void)m: (ObjCTy *) EXT_RET p {
+  p = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
+}
+@end
+
+void test4() {
+  __attribute__((objc_externally_retained(0))) ObjCTy *a; // expected-error{{'objc_externally_retained' attribute takes no arguments}}
+}
Index: clang/test/SemaObjC/externally-retained-no-arc.m
===
--- /dev/null
+++ clang/test/SemaObjC/externally-retained-no-arc.m
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 %s -verify
+
+@interface NSWidget @end
+
+void f() {
+  __attribute__((objc_externally_retained)) NSWidget *w; // expected-warning{{'objc_externally_retained' attribute ignored}}
+}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -94,6 +94,7 @@
 // CHECK-NEXT: ObjCBridgeRelated (SubjectMatchRule_record)
 // CHECK-NEXT: ObjCException (SubjectMatchRule_objc_interface)
 // CHECK-NEXT: ObjCExplicitProtocolImpl (SubjectMatchRule_objc_protocol)
+// CHECK-NEXT: ObjCExternallyRetained (SubjectMatchRule_variable)
 // CHECK-NEXT: ObjCMethodFamily (SubjectMatchRule_objc_method)
 // CHECK-NEXT: ObjCPreciseLifetime (SubjectMatchRule_variable)
 // CHECK-NEXT: ObjCRequiresPropertyDefs (SubjectMatchRule_objc_interface)
Index: clang/test/CodeGenObjC/externally-retained.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/externally-retained.m
@@ -0,0 +1,121 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fobjc-arc -fblocks -Wno-objc-root-class -O0 %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fobjc-arc -fblocks -Wno-objc-root-class -O0 -xobjective-c++ -std=c++11 %s -S -emit-llvm -o - | FileCheck %s --check-prefix CHECKXX --dump-input-on-failure
+
+#define EXT_RET __attribute__((objc_externally_retained))
+
+@interface ObjTy @end
+
+ObjTy *global;
+
+#if __cplusplus
+// Suppress name mangling in C++ mode for the sake of check lines.
+extern "C" void param(ObjTy *p);
+extern "C" void local();
+extern "C" void in_init();
+extern "C" void anchor();
+extern "C" void block_capture(ObjTy *);
+extern "C" void esc(void 

[PATCH] D55865: [ObjC] Add a new attribute to opt-out of implicit callee retain/release in ARC

2018-12-20 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added inline comments.



Comment at: clang/test/SemaObjC/externally-retained.m:14
+
+  EXT_RET int (^d)() = ^{return 0;};
+  EXT_RET ObjCTy *e = 0;

aaron.ballman wrote:
> Should this be useful for function pointer parameters as well? e.g.,
> ```
> typedef void (*fp)(EXT_RET __strong ObjCTy *);
> 
> void f(__strong ObjCTy *);
> 
> void g(EXT_RET ObjCTy *Ptr) {
>   fp Fn = f; // Good idea? Bad idea?
>   Fn(Ptr); // Which behavior "wins" in this call?
> }
> ```
The attribute doesn't have any effect on the caller side, so when used with a 
function pointer type the attribute doesn't really do anything (the function 
definition always "wins").


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

https://reviews.llvm.org/D55865



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


[PATCH] D47757: [Sema] Produce diagnostics when unavailable aligned allocation/deallocation functions are called

2018-12-20 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 179195.
ahatanak marked 2 inline comments as done.
ahatanak added a comment.

Check whether the declaration passed to Sema::CanUseDecl is an aligned 
allocation/deallocation function that is unavailable.


Repository:
  rC Clang

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

https://reviews.llvm.org/D47757

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaExprCXX.cpp
  test/CXX/drs/dr2xx.cpp
  test/SemaCXX/unavailable_aligned_allocation.cpp

Index: test/SemaCXX/unavailable_aligned_allocation.cpp
===
--- test/SemaCXX/unavailable_aligned_allocation.cpp
+++ test/SemaCXX/unavailable_aligned_allocation.cpp
@@ -124,7 +124,73 @@
 // expected-note@-20 2 {{if you supply your own aligned allocation functions}}
 #endif
 
-// No errors if user-defined aligned allocation functions are available.
+// Test that diagnostics are produced when an unavailable aligned deallocation
+// function is called from a deleting destructor.
+struct alignas(256) OveralignedS2 {
+  int a[4];
+  virtual ~OveralignedS2();
+};
+
+OveralignedS2::~OveralignedS2() {}
+
+#ifdef NO_ERRORS
+// expected-no-diagnostics
+#else
+#if defined(IOS)
+// expected-error@-6 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on iOS 11 or newer}}}
+// expected-note@-7 {{if you supply your own aligned allocation functions}}
+#elif defined(TVOS)
+// expected-error@-9 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on tvOS 11 or newer}}}
+// expected-note@-10 {{if you supply your own aligned allocation functions}}
+#elif defined(WATCHOS)
+// expected-error@-12 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on watchOS 4 or newer}}}
+// expected-note@-13 {{if you supply your own aligned allocation functions}}
+#else
+// expected-error@-15 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on macOS 10.13 or newer}}}
+// expected-note@-16 {{if you supply your own aligned allocation functions}}
+#endif
+#endif
+
+void testExplicitOperatorNewDelete() {
+  void *p = operator new(128);
+  operator delete(p);
+  p = operator new[](128);
+  operator delete[](p);
+  p = __builtin_operator_new(128);
+  __builtin_operator_delete(p);
+}
+
+void testExplicitOperatorNewDeleteOveraligned() {
+  void *p = operator new(128, (std::align_val_t)64);
+  operator delete(p, (std::align_val_t)64);
+  p = operator new[](128, (std::align_val_t)64);
+  operator delete[](p, (std::align_val_t)64);
+  p = __builtin_operator_new(128, (std::align_val_t)64);
+  __builtin_operator_delete(p, (std::align_val_t)64);
+}
+
+#ifdef NO_ERRORS
+// expected-no-diagnostics
+#else
+// expected-error@-11 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on}}
+// expected-note@-12 {{if you supply your own aligned allocation functions}}
+
+// expected-error@-13 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
+// expected-note@-14 {{if you supply your own aligned allocation functions}}
+
+// expected-error@-15 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on}}
+// expected-note@-16 {{if you supply your own aligned allocation functions}}
+
+// expected-error@-17 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
+// expected-note@-18 {{if you supply your own aligned allocation functions}}
+
+// expected-error@-19 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on}}
+// expected-note@-20 {{if you supply your own aligned allocation functions}}
+
+// expected-error@-21 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
+// expected-note@-22 {{if you supply your own aligned allocation functions}}
+#endif
+
 void *operator new(std::size_t __sz, std::align_val_t) {
   static char array[256];
   return 
Index: test/CXX/drs/dr2xx.cpp
===
--- test/CXX/drs/dr2xx.cpp
+++ test/CXX/drs/dr2xx.cpp
@@ -718,7 +718,7 @@
 A() {}
   };
 
-  // FIXME: These are ill-formed, with a required diagnostic, for the same
+  // FIXME: This is ill-formed, with a required diagnostic, for the same
   // reason.
   struct B {
 inline void operator delete(void*) __attribute__((unused));
@@ -726,7 +726,7 @@
   };
   struct C {
 inline void operator delete(void*) __attribute__((unused));
-virtual ~C() {}
+virtual ~C() {} // expected-warning {{'operator delete' was marked unused but was used}}
   };
 
   struct D {
Index: 

[PATCH] D55823: [analyzer] Fix backward compatibility issue after D53280 'Emit an error for invalid -analyzer-config inputs'

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

Remove debug prints >.<


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

https://reviews.llvm.org/D55823

Files:
  lib/Driver/ToolChains/Clang.cpp
  test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
  test/Analysis/invalid-analyzer-config-value.c

Index: test/Analysis/invalid-analyzer-config-value.c
===
--- test/Analysis/invalid-analyzer-config-value.c
+++ test/Analysis/invalid-analyzer-config-value.c
@@ -66,6 +66,11 @@
 
 // CHECK-NO-COMPAT: error: unknown analyzer-config 'no-false-positives'
 
+// Test the driver properly using "analyzer-config-compatibility-mode=true",
+// even if -analyze isn't specified.
+// RUN: %clang -fsyntax-only -Xclang -analyzer-config\
+// RUN:  -Xclang remember=TheVasa %s
+
 // expected-no-diagnostics
 
 int main() {}
Index: test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
===
--- /dev/null
+++ test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
@@ -0,0 +1,80 @@
+// Same as invalid-analyzer-config-value.c but without -analyzer-config
+// in the file name, so that argument string pattern matching
+// didn't accidentally match it.
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config notes-as-events=yesplease \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-BOOL-INPUT
+
+// CHECK-BOOL-INPUT: (frontend): invalid input for analyzer-config option
+// CHECK-BOOL-INPUT-SAME:'notes-as-events', that expects a boolean value
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config notes-as-events=yesplease
+
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config max-inlinable-size=400km/h \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-UINT-INPUT
+
+// CHECK-UINT-INPUT: (frontend): invalid input for analyzer-config option
+// CHECK-UINT-INPUT-SAME:'max-inlinable-size', that expects an unsigned
+// CHECK-UINT-INPUT-SAME:value
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config max-inlinable-size=400km/h
+
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config ctu-dir=0123012301230123 \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-FILENAME-INPUT
+
+// CHECK-FILENAME-INPUT: (frontend): invalid input for analyzer-config option
+// CHECK-FILENAME-INPUT-SAME:'ctu-dir', that expects a filename
+// CHECK-FILENAME-INPUT-SAME:value
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config ctu-dir=0123012301230123
+
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config no-false-positives=true \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-UNKNOWN-CFG
+
+// CHECK-UNKNOWN-CFG: (frontend): unknown analyzer-config 'no-false-positives'
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config no-false-positives=true
+
+
+// Test the driver properly using "analyzer-config-compatibility-mode=true",
+// no longer causing an error on input error.
+// RUN: %clang --analyze %s
+
+// RUN: not %clang --analyze %s \
+// RUN:   -Xclang -analyzer-config -Xclang no-false-positives=true \
+// RUN:   -Xclang -analyzer-config-compatibility-mode=false \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-NO-COMPAT
+
+// CHECK-NO-COMPAT: error: unknown analyzer-config 'no-false-positives'
+
+// Test the driver properly using "analyzer-config-compatibility-mode=true",
+// even if -analyze isn't specified.
+// RUN: %clang -fsyntax-only -Xclang -analyzer-config\
+// RUN:  -Xclang remember=TheVasa %s
+
+// expected-no-diagnostics
+
+int main() {}
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -2360,9 +2360,6 @@
   // Treat blocks as analysis entry points.
   CmdArgs.push_back("-analyzer-opt-analyze-nested-blocks");
 
-  // Enable compatilibily mode to avoid analyzer-config related errors.
-  CmdArgs.push_back("-analyzer-config-compatibility-mode=true");
-
   // Add default argument set.
   if (!Args.hasArg(options::OPT__analyzer_no_default_checks)) {
 CmdArgs.push_back("-analyzer-checker=core");
@@ -3694,6 +3691,18 @@
   if (isa(JA))
 RenderAnalyzerOptions(Args, CmdArgs, Triple, Input);
 
+  // Enable compatilibily mode to avoid analyzer-config 

[PATCH] D55823: [analyzer] Fix backward compatibility issue after D53280 'Emit an error for invalid -analyzer-config inputs'

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

Though yeah, thanks, we might be crashing for that reason as well in the future!


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

https://reviews.llvm.org/D55823

Files:
  lib/Driver/ToolChains/Clang.cpp
  test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
  test/Analysis/invalid-analyzer-config-value.c

Index: test/Analysis/invalid-analyzer-config-value.c
===
--- test/Analysis/invalid-analyzer-config-value.c
+++ test/Analysis/invalid-analyzer-config-value.c
@@ -66,6 +66,11 @@
 
 // CHECK-NO-COMPAT: error: unknown analyzer-config 'no-false-positives'
 
+// Test the driver properly using "analyzer-config-compatibility-mode=true",
+// even if -analyze isn't specified.
+// RUN: %clang -fsyntax-only -Xclang -analyzer-config\
+// RUN:  -Xclang remember=TheVasa %s
+
 // expected-no-diagnostics
 
 int main() {}
Index: test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
===
--- /dev/null
+++ test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
@@ -0,0 +1,80 @@
+// Same as invalid-analyzer-config-value.c but without -analyzer-config
+// in the file name, so that argument string pattern matching
+// didn't accidentally match it.
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config notes-as-events=yesplease \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-BOOL-INPUT
+
+// CHECK-BOOL-INPUT: (frontend): invalid input for analyzer-config option
+// CHECK-BOOL-INPUT-SAME:'notes-as-events', that expects a boolean value
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config notes-as-events=yesplease
+
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config max-inlinable-size=400km/h \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-UINT-INPUT
+
+// CHECK-UINT-INPUT: (frontend): invalid input for analyzer-config option
+// CHECK-UINT-INPUT-SAME:'max-inlinable-size', that expects an unsigned
+// CHECK-UINT-INPUT-SAME:value
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config max-inlinable-size=400km/h
+
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config ctu-dir=0123012301230123 \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-FILENAME-INPUT
+
+// CHECK-FILENAME-INPUT: (frontend): invalid input for analyzer-config option
+// CHECK-FILENAME-INPUT-SAME:'ctu-dir', that expects a filename
+// CHECK-FILENAME-INPUT-SAME:value
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config ctu-dir=0123012301230123
+
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config no-false-positives=true \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-UNKNOWN-CFG
+
+// CHECK-UNKNOWN-CFG: (frontend): unknown analyzer-config 'no-false-positives'
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config no-false-positives=true
+
+
+// Test the driver properly using "analyzer-config-compatibility-mode=true",
+// no longer causing an error on input error.
+// RUN: %clang --analyze %s
+
+// RUN: not %clang --analyze %s \
+// RUN:   -Xclang -analyzer-config -Xclang no-false-positives=true \
+// RUN:   -Xclang -analyzer-config-compatibility-mode=false \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-NO-COMPAT
+
+// CHECK-NO-COMPAT: error: unknown analyzer-config 'no-false-positives'
+
+// Test the driver properly using "analyzer-config-compatibility-mode=true",
+// even if -analyze isn't specified.
+// RUN: %clang -fsyntax-only -Xclang -analyzer-config\
+// RUN:  -Xclang remember=TheVasa %s
+
+// expected-no-diagnostics
+
+int main() {}
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -2360,9 +2360,6 @@
   // Treat blocks as analysis entry points.
   CmdArgs.push_back("-analyzer-opt-analyze-nested-blocks");
 
-  // Enable compatilibily mode to avoid analyzer-config related errors.
-  CmdArgs.push_back("-analyzer-config-compatibility-mode=true");
-
   // Add default argument set.
   if (!Args.hasArg(options::OPT__analyzer_no_default_checks)) {
 CmdArgs.push_back("-analyzer-checker=core");
@@ -3694,6 +3691,20 @@
   if (isa(JA))
 RenderAnalyzerOptions(Args, CmdArgs, Triple, Input);
 
+ 

[PATCH] D55823: [analyzer] Fix backward compatibility issue after D53280 'Emit an error for invalid -analyzer-config inputs'

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

In D55823#1338337 , @arphaman wrote:

> I think `Args.getArgString` might return `nullptr` so that's why you could 
> crash.


Nope, we crash on index lookup. It seems that `Args.size()` is larger than the 
small vector that we're allowed to access via `.getArgStrings()`. I tried 
`Args.getNumInputArgStrings()` and it seems better.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D55823



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


[PATCH] D55964: [clang-format][TableGen] Don't add spaces around items in square braces.

2018-12-20 Thread Jordan Rupprecht via Phabricator via cfe-commits
rupprecht created this revision.
rupprecht added reviewers: djasper, krasimir.
Herald added a subscriber: cfe-commits.

clang-formatting wants to add spaces around items in square braces, e.g. [1, 2] 
-> [ 1, 2 ]. Based on a quick check [1], it seems like most cases are using the 
[1, 2] format, so make that the consistent one.

[1] in llvm `.td` files, the regex `\[[^ ]` (bracket followed by not-a-space) 
shows up ~400 times, but `\[\s[^ ]` (bracket followed by one space and one 
not-a-space) shows up ~40 times => ~90% uses this format.


Repository:
  rC Clang

https://reviews.llvm.org/D55964

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestTableGen.cpp


Index: unittests/Format/FormatTestTableGen.cpp
===
--- unittests/Format/FormatTestTableGen.cpp
+++ unittests/Format/FormatTestTableGen.cpp
@@ -52,5 +52,9 @@
"   \"very long help string\">;\n");
 }
 
+TEST_F(FormatTestTableGen, NoSpacesInSquareBracketLists) {
+  verifyFormat("def flag : Flag<[\"-\", \"--\"], \"foo\">;\n");
+}
+
 } // namespace format
 } // end namespace clang
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -432,6 +432,10 @@
   } else if (CurrentToken->is(tok::r_square) && Parent &&
  Parent->is(TT_TemplateCloser)) {
 Left->Type = TT_ArraySubscriptLSquare;
+  } else if (Style.Language == FormatStyle::LK_TableGen) {
+// TableGen treats '[' as array subscripts to avoid spaces, e.g.
+// def foo : Flag<["-", "--"], "foo">;
+Left->Type = TT_ArraySubscriptLSquare;
   } else if (Style.Language == FormatStyle::LK_Proto ||
  Style.Language == FormatStyle::LK_TextProto) {
 // Square braces in LK_Proto can either be message field attributes:


Index: unittests/Format/FormatTestTableGen.cpp
===
--- unittests/Format/FormatTestTableGen.cpp
+++ unittests/Format/FormatTestTableGen.cpp
@@ -52,5 +52,9 @@
"   \"very long help string\">;\n");
 }
 
+TEST_F(FormatTestTableGen, NoSpacesInSquareBracketLists) {
+  verifyFormat("def flag : Flag<[\"-\", \"--\"], \"foo\">;\n");
+}
+
 } // namespace format
 } // end namespace clang
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -432,6 +432,10 @@
   } else if (CurrentToken->is(tok::r_square) && Parent &&
  Parent->is(TT_TemplateCloser)) {
 Left->Type = TT_ArraySubscriptLSquare;
+  } else if (Style.Language == FormatStyle::LK_TableGen) {
+// TableGen treats '[' as array subscripts to avoid spaces, e.g.
+// def foo : Flag<["-", "--"], "foo">;
+Left->Type = TT_ArraySubscriptLSquare;
   } else if (Style.Language == FormatStyle::LK_Proto ||
  Style.Language == FormatStyle::LK_TextProto) {
 // Square braces in LK_Proto can either be message field attributes:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55823: [analyzer] Fix backward compatibility issue after D53280 'Emit an error for invalid -analyzer-config inputs'

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

I think `Args.getArgString` might return `nullptr` so that's why you could 
crash.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D55823



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


r349853 - [CodeGen] Fix a test from r349848 by replacing `objc_` with `llvm.objc.`

2018-12-20 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Thu Dec 20 15:26:29 2018
New Revision: 349853

URL: http://llvm.org/viewvc/llvm-project?rev=349853=rev
Log:
[CodeGen] Fix a test from r349848 by replacing `objc_` with `llvm.objc.`

Modified:
cfe/trunk/test/CodeGenObjCXX/inheriting-constructor-cleanup.mm

Modified: cfe/trunk/test/CodeGenObjCXX/inheriting-constructor-cleanup.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/inheriting-constructor-cleanup.mm?rev=349853=349852=349853=diff
==
--- cfe/trunk/test/CodeGenObjCXX/inheriting-constructor-cleanup.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/inheriting-constructor-cleanup.mm Thu Dec 20 
15:26:29 2018
@@ -23,7 +23,7 @@ void f() {
 }
 // CHECK-LABEL: define void @_Z1fv
 // CHECK:   %[[TMP:.*]] = call i8* @_Z1gv()
-// CHECK:   {{.*}} = call i8* @objc_retainAutoreleasedReturnValue(i8* 
%[[TMP]])
+// CHECK:   {{.*}} = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* 
%[[TMP]])
 // CHECK:   call void (%struct.Base*, i8*, ...) 
@_ZN4BaseC2E6Strongz(%struct.Base* {{.*}}, i8* {{.*}})
 // CHECK-NEXT:  call void @_ZN9InheritorD1Ev(%struct.Inheritor* {{.*}})
 
@@ -37,7 +37,7 @@ void f() {
 // CHECK:   call void @_ZN6StrongD2Ev(%struct.Strong* {{.*}})
 
 // CHECK-LABEL: define linkonce_odr void @_ZN6StrongD2Ev(%struct.Strong* 
{{.*}})
-// CHECK:   call void @objc_storeStrong(i8** {{.*}}, i8* null)
+// CHECK:   call void @llvm.objc.storeStrong(i8** {{.*}}, i8* null)
 
 // CHECK-LABEL: define linkonce_odr void @_ZN9InheritorD2Ev(%struct.Inheritor* 
{{.*}})
 // CHECK:   call void @_ZN14NonTrivialDtorD2Ev(%struct.NonTrivialDtor* 
{{.*}})


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


[PATCH] D55869: Convert some ObjC retain/release msgSends to runtime calls

2018-12-20 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D55869#1338003 , @theraven wrote:

> This should be fine for the GNUstep runtime (the GCC runtime doesn't support 
> ARC at all).  My main concern is that it will break already-released versions 
> of the runtime built with a newer version of clang.  I can easily enable a 
> new flag in the next release, but doing so for older ones is more problematic.


Well, it won't break as long as you don't tell the compiler that this is an 
acceptable rewrite to do.  I'm not sure there's a perfect way to stage this 
if/when you start thinking about enabling that — you can of course start 
passing the "don't rewrite message sends" flag in new releases of GNUstep, but 
it'll always be *possible* that someone might use a newer Clang to compile an 
older version of the runtime that doesn't do that workaround.  On the other 
hand, the brokenness of the result will not be subtle.


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

https://reviews.llvm.org/D55869



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


[PATCH] D55907: [analyzer] RetainCount: Bluntly suppress the CFRetain detection heuristic on a couple of CM functions.

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

In general, I'm against hardcoding, and I think we should use the annotations 
indicating that the function does retain.
(or use a naming convention, and use an annotation to indicate that the 
function does not retain).

However, if this is prohibitive for some reason, we could use this approach as 
well.


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

https://reviews.llvm.org/D55907



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


[PATCH] D55543: [CodeGen] Fix assertion on throwing object with inlined inherited constructor and non-trivial destructor.

2018-12-20 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Thanks for the review, John. Committed the change and will watch the buildbots 
on non-Darwin platform.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55543



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


[PATCH] D55850: [OpenCL] Allow address spaces as method qualifiers

2018-12-20 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Parse/ParseDecl.cpp:6162
+}
+  }
+

Anastasia wrote:
> rjmccall wrote:
> > Anastasia wrote:
> > > rjmccall wrote:
> > > > This is enforcing a restriction that users write `const __private`, 
> > > > which seems unreasonable.  It looks like `ParseTypeQualifierList` takes 
> > > > a flag saying not to parse attributes; try adding a new option to that 
> > > > enum allowing address-space attributes.
> > > > 
> > > > Collecting the attributes on the type-qualifiers `DeclSpec` rather than 
> > > > adding them as function attributes seems correct.
> > > Do you mean `ParseTypeQualifierListOpt`? That already parses the address 
> > > spaces unconditionally. The problem is however that we are using local 
> > > `DeclSpec` - `DS` variable here during the function qualifiers parsing 
> > > because the `DeclSpec` member of the `Declarator` corresponds to the 
> > > return type as far as I understand it. Therefore I am propagating missing 
> > > address space attributes from the local `DS` variable into `FnAttrs` to 
> > > be used in the function type info.
> > > 
> > > With current patch both of the following two forms:
> > >   struct C {
> > > void foo() __local const;
> > >   };
> > > and 
> > >   struct C {
> > > void foo() const __local;
> > >   };
> > > would be parsed correctly generating identical IR
> > >   declare void @_ZNU3AS3K1C3fooEv(%struct.C addrspace(3)*)
> > > 
> > > 
> > > 
> > Oh, I see, sorry.  Why filter on attributes at all, then?  We should *only* 
> > be parsing qualifier attributes in that list.
> > 
> > I actually think it would be reasonable to change 
> > `DeclaratorChunk::FunctionTypeInfo` to just store a `DeclSpec` for all the 
> > qualifiers; we're already duplicating an unfortunate amount of the logic 
> > from `DeclSpec`, like remembering `SourceLocation`s for all the qualifiers. 
> >  You'll have to store it out-of-line, but we already store e.g. parameters 
> > out of line, so the machinery for allocating and destroying it already 
> > exists.  Just make sure we don't actually allocate anything in the common 
> > case where there aren't any qualifiers (i.e. for C and non-member C++ 
> > functions).
> > 
> > Also, I suspect that the use of `CXXThisScopeRAII` below this needs to be 
> > updated to pull *all* the qualifiers out of `DS`.  Maybe Sema should have a 
> > function for that.
> I have uploaded a separate patch for this:
> https://reviews.llvm.org/D55948
> 
> I think I can't avoid storing `DeclSpec` for non-memeber functions in C++ 
> because we still use them to give diagnostics about the qualifiers. For 
> example:
>   test.cpp:1:12: error: non-member function cannot have 'const' qualifier
>   void foo() const;
> 
> As for `CXXThisScopeRAII`, we seem to be adding other qualifiers to the 
> `QualType` directly (while building it), so there seems to be no function to 
> collect them into `Qualifiers`. I can, however, add code to collect address 
> space qualifiers here. I guess we don't have any other missing qualifiers to 
> collect?
> 
I think you can probably avoid allocating and storing a `DeclSpec` if there are 
no qualifiers, which should be easy to test, and then the absence of a 
`DeclSpec` should allow Sema to quickly bail out of the check for illegal 
qualifiers on a non-member function type.

> I guess we don't have any other missing qualifiers to collect?

Not that are legal to apply to `this`.


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

https://reviews.llvm.org/D55850



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


[PATCH] D55543: [CodeGen] Fix assertion on throwing object with inlined inherited constructor and non-trivial destructor.

2018-12-20 Thread Volodymyr Sapsai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC349848: [CodeGen] Fix assertion on emitting cleanup for 
object with inlined inherited… (authored by vsapsai, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D55543?vs=178921=179165#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D55543

Files:
  lib/CodeGen/CGClass.cpp
  test/CodeGenCXX/inheriting-constructor-cleanup.cpp
  test/CodeGenObjCXX/inheriting-constructor-cleanup.mm

Index: test/CodeGenCXX/inheriting-constructor-cleanup.cpp
===
--- test/CodeGenCXX/inheriting-constructor-cleanup.cpp
+++ test/CodeGenCXX/inheriting-constructor-cleanup.cpp
@@ -0,0 +1,52 @@
+// RUN: %clang_cc1 -triple x86_64-darwin -std=c++11 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-darwin -std=c++11 -fcxx-exceptions -fexceptions -emit-llvm -o - %s | FileCheck %s --check-prefix=EXCEPTIONS
+
+// PR36748
+// rdar://problem/45805151
+
+// Classes to verify order of destroying function parameters.
+struct S1 {
+  ~S1();
+};
+struct S2 {
+  ~S2();
+};
+
+struct Base {
+  // Use variadic args to cause inlining the inherited constructor.
+  Base(const S1&, const S2&, const char *fmt, ...) {}
+};
+
+struct NonTrivialDtor {
+  ~NonTrivialDtor() {}
+};
+struct Inheritor : public NonTrivialDtor, public Base {
+  using Base::Base;
+};
+
+void f() {
+  Inheritor(S1(), S2(), "foo");
+  // CHECK-LABEL: define void @_Z1fv
+  // CHECK: %[[TMP1:.*]] = alloca %struct.S1
+  // CHECK: %[[TMP2:.*]] = alloca %struct.S2
+  // CHECK: call void (%struct.Base*, %struct.S1*, %struct.S2*, i8*, ...) @_ZN4BaseC2ERK2S1RK2S2PKcz(%struct.Base* {{.*}}, %struct.S1* dereferenceable(1) %[[TMP1]], %struct.S2* dereferenceable(1) %[[TMP2]], i8* {{.*}})
+  // CHECK-NEXT: call void @_ZN9InheritorD1Ev(%struct.Inheritor* {{.*}})
+  // CHECK-NEXT: call void @_ZN2S2D1Ev(%struct.S2* %[[TMP2]])
+  // CHECK-NEXT: call void @_ZN2S1D1Ev(%struct.S1* %[[TMP1]])
+
+  // EXCEPTIONS-LABEL: define void @_Z1fv
+  // EXCEPTIONS: %[[TMP1:.*]] = alloca %struct.S1
+  // EXCEPTIONS: %[[TMP2:.*]] = alloca %struct.S2
+  // EXCEPTIONS: invoke void (%struct.Base*, %struct.S1*, %struct.S2*, i8*, ...) @_ZN4BaseC2ERK2S1RK2S2PKcz(%struct.Base* {{.*}}, %struct.S1* dereferenceable(1) %[[TMP1]], %struct.S2* dereferenceable(1) %[[TMP2]], i8* {{.*}})
+  // EXCEPTIONS-NEXT: to label %[[CONT:.*]] unwind label %[[LPAD:.*]]
+
+  // EXCEPTIONS: [[CONT]]:
+  // EXCEPTIONS-NEXT: call void @_ZN9InheritorD1Ev(%struct.Inheritor* {{.*}})
+  // EXCEPTIONS-NEXT: call void @_ZN2S2D1Ev(%struct.S2* %[[TMP2]])
+  // EXCEPTIONS-NEXT: call void @_ZN2S1D1Ev(%struct.S1* %[[TMP1]])
+
+  // EXCEPTIONS: [[LPAD]]:
+  // EXCEPTIONS: call void @_ZN14NonTrivialDtorD2Ev(%struct.NonTrivialDtor* {{.*}})
+  // EXCEPTIONS-NEXT: call void @_ZN2S2D1Ev(%struct.S2* %[[TMP2]])
+  // EXCEPTIONS-NEXT: call void @_ZN2S1D1Ev(%struct.S1* %[[TMP1]])
+}
Index: test/CodeGenObjCXX/inheriting-constructor-cleanup.mm
===
--- test/CodeGenObjCXX/inheriting-constructor-cleanup.mm
+++ test/CodeGenObjCXX/inheriting-constructor-cleanup.mm
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -triple x86_64-darwin -std=c++11 -fobjc-arc -emit-llvm -o - %s | FileCheck %s --implicit-check-not "call\ "
+// rdar://problem/45805151
+
+struct Strong {
+  __strong id x;
+};
+
+struct Base {
+  // Use variadic args to cause inlining the inherited constructor.
+  Base(Strong s, ...) {}
+};
+
+struct NonTrivialDtor {
+  ~NonTrivialDtor() {}
+};
+struct Inheritor : public NonTrivialDtor, public Base {
+  using Base::Base;
+};
+
+id g(void);
+void f() {
+  Inheritor({g()});
+}
+// CHECK-LABEL: define void @_Z1fv
+// CHECK:   %[[TMP:.*]] = call i8* @_Z1gv()
+// CHECK:   {{.*}} = call i8* @objc_retainAutoreleasedReturnValue(i8* %[[TMP]])
+// CHECK:   call void (%struct.Base*, i8*, ...) @_ZN4BaseC2E6Strongz(%struct.Base* {{.*}}, i8* {{.*}})
+// CHECK-NEXT:  call void @_ZN9InheritorD1Ev(%struct.Inheritor* {{.*}})
+
+// CHECK-LABEL: define linkonce_odr void @_ZN4BaseC2E6Strongz(%struct.Base* {{.*}}, i8* {{.*}}, ...)
+// CHECK:   call void @_ZN6StrongD1Ev(%struct.Strong* {{.*}})
+
+// CHECK-LABEL: define linkonce_odr void @_ZN9InheritorD1Ev(%struct.Inheritor* {{.*}})
+// CHECK:   call void @_ZN9InheritorD2Ev(%struct.Inheritor* {{.*}})
+
+// CHECK-LABEL: define linkonce_odr void @_ZN6StrongD1Ev(%struct.Strong* {{.*}})
+// CHECK:   call void @_ZN6StrongD2Ev(%struct.Strong* {{.*}})
+
+// CHECK-LABEL: define linkonce_odr void @_ZN6StrongD2Ev(%struct.Strong* {{.*}})
+// CHECK:   call void @objc_storeStrong(i8** {{.*}}, i8* null)
+
+// CHECK-LABEL: define linkonce_odr void @_ZN9InheritorD2Ev(%struct.Inheritor* {{.*}})
+// CHECK:   call void @_ZN14NonTrivialDtorD2Ev(%struct.NonTrivialDtor* {{.*}})
Index: lib/CodeGen/CGClass.cpp

r349848 - [CodeGen] Fix assertion on emitting cleanup for object with inlined inherited constructor and non-trivial destructor.

2018-12-20 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Thu Dec 20 14:43:26 2018
New Revision: 349848

URL: http://llvm.org/viewvc/llvm-project?rev=349848=rev
Log:
[CodeGen] Fix assertion on emitting cleanup for object with inlined inherited 
constructor and non-trivial destructor.

Fixes assertion
> Assertion failed: (isa(Val) && "cast() argument of incompatible 
> type!"), function cast, file llvm/Support/Casting.h, line 255.

It was triggered by trying to cast `FunctionDecl` to `CXXMethodDecl` as
`CGF.CurCodeDecl` in `CallBaseDtor::Emit`. It was happening because
cleanups were emitted in `ScalarExprEmitter::VisitExprWithCleanups`
after destroying `InlinedInheritingConstructorScope`, so
`CodeGenFunction.CurCodeDecl` didn't correspond to expected cleanup decl.

Fix the assertion by emitting cleanups before leaving
`InlinedInheritingConstructorScope` and changing `CurCodeDecl`.

Test cases based on a patch by Shoaib Meenai.

Fixes PR36748.

rdar://problem/45805151

Reviewers: rsmith, rjmccall

Reviewed By: rjmccall

Subscribers: jkorous, dexonsmith, cfe-commits, smeenai, compnerd

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


Added:
cfe/trunk/test/CodeGenCXX/inheriting-constructor-cleanup.cpp
cfe/trunk/test/CodeGenObjCXX/inheriting-constructor-cleanup.mm
Modified:
cfe/trunk/lib/CodeGen/CGClass.cpp

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=349848=349847=349848=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Thu Dec 20 14:43:26 2018
@@ -2208,6 +2208,7 @@ void CodeGenFunction::EmitInlinedInherit
   GlobalDecl GD(Ctor, CtorType);
   InlinedInheritingConstructorScope Scope(*this, GD);
   ApplyInlineDebugLocation DebugScope(*this, GD);
+  RunCleanupsScope RunCleanups(*this);
 
   // Save the arguments to be passed to the inherited constructor.
   CXXInheritedCtorInitExprArgs = Args;

Added: cfe/trunk/test/CodeGenCXX/inheriting-constructor-cleanup.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/inheriting-constructor-cleanup.cpp?rev=349848=auto
==
--- cfe/trunk/test/CodeGenCXX/inheriting-constructor-cleanup.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/inheriting-constructor-cleanup.cpp Thu Dec 20 
14:43:26 2018
@@ -0,0 +1,52 @@
+// RUN: %clang_cc1 -triple x86_64-darwin -std=c++11 -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-darwin -std=c++11 -fcxx-exceptions 
-fexceptions -emit-llvm -o - %s | FileCheck %s --check-prefix=EXCEPTIONS
+
+// PR36748
+// rdar://problem/45805151
+
+// Classes to verify order of destroying function parameters.
+struct S1 {
+  ~S1();
+};
+struct S2 {
+  ~S2();
+};
+
+struct Base {
+  // Use variadic args to cause inlining the inherited constructor.
+  Base(const S1&, const S2&, const char *fmt, ...) {}
+};
+
+struct NonTrivialDtor {
+  ~NonTrivialDtor() {}
+};
+struct Inheritor : public NonTrivialDtor, public Base {
+  using Base::Base;
+};
+
+void f() {
+  Inheritor(S1(), S2(), "foo");
+  // CHECK-LABEL: define void @_Z1fv
+  // CHECK: %[[TMP1:.*]] = alloca %struct.S1
+  // CHECK: %[[TMP2:.*]] = alloca %struct.S2
+  // CHECK: call void (%struct.Base*, %struct.S1*, %struct.S2*, i8*, ...) 
@_ZN4BaseC2ERK2S1RK2S2PKcz(%struct.Base* {{.*}}, %struct.S1* dereferenceable(1) 
%[[TMP1]], %struct.S2* dereferenceable(1) %[[TMP2]], i8* {{.*}})
+  // CHECK-NEXT: call void @_ZN9InheritorD1Ev(%struct.Inheritor* {{.*}})
+  // CHECK-NEXT: call void @_ZN2S2D1Ev(%struct.S2* %[[TMP2]])
+  // CHECK-NEXT: call void @_ZN2S1D1Ev(%struct.S1* %[[TMP1]])
+
+  // EXCEPTIONS-LABEL: define void @_Z1fv
+  // EXCEPTIONS: %[[TMP1:.*]] = alloca %struct.S1
+  // EXCEPTIONS: %[[TMP2:.*]] = alloca %struct.S2
+  // EXCEPTIONS: invoke void (%struct.Base*, %struct.S1*, %struct.S2*, i8*, 
...) @_ZN4BaseC2ERK2S1RK2S2PKcz(%struct.Base* {{.*}}, %struct.S1* 
dereferenceable(1) %[[TMP1]], %struct.S2* dereferenceable(1) %[[TMP2]], i8* 
{{.*}})
+  // EXCEPTIONS-NEXT: to label %[[CONT:.*]] unwind label %[[LPAD:.*]]
+
+  // EXCEPTIONS: [[CONT]]:
+  // EXCEPTIONS-NEXT: call void @_ZN9InheritorD1Ev(%struct.Inheritor* {{.*}})
+  // EXCEPTIONS-NEXT: call void @_ZN2S2D1Ev(%struct.S2* %[[TMP2]])
+  // EXCEPTIONS-NEXT: call void @_ZN2S1D1Ev(%struct.S1* %[[TMP1]])
+
+  // EXCEPTIONS: [[LPAD]]:
+  // EXCEPTIONS: call void @_ZN14NonTrivialDtorD2Ev(%struct.NonTrivialDtor* 
{{.*}})
+  // EXCEPTIONS-NEXT: call void @_ZN2S2D1Ev(%struct.S2* %[[TMP2]])
+  // EXCEPTIONS-NEXT: call void @_ZN2S1D1Ev(%struct.S1* %[[TMP1]])
+}

Added: cfe/trunk/test/CodeGenObjCXX/inheriting-constructor-cleanup.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/inheriting-constructor-cleanup.mm?rev=349848=auto
==
--- 

[PATCH] D55628: Add support for "labels" on push/pop directives in #pragma clang attribute

2018-12-20 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC349845: Add support for namespaces on #pragma clang 
attribute (authored by epilk, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D55628?vs=178952=179160#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D55628

Files:
  docs/LanguageExtensions.rst
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/Parse/ParsePragma.cpp
  lib/Sema/SemaAttr.cpp
  test/Parser/pragma-attribute.cpp
  test/Sema/pragma-attribute-namespace.c

Index: lib/Sema/SemaAttr.cpp
===
--- lib/Sema/SemaAttr.cpp
+++ lib/Sema/SemaAttr.cpp
@@ -631,28 +631,46 @@
   {PragmaLoc, , std::move(SubjectMatchRules), /*IsUsed=*/false});
 }
 
-void Sema::ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc) {
+void Sema::ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc,
+ const IdentifierInfo *Namespace) {
   PragmaAttributeStack.emplace_back();
   PragmaAttributeStack.back().Loc = PragmaLoc;
+  PragmaAttributeStack.back().Namespace = Namespace;
 }
 
-void Sema::ActOnPragmaAttributePop(SourceLocation PragmaLoc) {
+void Sema::ActOnPragmaAttributePop(SourceLocation PragmaLoc,
+   const IdentifierInfo *Namespace) {
   if (PragmaAttributeStack.empty()) {
-Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch);
+Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch) << 1;
 return;
   }
 
-  for (const PragmaAttributeEntry  :
-   PragmaAttributeStack.back().Entries) {
-if (!Entry.IsUsed) {
-  assert(Entry.Attribute && "Expected an attribute");
-  Diag(Entry.Attribute->getLoc(), diag::warn_pragma_attribute_unused)
-  << Entry.Attribute->getName();
-  Diag(PragmaLoc, diag::note_pragma_attribute_region_ends_here);
+  // Dig back through the stack trying to find the most recently pushed group
+  // that in Namespace. Note that this works fine if no namespace is present,
+  // think of push/pops without namespaces as having an implicit "nullptr"
+  // namespace.
+  for (size_t Index = PragmaAttributeStack.size(); Index;) {
+--Index;
+if (PragmaAttributeStack[Index].Namespace == Namespace) {
+  for (const PragmaAttributeEntry  :
+   PragmaAttributeStack[Index].Entries) {
+if (!Entry.IsUsed) {
+  assert(Entry.Attribute && "Expected an attribute");
+  Diag(Entry.Attribute->getLoc(), diag::warn_pragma_attribute_unused)
+  << *Entry.Attribute;
+  Diag(PragmaLoc, diag::note_pragma_attribute_region_ends_here);
+}
+  }
+  PragmaAttributeStack.erase(PragmaAttributeStack.begin() + Index);
+  return;
 }
   }
 
-  PragmaAttributeStack.pop_back();
+  if (Namespace)
+Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch)
+<< 0 << Namespace->getName();
+  else
+Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch) << 1;
 }
 
 void Sema::AddPragmaAttributes(Scope *S, Decl *D) {
Index: lib/Parse/ParsePragma.cpp
===
--- lib/Parse/ParsePragma.cpp
+++ lib/Parse/ParsePragma.cpp
@@ -1139,6 +1139,7 @@
   enum ActionType { Push, Pop, Attribute };
   ParsedAttributes 
   ActionType Action;
+  const IdentifierInfo *Namespace = nullptr;
   ArrayRef Tokens;
 
   PragmaAttributeInfo(ParsedAttributes ) : Attributes(Attributes) {}
@@ -1393,7 +1394,7 @@
   auto *Info = static_cast(Tok.getAnnotationValue());
   if (Info->Action == PragmaAttributeInfo::Pop) {
 ConsumeAnnotationToken();
-Actions.ActOnPragmaAttributePop(PragmaLoc);
+Actions.ActOnPragmaAttributePop(PragmaLoc, Info->Namespace);
 return;
   }
   // Parse the actual attribute with its arguments.
@@ -1403,7 +1404,7 @@
 
   if (Info->Action == PragmaAttributeInfo::Push && Info->Tokens.empty()) {
 ConsumeAnnotationToken();
-Actions.ActOnPragmaAttributeEmptyPush(PragmaLoc);
+Actions.ActOnPragmaAttributeEmptyPush(PragmaLoc, Info->Namespace);
 return;
   }
 
@@ -1555,7 +1556,7 @@
 
   // Handle a mixed push/attribute by desurging to a push, then an attribute.
   if (Info->Action == PragmaAttributeInfo::Push)
-Actions.ActOnPragmaAttributeEmptyPush(PragmaLoc);
+Actions.ActOnPragmaAttributeEmptyPush(PragmaLoc, Info->Namespace);
 
   Actions.ActOnPragmaAttributeAttribute(Attribute, PragmaLoc,
 std::move(SubjectMatchRules));
@@ -3118,12 +3119,22 @@
 ///
 /// The syntax is:
 /// \code
-///  #pragma clang attribute push(attribute, subject-set)
+///  #pragma clang attribute push (attribute, subject-set)
 ///  #pragma clang attribute push
 ///  #pragma clang attribute (attribute, subject-set)
 ///  #pragma clang attribute pop
 /// \endcode
 ///
+/// 

r349845 - Add support for namespaces on #pragma clang attribute

2018-12-20 Thread Erik Pilkington via cfe-commits
Author: epilk
Date: Thu Dec 20 14:32:04 2018
New Revision: 349845

URL: http://llvm.org/viewvc/llvm-project?rev=349845=rev
Log:
Add support for namespaces on #pragma clang attribute

Namespaces are introduced by adding an "identifier." before a
push/pop directive. Pop directives with namespaces can only pop a
attribute group that was pushed with the same namespace. Push and pop
directives that don't opt into namespaces have the same semantics.

This is necessary to prevent a pitfall of using multiple #pragma
clang attribute directives spread out in a large file, particularly
when macros are involved. It isn't easy to see which pop corripsonds
to which push, so its easy to inadvertently pop the wrong group.

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

Added:
cfe/trunk/test/Sema/pragma-attribute-namespace.c
Modified:
cfe/trunk/docs/LanguageExtensions.rst
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Parse/ParsePragma.cpp
cfe/trunk/lib/Sema/SemaAttr.cpp
cfe/trunk/test/Parser/pragma-attribute.cpp

Modified: cfe/trunk/docs/LanguageExtensions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LanguageExtensions.rst?rev=349845=349844=349845=diff
==
--- cfe/trunk/docs/LanguageExtensions.rst (original)
+++ cfe/trunk/docs/LanguageExtensions.rst Thu Dec 20 14:32:04 2018
@@ -2697,6 +2697,36 @@ The ``__declspec`` style syntax is also
 A single push directive accepts only one attribute regardless of the syntax
 used.
 
+Because multiple push directives can be nested, if you're writing a macro that
+expands to ``_Pragma("clang attribute")`` it's good hygiene (though not
+required) to add a namespace to your push/pop directives. A pop directive with 
a
+namespace will pop the innermost push that has that same namespace. This will
+ensure that another macro's ``pop`` won't inadvertently pop your attribute. 
Note
+that an ``pop`` without a namespace will pop the innermost ``push`` without a
+namespace. ``push``es with a namespace can only be popped by ``pop`` with the
+same namespace. For instance:
+
+.. code-block:: c++
+
+   #define ASSUME_NORETURN_BEGIN _Pragma("clang attribute AssumeNoreturn.push 
([[noreturn]], apply_to = function)")
+   #define ASSUME_NORETURN_END   _Pragma("clang attribute AssumeNoreturn.pop")
+
+   #define ASSUME_UNAVAILABLE_BEGIN _Pragma("clang attribute Unavailable.push 
(__attribute__((unavailable)), apply_to=function)")
+   #define ASSUME_UNAVAILABLE_END   _Pragma("clang attribute Unavailable.pop")
+
+
+   ASSUME_NORETURN_BEGIN
+   ASSUME_UNAVAILABLE_BEGIN
+   void function(); // function has [[noreturn]] and 
__attribute__((unavailable))
+   ASSUME_NORETURN_END
+   void other_function(); // function has __attribute__((unavailable))
+   ASSUME_UNAVAILABLE_END
+
+Without the namespaces on the macros, ``other_function`` will be annotated with
+``[[noreturn]]`` instead of ``__attribute__((unavailable))``. This may seem 
like
+a contrived example, but its very possible for this kind of situation to appear
+in real code if the pragmas are spread out accross a large file.
+
 Subject Match Rules
 ---
 

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=349845=349844=349845=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Thu Dec 20 14:32:04 
2018
@@ -1100,6 +1100,13 @@ def err_pragma_attribute_unknown_subject
   "sub-rules: %3}2">;
 def err_pragma_attribute_duplicate_subject : Error<
   "duplicate attribute subject matcher '%0'">;
+def err_pragma_attribute_expected_period : Error<
+  "expected '.' after pragma attribute namespace %0">;
+def err_pragma_attribute_namespace_on_attribute : Error<
+  "namespace can only apply to 'push' or 'pop' directives">;
+def note_pragma_attribute_namespace_on_attribute : Note<
+  "omit the namespace to add attributes to the most-recently"
+  " pushed attribute group">;
 
 def err_opencl_unroll_hint_on_non_loop : Error<
   "OpenCL only supports 'opencl_unroll_hint' attribute on for, while, and do 
statements">;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=349845=349844=349845=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Dec 20 14:32:04 
2018
@@ -815,7 +815,8 @@ def err_pragma_attribute_matcher_negated
 def err_pragma_attribute_invalid_matchers : Error<
   "attribute 

r349843 - Revert "[driver] [analyzer] Fix a backward compatibility issue after r348038."

2018-12-20 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Thu Dec 20 14:29:49 2018
New Revision: 349843

URL: http://llvm.org/viewvc/llvm-project?rev=349843=rev
Log:
Revert "[driver] [analyzer] Fix a backward compatibility issue after r348038."

This reverts commits r349824, r349828, r349835.

More buildbot failures were noticed.

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

rdar://problem/46504165

Removed:
cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Analysis/invalid-analyzer-config-value.c

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=349843=349842=349843=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Thu Dec 20 14:29:49 2018
@@ -2360,6 +2360,9 @@ static void RenderAnalyzerOptions(const
   // Treat blocks as analysis entry points.
   CmdArgs.push_back("-analyzer-opt-analyze-nested-blocks");
 
+  // Enable compatilibily mode to avoid analyzer-config related errors.
+  CmdArgs.push_back("-analyzer-config-compatibility-mode=true");
+
   // Add default argument set.
   if (!Args.hasArg(options::OPT__analyzer_no_default_checks)) {
 CmdArgs.push_back("-analyzer-checker=core");
@@ -3735,16 +3738,6 @@ void Clang::ConstructJob(Compilation ,
   if (isa(JA))
 RenderAnalyzerOptions(Args, CmdArgs, Triple, Input);
 
-  // Enable compatilibily mode to avoid analyzer-config related errors.
-  // Since we can't access frontend flags through hasArg, let's manually 
iterate
-  // through them.
-  for (size_t Index = 0; Index < Args.size(); ++Index) {
-if (StringRef(Args.getArgString(Index)).contains("-analyzer-config")) {
-  CmdArgs.push_back("-analyzer-config-compatibility-mode=true");
-  break;
-}
-  }
-
   CheckCodeGenerationOptions(D, Args);
 
   unsigned FunctionAlignment = ParseFunctionAlignment(TC, Args);

Removed: cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c?rev=349842=auto
==
--- cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c (original)
+++ cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c (removed)
@@ -1,80 +0,0 @@
-// Same as invalid-analyzer-config-value.c but without -analyzer-config
-// in the file name, so that argument string pattern matching
-// didn't accidentally match it.
-
-// RUN: not %clang_analyze_cc1 -verify %s \
-// RUN:   -analyzer-checker=core \
-// RUN:   -analyzer-config notes-as-events=yesplease \
-// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-BOOL-INPUT
-
-// CHECK-BOOL-INPUT: (frontend): invalid input for analyzer-config option
-// CHECK-BOOL-INPUT-SAME:'notes-as-events', that expects a boolean 
value
-
-// RUN: %clang_analyze_cc1 -verify %s \
-// RUN:   -analyzer-checker=core \
-// RUN:   -analyzer-config-compatibility-mode=true \
-// RUN:   -analyzer-config notes-as-events=yesplease
-
-
-// RUN: not %clang_analyze_cc1 -verify %s \
-// RUN:   -analyzer-checker=core \
-// RUN:   -analyzer-config max-inlinable-size=400km/h \
-// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-UINT-INPUT
-
-// CHECK-UINT-INPUT: (frontend): invalid input for analyzer-config option
-// CHECK-UINT-INPUT-SAME:'max-inlinable-size', that expects an unsigned
-// CHECK-UINT-INPUT-SAME:value
-
-// RUN: %clang_analyze_cc1 -verify %s \
-// RUN:   -analyzer-checker=core \
-// RUN:   -analyzer-config-compatibility-mode=true \
-// RUN:   -analyzer-config max-inlinable-size=400km/h
-
-
-// RUN: not %clang_analyze_cc1 -verify %s \
-// RUN:   -analyzer-checker=core \
-// RUN:   -analyzer-config ctu-dir=0123012301230123 \
-// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-FILENAME-INPUT
-
-// CHECK-FILENAME-INPUT: (frontend): invalid input for analyzer-config option
-// CHECK-FILENAME-INPUT-SAME:'ctu-dir', that expects a filename
-// CHECK-FILENAME-INPUT-SAME:value
-
-// RUN: %clang_analyze_cc1 -verify %s \
-// RUN:   -analyzer-checker=core \
-// RUN:   -analyzer-config-compatibility-mode=true \
-// RUN:   -analyzer-config ctu-dir=0123012301230123
-
-
-// RUN: not %clang_analyze_cc1 -verify %s \
-// RUN:   -analyzer-checker=core \
-// RUN:   -analyzer-config no-false-positives=true \
-// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-UNKNOWN-CFG
-
-// CHECK-UNKNOWN-CFG: (frontend): unknown analyzer-config 'no-false-positives'
-
-// RUN: %clang_analyze_cc1 -verify %s \
-// RUN:   -analyzer-checker=core \
-// RUN:   -analyzer-config-compatibility-mode=true \
-// RUN:   -analyzer-config no-false-positives=true
-
-
-// Test the driver properly using "analyzer-config-compatibility-mode=true",
-// no longer causing an error on input error.
-// RUN: 

[PATCH] D55865: [ObjC] Add a new attribute to opt-out of implicit callee retain/release in ARC

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



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:6117
+  // to ensure that the variable is 'const' so that we can error on
+  // modification, which can otherwise overrelease.
+  VD->setType(Ty.withConst());

erik.pilkington wrote:
> aaron.ballman wrote:
> > erik.pilkington wrote:
> > > aaron.ballman wrote:
> > > > overrelease -> over-release
> > > > 
> > > > Btw, this isn't a bit of a hack, it's a huge hack, IMO. Instead, can we 
> > > > simply err if the user hasn't specified `const` explicitly? I'm not a 
> > > > fan of "we're hiding this rather important language detail behind an 
> > > > attribute that can be ignored". This is especially worrisome because it 
> > > > means the variable is const only when ARC is enabled, which seems like 
> > > > surprising behavioral differences for that compiler flag.
> > > An important part of this feature is that it could applied to parameters 
> > > with `#pragma clang attribute` over code that has been audited to be 
> > > safe. If we require adding `const` to every parameter, then that falls 
> > > apart :/. 
> > > 
> > > For better or for worse, this is also consistent with other cases of 
> > > pseudo-strong in the language, i.e.:
> > > ```
> > > void f(NSArray *A) {
> > >   for (id Elem in A)
> > > Elem = nil; // fine in -fno-objc-arc, error in -fobjc-arc because 
> > > Elem is implicitly const.
> > > }
> > > ```
> > > An important part of this feature is that it could applied to parameters 
> > > with #pragma clang attribute over code that has been audited to be safe. 
> > > If we require adding const to every parameter, then that falls apart :/.
> > 
> > Thanks for letting me know about that use case; it adds some helpful 
> > context. However, I don't see why this falls apart -- if you're auditing 
> > the code, you could add the `const` qualifiers at that time, couldn't you? 
> > 
> > Alternatively, if we warned instead of erred on the absence of `const`, 
> > then this could be automated through clang-tidy by checking declarations 
> > that are marked with the attribute but are not marked `const` and use the 
> > fix-it machinery to update the code.
> > 
> > > For better or for worse, this is also consistent with other cases of 
> > > pseudo-strong in the language,
> > 
> > Yes, but it's weird behavior for an attribute. The attribute is applied to 
> > the *declaration* but then it silently modifies the *type* as well, but 
> > only for that one declaration (which is at odds with the usual rules for 
> > double-square bracket attributes and what they appertain to based on 
> > syntactic location). Sometimes, this will lead to good behavior (such as 
> > semantic checks and when doing AST matching over const-qualified types) and 
> > sometimes it will lead to confusing behavior (pretty-printing the code is 
> > going to stick const qualifers where none are written, diagnostics will 
> > talk about const qualifiers that aren't written in the source, etc).
> > 
> > Also, doesn't this cause ABI issues? If you write the attribute on a 
> > parameter, the presence or absence of that attribute is now part of the ABI 
> > for the function call because the parameter type will be mangled as being 
> > const-qualified. (Perhaps that's more of a feature than a bug -- I imagine 
> > you want both sides of the ABI to agree whether ARC is enabled or not?)
> > 
> > I'm wondering if this is weird enough that it should be using a keyword 
> > spelling instead of an attribute spelling? However, I'm not certain if that 
> > works with `#pragma clang attribute`.
> > Thanks for letting me know about that use case; it adds some helpful 
> > context. However, I don't see why this falls apart -- if you're auditing 
> > the code, you could add the const qualifiers at that time, couldn't you?
> 
> If we're going to require O(n) annotations for each application, then there 
> isn't really any reason to use the automatic #pragma annotations. I think it 
> would be nice to be able to throw this around more easily, so you could see 
> what parts of your program are worth auditing, and what stuff breaks. I don't 
> think the const annotation is a dealbreaker for me, but I think it makes this 
> feature easier to use and more consistent.
> 
> > Yes, but it's weird behavior for an attribute. The attribute is applied to 
> > the *declaration* but then it silently modifies the *type* as well, but 
> > only for that one declaration (which is at odds with the usual rules for 
> > double-square bracket attributes and what they appertain to based on 
> > syntactic location). Sometimes, this will lead to good behavior (such as 
> > semantic checks and when doing AST matching over const-qualified types) and 
> > sometimes it will lead to confusing behavior (pretty-printing the code is 
> > going to stick const qualifers where none are written, diagnostics will 
> > talk about const qualifiers that aren't written in the 

[PATCH] D55823: [analyzer] Fix backward compatibility issue after D53280 'Emit an error for invalid -analyzer-config inputs'

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

Hmm, this 
http://lab.llvm.org:8011/builders/clang-with-thin-lto-ubuntu/builds/14563/steps/test-stage2-compiler/logs/stdio
 also looks like ours. I guess i'll revert cause i've no idea what causes that.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D55823



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


[PATCH] D36790: [ObjC] Messages to 'self' in class methods that return 'instancetype' should use the pointer to the class as the result type of the message

2018-12-20 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rC349841: [ObjC] Messages to self in class methods 
that return instancetype should (authored by arphaman, committed by 
).

Changed prior to commit:
  https://reviews.llvm.org/D36790?vs=127192=179156#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D36790

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaExprObjC.cpp
  test/SemaObjC/multiple-method-names-in-class-self.m

Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -9842,21 +9842,20 @@
   /// \param Method - May be null.
   /// \param [out] ReturnType - The return type of the send.
   /// \return true iff there were any incompatible types.
-  bool CheckMessageArgumentTypes(QualType ReceiverType,
+  bool CheckMessageArgumentTypes(const Expr *Receiver, QualType ReceiverType,
  MultiExprArg Args, Selector Sel,
  ArrayRef SelectorLocs,
  ObjCMethodDecl *Method, bool isClassMessage,
- bool isSuperMessage,
- SourceLocation lbrac, SourceLocation rbrac,
- SourceRange RecRange,
+ bool isSuperMessage, SourceLocation lbrac,
+ SourceLocation rbrac, SourceRange RecRange,
  QualType , ExprValueKind );
 
   /// Determine the result of a message send expression based on
   /// the type of the receiver, the method expected to receive the message,
   /// and the form of the message send.
-  QualType getMessageSendResultType(QualType ReceiverType,
-ObjCMethodDecl *Method,
-bool isClassMessage, bool isSuperMessage);
+  QualType getMessageSendResultType(const Expr *Receiver, QualType ReceiverType,
+ObjCMethodDecl *Method, bool isClassMessage,
+bool isSuperMessage);
 
   /// If the given expression involves a message send to a method
   /// with a related result type, emit a note describing what happened.
Index: test/SemaObjC/multiple-method-names-in-class-self.m
===
--- test/SemaObjC/multiple-method-names-in-class-self.m
+++ test/SemaObjC/multiple-method-names-in-class-self.m
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -Wobjc-multiple-method-names -x objective-c -verify %s
+// RUN: %clang_cc1 -Wobjc-multiple-method-names -x objective-c -verify -fobjc-arc %s
+// expected-no-diagnostics
+
+@interface NSObj
+
++ (instancetype) alloc;
+
++ (_Nonnull instancetype) globalObject;
+
+@end
+
+@interface SelfAllocReturn: NSObj
+
+- (instancetype)initWithFoo:(int)x;
+
+@end
+
+@interface SelfAllocReturn2: NSObj
+
+- (instancetype)initWithFoo:(SelfAllocReturn *)x;
+
+@end
+
+@implementation SelfAllocReturn
+
+- (instancetype)initWithFoo:(int)x {
+return self;
+}
+
++ (instancetype) thingWithFoo:(int)x {
+return [[self alloc] initWithFoo: x];
+}
+
++ (void) initGlobal {
+  (void)[[self globalObject] initWithFoo: 20];
+}
+
+@end
Index: lib/Sema/SemaExprObjC.cpp
===
--- lib/Sema/SemaExprObjC.cpp
+++ lib/Sema/SemaExprObjC.cpp
@@ -1346,7 +1346,8 @@
   return transferNullability(ReceiverType);
 }
 
-QualType Sema::getMessageSendResultType(QualType ReceiverType,
+QualType Sema::getMessageSendResultType(const Expr *Receiver,
+QualType ReceiverType,
 ObjCMethodDecl *Method,
 bool isClassMessage,
 bool isSuperMessage) {
@@ -1357,8 +1358,33 @@
  isSuperMessage);
 
   // If this is a class message, ignore the nullability of the receiver.
-  if (isClassMessage)
+  if (isClassMessage) {
+// In a class method, class messages to 'self' that return instancetype can
+// be typed as the current class.  We can safely do this in ARC because self
+// can't be reassigned, and we do it unsafely outside of ARC because in
+// practice people never reassign self in class methods and there's some
+// virtue in not being aggressively pedantic.
+if (Receiver && Receiver->isObjCSelfExpr()) {
+  assert(ReceiverType->isObjCClassType() && "expected a Class self");
+  QualType T = Method->getSendResultType(ReceiverType);
+  AttributedType::stripOuterNullability(T);
+  if (T == Context.getObjCInstanceType()) {
+const ObjCMethodDecl *MD = cast(
+

[PATCH] D36790: [ObjC] Messages to 'self' in class methods that return 'instancetype' should use the pointer to the class as the result type of the message

2018-12-20 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman marked an inline comment as done.
arphaman added a comment.
Herald added subscribers: dexonsmith, jkorous.

Fixed comment, will commit.


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

https://reviews.llvm.org/D36790



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


[PATCH] D55907: [analyzer] RetainCount: Bluntly suppress the CFRetain detection heuristic on a couple of CM functions.

2018-12-20 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

This seems reasonable to me, but please have George take a look too.


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

https://reviews.llvm.org/D55907



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


r349841 - [ObjC] Messages to 'self' in class methods that return 'instancetype' should

2018-12-20 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Thu Dec 20 14:11:11 2018
New Revision: 349841

URL: http://llvm.org/viewvc/llvm-project?rev=349841=rev
Log:
[ObjC] Messages to 'self' in class methods that return 'instancetype' should
use the pointer to the class as the result type of the message

Prior to this commit, messages to self in class methods were treated as instance
methods to a Class value. When these methods returned instancetype the compiler
only saw id through the instancetype, and not the Interface *. This caused
problems when that return value was a receiver in a message send, as the
compiler couldn't select the right method declaration and had to rely on a
selection from the global method pool.

This commit modifies the semantics of such message sends and uses class messages
that are dispatched to the interface that corresponds to the class that contains
the class method. This ensures that instancetypes are correctly interpreted by
the compiler. This change is safe under ARC (as self can't be reassigned),
however, it also applies to MRR code as we are assuming that the user isn't
doing anything unreasonable.

rdar://20940997

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

Added:
cfe/trunk/test/SemaObjC/multiple-method-names-in-class-self.m
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExprObjC.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=349841=349840=349841=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Dec 20 14:11:11 2018
@@ -9842,21 +9842,20 @@ public:
   /// \param Method - May be null.
   /// \param [out] ReturnType - The return type of the send.
   /// \return true iff there were any incompatible types.
-  bool CheckMessageArgumentTypes(QualType ReceiverType,
+  bool CheckMessageArgumentTypes(const Expr *Receiver, QualType ReceiverType,
  MultiExprArg Args, Selector Sel,
  ArrayRef SelectorLocs,
  ObjCMethodDecl *Method, bool isClassMessage,
- bool isSuperMessage,
- SourceLocation lbrac, SourceLocation rbrac,
- SourceRange RecRange,
+ bool isSuperMessage, SourceLocation lbrac,
+ SourceLocation rbrac, SourceRange RecRange,
  QualType , ExprValueKind );
 
   /// Determine the result of a message send expression based on
   /// the type of the receiver, the method expected to receive the message,
   /// and the form of the message send.
-  QualType getMessageSendResultType(QualType ReceiverType,
-ObjCMethodDecl *Method,
-bool isClassMessage, bool isSuperMessage);
+  QualType getMessageSendResultType(const Expr *Receiver, QualType 
ReceiverType,
+ObjCMethodDecl *Method, bool 
isClassMessage,
+bool isSuperMessage);
 
   /// If the given expression involves a message send to a method
   /// with a related result type, emit a note describing what happened.

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=349841=349840=349841=diff
==
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Thu Dec 20 14:11:11 2018
@@ -1346,7 +1346,8 @@ static QualType getBaseMessageSendResult
   return transferNullability(ReceiverType);
 }
 
-QualType Sema::getMessageSendResultType(QualType ReceiverType,
+QualType Sema::getMessageSendResultType(const Expr *Receiver,
+QualType ReceiverType,
 ObjCMethodDecl *Method,
 bool isClassMessage,
 bool isSuperMessage) {
@@ -1357,8 +1358,33 @@ QualType Sema::getMessageSendResultType(
  isSuperMessage);
 
   // If this is a class message, ignore the nullability of the receiver.
-  if (isClassMessage)
+  if (isClassMessage) {
+// In a class method, class messages to 'self' that return instancetype can
+// be typed as the current class.  We can safely do this in ARC because 
self
+// can't be reassigned, and we do it unsafely outside of ARC because in
+// practice people never reassign self in class methods and there's some
+// virtue in not being aggressively pedantic.
+if (Receiver && Receiver->isObjCSelfExpr()) {
+  assert(ReceiverType->isObjCClassType() && "expected a Class self");
+  

[PATCH] D55949: Correctly handle function pointers returning a type marked nodiscard

2018-12-20 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington accepted this revision.
erik.pilkington added a comment.
This revision is now accepted and ready to land.

LGTM!




Comment at: lib/AST/Expr.cpp:2281-2286
+  // If there is no FunctionDecl for the call, check the return type of the
+  // callee to see if it was declared with the WarnUnusedResult attribute.
+  if (!Func && !HasWarnUnusedResultAttr) {
+if (const TagDecl *TD = CE->getCallReturnType(Ctx)->getAsTagDecl())
+  HasWarnUnusedResultAttr = TD->hasAttr();
+  }

This duplicates some logic from FunctionDecl::hasUnusedResultAttr(), maybe we 
should move that member function to the CallExpr?



Comment at: test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp:51
+
+  one(); // expected-warning {{ignoring return value of function declared with 
'nodiscard' attribute}}
+  two(); // expected-warning {{ignoring return value of function declared with 
'nodiscard' attribute}}

This diagnostic should also probably be improved at some point, the function 
wasn't declared 'nodiscard', the type was.


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

https://reviews.llvm.org/D55949



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


r349840 - cmake: Remove uses of add_llvm_loadable_module macro

2018-12-20 Thread Tom Stellard via cfe-commits
Author: tstellar
Date: Thu Dec 20 14:04:36 2018
New Revision: 349840

URL: http://llvm.org/viewvc/llvm-project?rev=349840=rev
Log:
cmake: Remove uses of add_llvm_loadable_module macro

This was removed from llvm in r349839.

Modified:
cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt
cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt
cfe/trunk/examples/analyzer-plugin/CMakeLists.txt

Modified: cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt?rev=349840=349839=349840=diff
==
--- cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt (original)
+++ cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt Thu Dec 20 14:04:36 2018
@@ -1,4 +1,4 @@
-add_llvm_loadable_module(AnnotateFunctions AnnotateFunctions.cpp PLUGIN_TOOL 
clang)
+add_llvm_library(AnnotateFunctions MODULE AnnotateFunctions.cpp PLUGIN_TOOL 
clang)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
   target_link_libraries(AnnotateFunctions PRIVATE

Modified: cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt?rev=349840=349839=349840=diff
==
--- cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt (original)
+++ cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt Thu Dec 20 14:04:36 
2018
@@ -9,7 +9,7 @@ if( NOT MSVC ) # MSVC mangles symbols di
   endif()
 endif()
 
-add_llvm_loadable_module(PrintFunctionNames PrintFunctionNames.cpp PLUGIN_TOOL 
clang)
+add_llvm_library(PrintFunctionNames MODULE PrintFunctionNames.cpp PLUGIN_TOOL 
clang)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
   target_link_libraries(PrintFunctionNames PRIVATE

Modified: cfe/trunk/examples/analyzer-plugin/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/analyzer-plugin/CMakeLists.txt?rev=349840=349839=349840=diff
==
--- cfe/trunk/examples/analyzer-plugin/CMakeLists.txt (original)
+++ cfe/trunk/examples/analyzer-plugin/CMakeLists.txt Thu Dec 20 14:04:36 2018
@@ -1,5 +1,5 @@
 set(LLVM_EXPORTED_SYMBOL_FILE 
${CMAKE_CURRENT_SOURCE_DIR}/SampleAnalyzerPlugin.exports)
-add_llvm_loadable_module(SampleAnalyzerPlugin MainCallChecker.cpp PLUGIN_TOOL 
clang)
+add_llvm_library(SampleAnalyzerPlugin MODULE MainCallChecker.cpp PLUGIN_TOOL 
clang)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
   target_link_libraries(SampleAnalyzerPlugin PRIVATE


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


[PATCH] D55823: [analyzer] Fix backward compatibility issue after D53280 'Emit an error for invalid -analyzer-config inputs'

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

Np! We really appreciate your work!


Repository:
  rL LLVM

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

https://reviews.llvm.org/D55823



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


[PATCH] D55955: Properly diagnose [[nodiscard]] on the body of a range-based for loop

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



Comment at: lib/Sema/SemaStmt.cpp:2846
 diag::warn_empty_range_based_for_body);
+  DiagnoseUnusedExprResult(B);
 

rsmith wrote:
> While this looks correct per the current approach to this function, we really 
> shouldn't be duplicating calls to this everywhere. Can we move all the calls 
> to a single call in `ActOnFinishFullStmt`?
Looks like that's not actually called from almost anywhere, but checking from 
`ActOnFinishFullExpr` in the case where `DiscardedValue` is `true` seems 
appropriate.


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

https://reviews.llvm.org/D55955



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


[PATCH] D55955: Properly diagnose [[nodiscard]] on the body of a range-based for loop

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



Comment at: lib/Sema/SemaStmt.cpp:2846
 diag::warn_empty_range_based_for_body);
+  DiagnoseUnusedExprResult(B);
 

While this looks correct per the current approach to this function, we really 
shouldn't be duplicating calls to this everywhere. Can we move all the calls to 
a single call in `ActOnFinishFullStmt`?


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

https://reviews.llvm.org/D55955



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


[PATCH] D55931: [gn build] Add build file for clang/lib/CodeGen and llvm/lib/ProfileData/Coverage

2018-12-20 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349834: [gn build] Add build file for clang/lib/CodeGen and… 
(authored by nico, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D55931?vs=179075=179153#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55931

Files:
  llvm/trunk/utils/gn/secondary/BUILD.gn
  llvm/trunk/utils/gn/secondary/clang/lib/CodeGen/BUILD.gn
  llvm/trunk/utils/gn/secondary/llvm/lib/ProfileData/Coverage/BUILD.gn

Index: llvm/trunk/utils/gn/secondary/clang/lib/CodeGen/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/clang/lib/CodeGen/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/clang/lib/CodeGen/BUILD.gn
@@ -0,0 +1,88 @@
+static_library("CodeGen") {
+  output_name = "clangCodeGen"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/lib/AST",
+"//clang/lib/Analysis",
+"//clang/lib/Basic",
+"//clang/lib/Frontend",
+"//clang/lib/Lex",
+"//llvm/lib/Analysis",
+"//llvm/lib/Bitcode/Reader",
+"//llvm/lib/IR",
+"//llvm/lib/IRReader",
+"//llvm/lib/LTO",
+"//llvm/lib/Linker",
+"//llvm/lib/MC",
+"//llvm/lib/Object",
+"//llvm/lib/Passes",
+"//llvm/lib/ProfileData",
+"//llvm/lib/ProfileData/Coverage",
+"//llvm/lib/Support",
+"//llvm/lib/Target",
+"//llvm/lib/Transforms/Coroutines",
+"//llvm/lib/Transforms/IPO",
+"//llvm/lib/Transforms/InstCombine",
+"//llvm/lib/Transforms/Instrumentation",
+"//llvm/lib/Transforms/ObjCARC",
+"//llvm/lib/Transforms/Scalar",
+"//llvm/lib/Transforms/Utils",
+  ]
+  sources = [
+"BackendUtil.cpp",
+"CGAtomic.cpp",
+"CGBlocks.cpp",
+"CGBuiltin.cpp",
+"CGCUDANV.cpp",
+"CGCUDARuntime.cpp",
+"CGCXX.cpp",
+"CGCXXABI.cpp",
+"CGCall.cpp",
+"CGClass.cpp",
+"CGCleanup.cpp",
+"CGCoroutine.cpp",
+"CGDebugInfo.cpp",
+"CGDecl.cpp",
+"CGDeclCXX.cpp",
+"CGException.cpp",
+"CGExpr.cpp",
+"CGExprAgg.cpp",
+"CGExprCXX.cpp",
+"CGExprComplex.cpp",
+"CGExprConstant.cpp",
+"CGExprScalar.cpp",
+"CGGPUBuiltin.cpp",
+"CGLoopInfo.cpp",
+"CGNonTrivialStruct.cpp",
+"CGObjC.cpp",
+"CGObjCGNU.cpp",
+"CGObjCMac.cpp",
+"CGObjCRuntime.cpp",
+"CGOpenCLRuntime.cpp",
+"CGOpenMPRuntime.cpp",
+"CGOpenMPRuntimeNVPTX.cpp",
+"CGRecordLayoutBuilder.cpp",
+"CGStmt.cpp",
+"CGStmtOpenMP.cpp",
+"CGVTT.cpp",
+"CGVTables.cpp",
+"CodeGenABITypes.cpp",
+"CodeGenAction.cpp",
+"CodeGenFunction.cpp",
+"CodeGenModule.cpp",
+"CodeGenPGO.cpp",
+"CodeGenTBAA.cpp",
+"CodeGenTypes.cpp",
+"ConstantInitBuilder.cpp",
+"CoverageMappingGen.cpp",
+"ItaniumCXXABI.cpp",
+"MacroPPCallbacks.cpp",
+"MicrosoftCXXABI.cpp",
+"ModuleBuilder.cpp",
+"ObjectFilePCHContainerOperations.cpp",
+"SanitizerMetadata.cpp",
+"SwiftCallingConv.cpp",
+"TargetInfo.cpp",
+"VarBypassDetector.cpp",
+  ]
+}
Index: llvm/trunk/utils/gn/secondary/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/BUILD.gn
@@ -1,5 +1,6 @@
 group("default") {
   deps = [
+"//clang/lib/CodeGen",
 "//clang/lib/Driver",
 "//clang/lib/Frontend",
 "//clang/lib/Frontend/Rewrite",
Index: llvm/trunk/utils/gn/secondary/llvm/lib/ProfileData/Coverage/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/llvm/lib/ProfileData/Coverage/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/llvm/lib/ProfileData/Coverage/BUILD.gn
@@ -0,0 +1,14 @@
+static_library("Coverage") {
+  output_name = "LLVMCoverage"
+  deps = [
+"//llvm/lib/IR",
+"//llvm/lib/Object",
+"//llvm/lib/ProfileData",
+"//llvm/lib/Support",
+  ]
+  sources = [
+"CoverageMapping.cpp",
+"CoverageMappingReader.cpp",
+"CoverageMappingWriter.cpp",
+  ]
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r349835 - [driver] [analyzer] Fix redundant test output.

2018-12-20 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Thu Dec 20 13:56:49 2018
New Revision: 349835

URL: http://llvm.org/viewvc/llvm-project?rev=349835=rev
Log:
[driver] [analyzer] Fix redundant test output.

The -c flag causes a .o file to appear every time we run a test.
Remove it.

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

rdar://problem/46504165

Modified:
cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
cfe/trunk/test/Analysis/invalid-analyzer-config-value.c

Modified: cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c?rev=349835=349834=349835=diff
==
--- cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c (original)
+++ cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c Thu Dec 20 
13:56:49 2018
@@ -72,7 +72,8 @@
 
 // Test the driver properly using "analyzer-config-compatibility-mode=true",
 // even if -analyze isn't specified.
-// RUN: %clang -c -Xclang -analyzer-config -Xclang remember=TheVasa %s
+// RUN: %clang -fsyntax-only -Xclang -analyzer-config\
+// RUN:  -Xclang remember=TheVasa %s
 
 // expected-no-diagnostics
 

Modified: cfe/trunk/test/Analysis/invalid-analyzer-config-value.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/invalid-analyzer-config-value.c?rev=349835=349834=349835=diff
==
--- cfe/trunk/test/Analysis/invalid-analyzer-config-value.c (original)
+++ cfe/trunk/test/Analysis/invalid-analyzer-config-value.c Thu Dec 20 13:56:49 
2018
@@ -68,7 +68,8 @@
 
 // Test the driver properly using "analyzer-config-compatibility-mode=true",
 // even if -analyze isn't specified.
-// RUN: %clang -c -Xclang -analyzer-config -Xclang remember=TheVasa %s
+// RUN: %clang -fsyntax-only -Xclang -analyzer-config\
+// RUN:  -Xclang remember=TheVasa %s
 
 // expected-no-diagnostics
 


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


[PATCH] D55930: [gn build] Add build files for clang/lib/{Frontend, Frontend/Rewrite, Serialization}

2018-12-20 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349833: [gn build] Add build files for 
clang/lib/{Frontend,Frontend/Rewrite… (authored by nico, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55930?vs=179071=179151#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55930

Files:
  llvm/trunk/utils/gn/secondary/BUILD.gn
  llvm/trunk/utils/gn/secondary/clang/include/clang/Serialization/BUILD.gn
  llvm/trunk/utils/gn/secondary/clang/lib/Frontend/BUILD.gn
  llvm/trunk/utils/gn/secondary/clang/lib/Frontend/Rewrite/BUILD.gn
  llvm/trunk/utils/gn/secondary/clang/lib/Serialization/BUILD.gn

Index: llvm/trunk/utils/gn/secondary/clang/lib/Frontend/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/clang/lib/Frontend/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/clang/lib/Frontend/BUILD.gn
@@ -0,0 +1,54 @@
+static_library("Frontend") {
+  output_name = "clangFrontend"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/include/clang/Config",
+"//clang/lib/AST",
+"//clang/lib/Basic",
+"//clang/lib/Driver",
+"//clang/lib/Edit",
+"//clang/lib/Lex",
+"//clang/lib/Parse",
+"//clang/lib/Sema",
+"//clang/lib/Serialization",
+"//llvm/include/llvm/Config:llvm-config",
+"//llvm/lib/Bitcode/Reader",
+"//llvm/lib/Option",
+"//llvm/lib/ProfileData",
+"//llvm/lib/Support",
+  ]
+  sources = [
+"ASTConsumers.cpp",
+"ASTMerge.cpp",
+"ASTUnit.cpp",
+"ChainedDiagnosticConsumer.cpp",
+"ChainedIncludesSource.cpp",
+"CompilerInstance.cpp",
+"CompilerInvocation.cpp",
+"CreateInvocationFromCommandLine.cpp",
+"DependencyFile.cpp",
+"DependencyGraph.cpp",
+"DiagnosticRenderer.cpp",
+"FrontendAction.cpp",
+"FrontendActions.cpp",
+"FrontendOptions.cpp",
+"FrontendTiming.cpp",
+"HeaderIncludeGen.cpp",
+"InitHeaderSearch.cpp",
+"InitPreprocessor.cpp",
+"LangStandards.cpp",
+"LayoutOverrideSource.cpp",
+"LogDiagnosticPrinter.cpp",
+"ModuleDependencyCollector.cpp",
+"MultiplexConsumer.cpp",
+"PrecompiledPreamble.cpp",
+"PrintPreprocessedOutput.cpp",
+"SerializedDiagnosticPrinter.cpp",
+"SerializedDiagnosticReader.cpp",
+"TestModuleFileExtension.cpp",
+"TextDiagnostic.cpp",
+"TextDiagnosticBuffer.cpp",
+"TextDiagnosticPrinter.cpp",
+"VerifyDiagnosticConsumer.cpp",
+  ]
+}
Index: llvm/trunk/utils/gn/secondary/clang/lib/Frontend/Rewrite/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/clang/lib/Frontend/Rewrite/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/clang/lib/Frontend/Rewrite/BUILD.gn
@@ -0,0 +1,24 @@
+static_library("Rewrite") {
+  output_name = "clangRewriteFrontend"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/lib/AST",
+"//clang/lib/Basic",
+"//clang/lib/Edit",
+"//clang/lib/Frontend",
+"//clang/lib/Lex",
+"//clang/lib/Rewrite",
+"//clang/lib/Serialization",
+"//llvm/lib/Support",
+  ]
+  sources = [
+"FixItRewriter.cpp",
+"FrontendActions.cpp",
+"HTMLPrint.cpp",
+"InclusionRewriter.cpp",
+"RewriteMacros.cpp",
+"RewriteModernObjC.cpp",
+"RewriteObjC.cpp",
+"RewriteTest.cpp",
+  ]
+}
Index: llvm/trunk/utils/gn/secondary/clang/lib/Serialization/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/clang/lib/Serialization/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/clang/lib/Serialization/BUILD.gn
@@ -0,0 +1,31 @@
+static_library("Serialization") {
+  output_name = "clangSerialization"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/include/clang/Serialization:AttrPCHRead",
+"//clang/include/clang/Serialization:AttrPCHWrite",
+"//clang/lib/AST",
+"//clang/lib/Basic",
+"//clang/lib/Lex",
+"//clang/lib/Sema",
+"//llvm/lib/Bitcode/Reader",
+"//llvm/lib/Support",
+  ]
+  sources = [
+"ASTCommon.cpp",
+"ASTCommon.h",
+"ASTReader.cpp",
+"ASTReaderDecl.cpp",
+"ASTReaderInternals.h",
+"ASTReaderStmt.cpp",
+"ASTWriter.cpp",
+"ASTWriterDecl.cpp",
+"ASTWriterStmt.cpp",
+"GeneratePCH.cpp",
+"GlobalModuleIndex.cpp",
+"Module.cpp",
+"ModuleFileExtension.cpp",
+"ModuleManager.cpp",
+"PCHContainerOperations.cpp",
+  ]
+}
Index: llvm/trunk/utils/gn/secondary/clang/include/clang/Serialization/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/clang/include/clang/Serialization/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/clang/include/clang/Serialization/BUILD.gn
@@ -0,0 +1,19 @@
+import("//clang/utils/TableGen/clang_tablegen.gni")
+

[PATCH] D55927: [gn build] Add build file for clang/lib/Driver

2018-12-20 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349832: [gn build] Add build file for clang/lib/Driver 
(authored by nico, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55927?vs=179067=179150#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55927

Files:
  llvm/trunk/utils/gn/secondary/BUILD.gn
  llvm/trunk/utils/gn/secondary/clang/include/clang/Driver/BUILD.gn
  
llvm/trunk/utils/gn/secondary/clang/include/clang/StaticAnalyzer/Checkers/BUILD.gn
  llvm/trunk/utils/gn/secondary/clang/lib/Driver/BUILD.gn

Index: llvm/trunk/utils/gn/secondary/clang/lib/Driver/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/clang/lib/Driver/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/clang/lib/Driver/BUILD.gn
@@ -0,0 +1,88 @@
+static_library("Driver") {
+  output_name = "clangDriver"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  include_dirs = [ "." ]
+  deps = [
+"//clang/include/clang/Config",
+
+# Driver doesn't depend on StaticAnalyzer and the other way round, but
+# as of clang r311958 Driver does depend on StaticAnalyzer/Checkers's
+# tablegen'd Checkers.inc.  The CMake build runs all clang tablegen steps
+# before all lib compilations via the clang-tablegen-targets target; the
+# GN build has this dependency instead.
+# FIXME: Move Checkers.td somewhere else to clean up this layering mess.
+# See the review thread of r311958 for details.
+"//clang/include/clang/StaticAnalyzer/Checkers",
+"//clang/lib/Basic",
+"//llvm/include/llvm/Config:llvm-config",
+"//llvm/lib/BinaryFormat",
+"//llvm/lib/Option",
+"//llvm/lib/Support",
+  ]
+  public_deps = [
+# public_dep because public header Options.h includes generated Options.inc.
+"//clang/include/clang/Driver:Options",
+  ]
+  if (host_os == "win") {
+# MSVCToolChain.cpp uses version.dll.
+libs = [ "version.lib" ]
+  }
+  sources = [
+"Action.cpp",
+"Compilation.cpp",
+"DarwinSDKInfo.cpp",
+"Distro.cpp",
+"Driver.cpp",
+"DriverOptions.cpp",
+"Job.cpp",
+"Multilib.cpp",
+"Phases.cpp",
+"SanitizerArgs.cpp",
+"Tool.cpp",
+"ToolChain.cpp",
+"ToolChains/AMDGPU.cpp",
+"ToolChains/AVR.cpp",
+"ToolChains/Ananas.cpp",
+"ToolChains/Arch/AArch64.cpp",
+"ToolChains/Arch/ARM.cpp",
+"ToolChains/Arch/Mips.cpp",
+"ToolChains/Arch/PPC.cpp",
+"ToolChains/Arch/RISCV.cpp",
+"ToolChains/Arch/Sparc.cpp",
+"ToolChains/Arch/SystemZ.cpp",
+"ToolChains/Arch/X86.cpp",
+"ToolChains/BareMetal.cpp",
+"ToolChains/Clang.cpp",
+"ToolChains/CloudABI.cpp",
+"ToolChains/CommonArgs.cpp",
+"ToolChains/Contiki.cpp",
+"ToolChains/CrossWindows.cpp",
+"ToolChains/Cuda.cpp",
+"ToolChains/Darwin.cpp",
+"ToolChains/DragonFly.cpp",
+"ToolChains/FreeBSD.cpp",
+"ToolChains/Fuchsia.cpp",
+"ToolChains/Gnu.cpp",
+"ToolChains/HIP.cpp",
+"ToolChains/Haiku.cpp",
+"ToolChains/Hexagon.cpp",
+"ToolChains/Hurd.cpp",
+"ToolChains/Linux.cpp",
+"ToolChains/MSVC.cpp",
+"ToolChains/MinGW.cpp",
+"ToolChains/Minix.cpp",
+"ToolChains/MipsLinux.cpp",
+"ToolChains/Myriad.cpp",
+"ToolChains/NaCl.cpp",
+"ToolChains/NetBSD.cpp",
+"ToolChains/OpenBSD.cpp",
+"ToolChains/PS4CPU.cpp",
+"ToolChains/RISCVToolchain.cpp",
+"ToolChains/Solaris.cpp",
+"ToolChains/TCE.cpp",
+"ToolChains/WebAssembly.cpp",
+"ToolChains/XCore.cpp",
+"Types.cpp",
+"XRayArgs.cpp",
+  ]
+}
Index: llvm/trunk/utils/gn/secondary/clang/include/clang/StaticAnalyzer/Checkers/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/clang/include/clang/StaticAnalyzer/Checkers/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/clang/include/clang/StaticAnalyzer/Checkers/BUILD.gn
@@ -0,0 +1,5 @@
+import("//clang/utils/TableGen/clang_tablegen.gni")
+
+clang_tablegen("Checkers") {
+  args = [ "-gen-clang-sa-checkers" ]
+}
Index: llvm/trunk/utils/gn/secondary/clang/include/clang/Driver/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/clang/include/clang/Driver/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/clang/include/clang/Driver/BUILD.gn
@@ -0,0 +1,5 @@
+import("//llvm/utils/TableGen/tablegen.gni")
+
+tablegen("Options") {
+  args = [ "-gen-opt-parser-defs" ]
+}
Index: llvm/trunk/utils/gn/secondary/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/BUILD.gn
@@ -1,5 +1,6 @@
 group("default") {
   deps = [
+"//clang/lib/Driver",
 "//clang/lib/Parse",
 "//clang/tools/clang-format",
 "//lld/test",

[PATCH] D55925: [gn build] Add build file for clang/lib/Parse

2018-12-20 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349831: [gn build] Add build file for clang/lib/Parse 
(authored by nico, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55925?vs=179057=179149#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55925

Files:
  llvm/trunk/utils/gn/secondary/BUILD.gn
  llvm/trunk/utils/gn/secondary/clang/include/clang/Parse/BUILD.gn
  llvm/trunk/utils/gn/secondary/clang/lib/Parse/BUILD.gn


Index: llvm/trunk/utils/gn/secondary/clang/lib/Parse/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/clang/lib/Parse/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/clang/lib/Parse/BUILD.gn
@@ -0,0 +1,32 @@
+static_library("Parse") {
+  output_name = "clangParse"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/include/clang/Parse:AttrParserStringSwitches",
+"//clang/include/clang/Parse:AttrSubMatchRulesParserStringSwitches",
+"//clang/lib/AST",
+"//clang/lib/Basic",
+"//clang/lib/Lex",
+"//clang/lib/Sema",
+"//llvm/lib/MC",
+"//llvm/lib/MC/MCParser",
+"//llvm/lib/Support",
+  ]
+  sources = [
+"ParseAST.cpp",
+"ParseCXXInlineMethods.cpp",
+"ParseDecl.cpp",
+"ParseDeclCXX.cpp",
+"ParseExpr.cpp",
+"ParseExprCXX.cpp",
+"ParseInit.cpp",
+"ParseObjc.cpp",
+"ParseOpenMP.cpp",
+"ParsePragma.cpp",
+"ParseStmt.cpp",
+"ParseStmtAsm.cpp",
+"ParseTemplate.cpp",
+"ParseTentative.cpp",
+"Parser.cpp",
+  ]
+}
Index: llvm/trunk/utils/gn/secondary/clang/include/clang/Parse/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/clang/include/clang/Parse/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/clang/include/clang/Parse/BUILD.gn
@@ -0,0 +1,19 @@
+import("//clang/utils/TableGen/clang_tablegen.gni")
+
+clang_tablegen("AttrParserStringSwitches") {
+  args = [
+"-gen-clang-attr-parser-string-switches",
+"-I",
+rebase_path("../..", root_out_dir),
+  ]
+  td_file = "../Basic/Attr.td"
+}
+
+clang_tablegen("AttrSubMatchRulesParserStringSwitches") {
+  args = [
+"-gen-clang-attr-subject-match-rules-parser-string-switches",
+"-I",
+rebase_path("../..", root_out_dir),
+  ]
+  td_file = "../Basic/Attr.td"
+}
Index: llvm/trunk/utils/gn/secondary/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/BUILD.gn
@@ -1,5 +1,6 @@
 group("default") {
   deps = [
+"//clang/lib/Parse",
 "//clang/tools/clang-format",
 "//lld/test",
 "//llvm/tools/llvm-undname",


Index: llvm/trunk/utils/gn/secondary/clang/lib/Parse/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/clang/lib/Parse/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/clang/lib/Parse/BUILD.gn
@@ -0,0 +1,32 @@
+static_library("Parse") {
+  output_name = "clangParse"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/include/clang/Parse:AttrParserStringSwitches",
+"//clang/include/clang/Parse:AttrSubMatchRulesParserStringSwitches",
+"//clang/lib/AST",
+"//clang/lib/Basic",
+"//clang/lib/Lex",
+"//clang/lib/Sema",
+"//llvm/lib/MC",
+"//llvm/lib/MC/MCParser",
+"//llvm/lib/Support",
+  ]
+  sources = [
+"ParseAST.cpp",
+"ParseCXXInlineMethods.cpp",
+"ParseDecl.cpp",
+"ParseDeclCXX.cpp",
+"ParseExpr.cpp",
+"ParseExprCXX.cpp",
+"ParseInit.cpp",
+"ParseObjc.cpp",
+"ParseOpenMP.cpp",
+"ParsePragma.cpp",
+"ParseStmt.cpp",
+"ParseStmtAsm.cpp",
+"ParseTemplate.cpp",
+"ParseTentative.cpp",
+"Parser.cpp",
+  ]
+}
Index: llvm/trunk/utils/gn/secondary/clang/include/clang/Parse/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/clang/include/clang/Parse/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/clang/include/clang/Parse/BUILD.gn
@@ -0,0 +1,19 @@
+import("//clang/utils/TableGen/clang_tablegen.gni")
+
+clang_tablegen("AttrParserStringSwitches") {
+  args = [
+"-gen-clang-attr-parser-string-switches",
+"-I",
+rebase_path("../..", root_out_dir),
+  ]
+  td_file = "../Basic/Attr.td"
+}
+
+clang_tablegen("AttrSubMatchRulesParserStringSwitches") {
+  args = [
+"-gen-clang-attr-subject-match-rules-parser-string-switches",
+"-I",
+rebase_path("../..", root_out_dir),
+  ]
+  td_file = "../Basic/Attr.td"
+}
Index: llvm/trunk/utils/gn/secondary/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/BUILD.gn
@@ -1,5 +1,6 @@
 group("default") {
   deps = [
+"//clang/lib/Parse",
 

[PATCH] D55924: [gn build] Add build files for clang-format and lib/{Format, Rewrite, Tooling/Core, Tooling/Inclusions}

2018-12-20 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349830: [gn build] Add build files for clang-format and 
lib/{Format,Rewrite… (authored by nico, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55924?vs=179056=179148#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55924

Files:
  llvm/trunk/utils/gn/secondary/BUILD.gn
  llvm/trunk/utils/gn/secondary/clang/lib/Format/BUILD.gn
  llvm/trunk/utils/gn/secondary/clang/lib/Rewrite/BUILD.gn
  llvm/trunk/utils/gn/secondary/clang/lib/Tooling/Core/BUILD.gn
  llvm/trunk/utils/gn/secondary/clang/lib/Tooling/Inclusions/BUILD.gn
  llvm/trunk/utils/gn/secondary/clang/tools/clang-format/BUILD.gn

Index: llvm/trunk/utils/gn/secondary/clang/lib/Tooling/Core/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/clang/lib/Tooling/Core/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/clang/lib/Tooling/Core/BUILD.gn
@@ -0,0 +1,16 @@
+static_library("Core") {
+  output_name = "clangToolingCore"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/lib/AST",
+"//clang/lib/Basic",
+"//clang/lib/Lex",
+"//clang/lib/Rewrite",
+"//llvm/lib/Support",
+  ]
+  sources = [
+"Diagnostic.cpp",
+"Lookup.cpp",
+"Replacement.cpp",
+  ]
+}
Index: llvm/trunk/utils/gn/secondary/clang/lib/Tooling/Inclusions/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/clang/lib/Tooling/Inclusions/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/clang/lib/Tooling/Inclusions/BUILD.gn
@@ -0,0 +1,15 @@
+static_library("Inclusions") {
+  output_name = "clangToolingInclusions"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/lib/Basic",
+"//clang/lib/Lex",
+"//clang/lib/Rewrite",
+"//clang/lib/Tooling/Core",
+"//llvm/lib/Support",
+  ]
+  sources = [
+"HeaderIncludes.cpp",
+"IncludeStyle.cpp",
+  ]
+}
Index: llvm/trunk/utils/gn/secondary/clang/lib/Format/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/clang/lib/Format/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/clang/lib/Format/BUILD.gn
@@ -0,0 +1,27 @@
+static_library("Format") {
+  output_name = "clangFormat"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/lib/Basic",
+"//clang/lib/Lex",
+"//clang/lib/Tooling/Core",
+"//clang/lib/Tooling/Inclusions",
+"//llvm/lib/Support",
+  ]
+  sources = [
+"AffectedRangeManager.cpp",
+"BreakableToken.cpp",
+"ContinuationIndenter.cpp",
+"Format.cpp",
+"FormatToken.cpp",
+"FormatTokenLexer.cpp",
+"NamespaceEndCommentsFixer.cpp",
+"SortJavaScriptImports.cpp",
+"TokenAnalyzer.cpp",
+"TokenAnnotator.cpp",
+"UnwrappedLineFormatter.cpp",
+"UnwrappedLineParser.cpp",
+"UsingDeclarationsSorter.cpp",
+"WhitespaceManager.cpp",
+  ]
+}
Index: llvm/trunk/utils/gn/secondary/clang/lib/Rewrite/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/clang/lib/Rewrite/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/clang/lib/Rewrite/BUILD.gn
@@ -0,0 +1,16 @@
+static_library("Rewrite") {
+  output_name = "clangRewrite"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/lib/Basic",
+"//clang/lib/Lex",
+"//llvm/lib/Support",
+  ]
+  sources = [
+"DeltaTree.cpp",
+"HTMLRewrite.cpp",
+"RewriteRope.cpp",
+"Rewriter.cpp",
+"TokenRewriter.cpp",
+  ]
+}
Index: llvm/trunk/utils/gn/secondary/clang/tools/clang-format/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/clang/tools/clang-format/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/clang/tools/clang-format/BUILD.gn
@@ -0,0 +1,13 @@
+executable("clang-format") {
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/lib/Basic",
+"//clang/lib/Format",
+"//clang/lib/Rewrite",
+"//clang/lib/Tooling/Core",
+"//llvm/lib/Support",
+  ]
+  sources = [
+"ClangFormat.cpp",
+  ]
+}
Index: llvm/trunk/utils/gn/secondary/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/BUILD.gn
@@ -1,11 +1,6 @@
 group("default") {
   deps = [
-"//clang/lib/AST",
-"//clang/lib/Analysis",
-"//clang/lib/Basic",
-"//clang/lib/Edit",
-"//clang/lib/Lex",
-"//clang/lib/Sema",
+"//clang/tools/clang-format",
 "//lld/test",
 "//llvm/tools/llvm-undname",
   ]
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55955: Properly diagnose [[nodiscard]] on the body of a range-based for loop

2018-12-20 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: rsmith, Quuxplusone, erik.pilkington.

If the range-based for loop function body is not a compound statement, we would 
fail to diagnose discarded results from the statement. This only impacted 
range-based for loops because other kinds of for loops already manually check 
the body for unused expression results.

This addresses PR39837.


https://reviews.llvm.org/D55955

Files:
  lib/Sema/SemaStmt.cpp
  test/SemaCXX/warn-unused-result.cpp


Index: test/SemaCXX/warn-unused-result.cpp
===
--- test/SemaCXX/warn-unused-result.cpp
+++ test/SemaCXX/warn-unused-result.cpp
@@ -206,3 +206,13 @@
   (void)++p;
 }
 } // namespace
+
+namespace PR39837 {
+[[clang::warn_unused_result]] int f(int);
+
+void g() {
+  int a[2];
+  for (int b : a)
+f(b); // expected-warning {{ignoring return value}}
+}
+} // namespace PR39837
Index: lib/Sema/SemaStmt.cpp
===
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -2843,6 +2843,7 @@
 
   DiagnoseEmptyStmtBody(ForStmt->getRParenLoc(), B,
 diag::warn_empty_range_based_for_body);
+  DiagnoseUnusedExprResult(B);
 
   DiagnoseForRangeVariableCopies(*this, ForStmt);
 


Index: test/SemaCXX/warn-unused-result.cpp
===
--- test/SemaCXX/warn-unused-result.cpp
+++ test/SemaCXX/warn-unused-result.cpp
@@ -206,3 +206,13 @@
   (void)++p;
 }
 } // namespace
+
+namespace PR39837 {
+[[clang::warn_unused_result]] int f(int);
+
+void g() {
+  int a[2];
+  for (int b : a)
+f(b); // expected-warning {{ignoring return value}}
+}
+} // namespace PR39837
Index: lib/Sema/SemaStmt.cpp
===
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -2843,6 +2843,7 @@
 
   DiagnoseEmptyStmtBody(ForStmt->getRParenLoc(), B,
 diag::warn_empty_range_based_for_body);
+  DiagnoseUnusedExprResult(B);
 
   DiagnoseForRangeVariableCopies(*this, ForStmt);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r349828 - [driver] [analyzer] Fix buildbots after r349824.

2018-12-20 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Thu Dec 20 13:45:33 2018
New Revision: 349828

URL: http://llvm.org/viewvc/llvm-project?rev=349828=rev
Log:
[driver] [analyzer] Fix buildbots after r349824.

Buildbots can't find the linker, which we don't really need in our tests.

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

rdar://problem/46504165

Modified:
cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
cfe/trunk/test/Analysis/invalid-analyzer-config-value.c

Modified: cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c?rev=349828=349827=349828=diff
==
--- cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c (original)
+++ cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c Thu Dec 20 
13:45:33 2018
@@ -72,7 +72,7 @@
 
 // Test the driver properly using "analyzer-config-compatibility-mode=true",
 // even if -analyze isn't specified.
-// RUN: %clang -Xclang -analyzer-config -Xclang remember=TheVasa %s
+// RUN: %clang -c -Xclang -analyzer-config -Xclang remember=TheVasa %s
 
 // expected-no-diagnostics
 

Modified: cfe/trunk/test/Analysis/invalid-analyzer-config-value.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/invalid-analyzer-config-value.c?rev=349828=349827=349828=diff
==
--- cfe/trunk/test/Analysis/invalid-analyzer-config-value.c (original)
+++ cfe/trunk/test/Analysis/invalid-analyzer-config-value.c Thu Dec 20 13:45:33 
2018
@@ -68,7 +68,7 @@
 
 // Test the driver properly using "analyzer-config-compatibility-mode=true",
 // even if -analyze isn't specified.
-// RUN: %clang -Xclang -analyzer-config -Xclang remember=TheVasa %s
+// RUN: %clang -c -Xclang -analyzer-config -Xclang remember=TheVasa %s
 
 // expected-no-diagnostics
 


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


[PATCH] D55710: add pragmas to control Software Pipelining optimisation

2018-12-20 Thread Alexey Lapshin via Phabricator via cfe-commits
alexey.lapshin updated this revision to Diff 179145.
alexey.lapshin added a comment.

update documentation section.


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

https://reviews.llvm.org/D55710

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticParseKinds.td
  lib/CodeGen/CGLoopInfo.cpp
  lib/CodeGen/CGLoopInfo.h
  lib/Parse/ParsePragma.cpp
  lib/Sema/SemaStmtAttr.cpp
  test/CodeGenCXX/pragma-pipeline.cpp
  test/Parser/pragma-loop.cpp
  test/Parser/pragma-pipeline.cpp
  test/Parser/pragma-unroll-and-jam.cpp

Index: test/Parser/pragma-unroll-and-jam.cpp
===
--- test/Parser/pragma-unroll-and-jam.cpp
+++ test/Parser/pragma-unroll-and-jam.cpp
@@ -67,7 +67,7 @@
   }
 
 // pragma clang unroll_and_jam is disabled for the moment
-/* expected-error {{invalid option 'unroll_and_jam'; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, or distribute}} */ #pragma clang loop unroll_and_jam(4)
+/* expected-error {{invalid option 'unroll_and_jam'; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, pipeline, pipeline_initiation_interval or distribute}} */ #pragma clang loop unroll_and_jam(4)
   for (int i = 0; i < Length; i++) {
 for (int j = 0; j < Length; j++) {
   List[i * Length + j] = Value;
Index: test/Parser/pragma-pipeline.cpp
===
--- /dev/null
+++ test/Parser/pragma-pipeline.cpp
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -std=c++11 -verify %s
+
+// Note that this puts the expected lines before the directives to work around
+// limitations in the -verify mode.
+
+void test(int *List, int Length, int Value) {
+  int i = 0;
+
+#pragma clang loop pipeline(disable)
+  for (int i = 0; i < Length; i++) {
+List[i] = Value;
+  }
+
+#pragma clang loop pipeline_initiation_interval(10)
+  for (int i = 0; i < Length; i++) {
+List[i] = Value;
+  }
+
+/* expected-error {{expected ')'}} */ #pragma clang loop pipeline(disable
+/* expected-error {{invalid argument; expected 'disable'}} */ #pragma clang loop pipeline(enable)
+/* expected-error {{invalid argument; expected 'disable'}} */ #pragma clang loop pipeline(error)
+/* expected-error {{expected '('}} */ #pragma clang loop pipeline disable
+/* expected-error {{missing argument; expected an integer value}} */ #pragma clang loop pipeline_initiation_interval()
+/* expected-error {{use of undeclared identifier 'error'}} */ #pragma clang loop pipeline_initiation_interval(error)
+/* expected-error {{expected '('}} */ #pragma clang loop pipeline_initiation_interval 1 2
+/* expected-error {{expected ')'}} */ #pragma clang loop pipeline_initiation_interval(1
+/* expected-error {{invalid argument of type 'double'; expected an integer type}} */ #pragma clang loop pipeline_initiation_interval(1.0)
+/* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop pipeline_initiation_interval(0)
+  for (int i = 0; i < Length; i++) {
+for (int j = 0; j < Length; j++) {
+  List[i * Length + j] = Value;
+}
+  }
+
+#pragma clang loop pipeline(disable) 
+/* expected-error {{expected a for, while, or do-while loop to follow '#pragma clang loop'}} */ int j = Length;
+#pragma clang loop pipeline_initiation_interval(4)
+/* expected-error {{expected a for, while, or do-while loop to follow '#pragma clang loop'}} */ int k = Length;
+
+#pragma clang loop pipeline(disable)
+#pragma clang loop pipeline_initiation_interval(4) /* expected-error {{incompatible directives 'pipeline(disable)' and 'pipeline_initiation_interval(4)'}} */
+  for (int i = 0; i < Length; i++) {
+List[i] = Value;
+  }
+
+#pragma clang loop pipeline(disable)
+/* expected-error {{expected statement}} */ }
Index: test/Parser/pragma-loop.cpp
===
--- test/Parser/pragma-loop.cpp
+++ test/Parser/pragma-loop.cpp
@@ -147,7 +147,7 @@
 /* expected-error {{missing argument; expected 'enable', 'full' or 'disable'}} */ #pragma clang loop unroll()
 /* expected-error {{missing argument; expected 'enable' or 'disable'}} */ #pragma clang loop distribute()
 
-/* expected-error {{missing option; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, or distribute}} */ #pragma clang loop
+/* expected-error {{missing option; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, pipeline, pipeline_initiation_interval or distribute}} */ #pragma clang loop
 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop badkeyword
 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop badkeyword(enable)
 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop vectorize(enable) badkeyword(4)
Index: test/CodeGenCXX/pragma-pipeline.cpp

[PATCH] D55930: [gn build] Add build files for clang/lib/{Frontend, Frontend/Rewrite, Serialization}

2018-12-20 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D55930



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


[PATCH] D55931: [gn build] Add build file for clang/lib/CodeGen and llvm/lib/ProfileData/Coverage

2018-12-20 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D55931



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


[PATCH] D55948: Modify DeclaratorChuck::getFunction to use DeclSpec for qualifiers

2018-12-20 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: include/clang/Sema/DeclSpec.h:1304
+/// DeclSpec for the function with the qualifier related info. 
+DeclSpec *TypeDeclSpec;
+

Can we give this a better name?  I know we use "type qualifiers" for this 
concept in the AST, but it's not a good name, and we should really rename it in 
the AST.  How about `MethodQualifiers`?



Comment at: lib/Parse/ParseDecl.cpp:6129
+  // create DeclSpec here to be populated later.
+  DS = new DeclSpec(AttrFactory);
+

Is it possible to just build into a local DS and then move that DS to the heap 
if it contains qualifiers or attributes?  It'd be nice to not do a heap 
allocation every time we parse a function declarator in C++ since the vast 
majority of them don't have qualifiers.  (It probably has to be a move to 
handle attributes and `AttributeFactory` correctly.)

That would also side-step any concerns about memory management.


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

https://reviews.llvm.org/D55948



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


r349825 - Declares __cpu_model as dso local

2018-12-20 Thread Haibo Huang via cfe-commits
Author: hhb
Date: Thu Dec 20 13:33:59 2018
New Revision: 349825

URL: http://llvm.org/viewvc/llvm-project?rev=349825=rev
Log:
Declares __cpu_model as dso local

__builtin_cpu_supports and __builtin_cpu_is use information in __cpu_model to 
decide cpu features. Before this change, __cpu_model was not declared as dso 
local. The generated code looks up the address in GOT when reading __cpu_model. 
This makes it impossible to use these functions in ifunc, because at that time 
GOT entries have not been relocated. This change makes it dso local.

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


Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGen/builtin-cpu-is.c
cfe/trunk/test/CodeGen/builtin-cpu-supports.c

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=349825=349824=349825=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Dec 20 13:33:59 2018
@@ -9537,6 +9537,7 @@ Value *CodeGenFunction::EmitX86CpuIs(Str
 
   // Grab the global __cpu_model.
   llvm::Constant *CpuModel = CGM.CreateRuntimeVariable(STy, "__cpu_model");
+  cast(CpuModel)->setDSOLocal(true);
 
   // Calculate the index needed to access the correct field based on the
   // range. Also adjust the expected value.
@@ -9609,6 +9610,7 @@ llvm::Value *CodeGenFunction::EmitX86Cpu
 
 // Grab the global __cpu_model.
 llvm::Constant *CpuModel = CGM.CreateRuntimeVariable(STy, "__cpu_model");
+cast(CpuModel)->setDSOLocal(true);
 
 // Grab the first (0th) element from the field __cpu_features off of the
 // global in the struct STy.
@@ -9628,6 +9630,8 @@ llvm::Value *CodeGenFunction::EmitX86Cpu
   if (Features2 != 0) {
 llvm::Constant *CpuFeatures2 = CGM.CreateRuntimeVariable(Int32Ty,
  
"__cpu_features2");
+cast(CpuFeatures2)->setDSOLocal(true);
+
 Value *Features =
 Builder.CreateAlignedLoad(CpuFeatures2, CharUnits::fromQuantity(4));
 
@@ -9645,6 +9649,9 @@ Value *CodeGenFunction::EmitX86CpuInit()
   llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy,
 /*Variadic*/ false);
   llvm::Constant *Func = CGM.CreateRuntimeFunction(FTy, 
"__cpu_indicator_init");
+  cast(Func)->setDSOLocal(true);
+  cast(Func)->setDLLStorageClass(
+  llvm::GlobalValue::DefaultStorageClass);
   return Builder.CreateCall(Func);
 }
 

Modified: cfe/trunk/test/CodeGen/builtin-cpu-is.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtin-cpu-is.c?rev=349825=349824=349825=diff
==
--- cfe/trunk/test/CodeGen/builtin-cpu-is.c (original)
+++ cfe/trunk/test/CodeGen/builtin-cpu-is.c Thu Dec 20 13:33:59 2018
@@ -4,6 +4,8 @@
 // global, the bit grab, and the icmp correct.
 extern void a(const char *);
 
+// CHECK: @__cpu_model = external dso_local global { i32, i32, i32, [1 x i32] }
+
 void intel() {
   if (__builtin_cpu_is("intel"))
 a("intel");

Modified: cfe/trunk/test/CodeGen/builtin-cpu-supports.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtin-cpu-supports.c?rev=349825=349824=349825=diff
==
--- cfe/trunk/test/CodeGen/builtin-cpu-supports.c (original)
+++ cfe/trunk/test/CodeGen/builtin-cpu-supports.c Thu Dec 20 13:33:59 2018
@@ -4,6 +4,9 @@
 // global, the bit grab, and the icmp correct.
 extern void a(const char *);
 
+// CHECK: @__cpu_model = external dso_local global { i32, i32, i32, [1 x i32] }
+// CHECK: @__cpu_features2 = external dso_local global i32
+
 int main() {
   __builtin_cpu_init();
 
@@ -25,3 +28,5 @@ int main() {
 
   return 0;
 }
+
+// CHECK: declare dso_local void @__cpu_indicator_init()


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


[PATCH] D55823: [analyzer] Fix backward compatibility issue after D53280 'Emit an error for invalid -analyzer-config inputs'

2018-12-20 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349824: [driver] [analyzer] Fix a backward compatibility 
issue after r348038. (authored by dergachev, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55823?vs=179135=179142#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55823

Files:
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
  cfe/trunk/test/Analysis/invalid-analyzer-config-value.c

Index: cfe/trunk/test/Analysis/invalid-analyzer-config-value.c
===
--- cfe/trunk/test/Analysis/invalid-analyzer-config-value.c
+++ cfe/trunk/test/Analysis/invalid-analyzer-config-value.c
@@ -66,6 +66,10 @@
 
 // CHECK-NO-COMPAT: error: unknown analyzer-config 'no-false-positives'
 
+// Test the driver properly using "analyzer-config-compatibility-mode=true",
+// even if -analyze isn't specified.
+// RUN: %clang -Xclang -analyzer-config -Xclang remember=TheVasa %s
+
 // expected-no-diagnostics
 
 int main() {}
Index: cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
===
--- cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
+++ cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
@@ -0,0 +1,79 @@
+// Same as invalid-analyzer-config-value.c but without -analyzer-config
+// in the file name, so that argument string pattern matching
+// didn't accidentally match it.
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config notes-as-events=yesplease \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-BOOL-INPUT
+
+// CHECK-BOOL-INPUT: (frontend): invalid input for analyzer-config option
+// CHECK-BOOL-INPUT-SAME:'notes-as-events', that expects a boolean value
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config notes-as-events=yesplease
+
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config max-inlinable-size=400km/h \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-UINT-INPUT
+
+// CHECK-UINT-INPUT: (frontend): invalid input for analyzer-config option
+// CHECK-UINT-INPUT-SAME:'max-inlinable-size', that expects an unsigned
+// CHECK-UINT-INPUT-SAME:value
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config max-inlinable-size=400km/h
+
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config ctu-dir=0123012301230123 \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-FILENAME-INPUT
+
+// CHECK-FILENAME-INPUT: (frontend): invalid input for analyzer-config option
+// CHECK-FILENAME-INPUT-SAME:'ctu-dir', that expects a filename
+// CHECK-FILENAME-INPUT-SAME:value
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config ctu-dir=0123012301230123
+
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config no-false-positives=true \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-UNKNOWN-CFG
+
+// CHECK-UNKNOWN-CFG: (frontend): unknown analyzer-config 'no-false-positives'
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config no-false-positives=true
+
+
+// Test the driver properly using "analyzer-config-compatibility-mode=true",
+// no longer causing an error on input error.
+// RUN: %clang --analyze %s
+
+// RUN: not %clang --analyze %s \
+// RUN:   -Xclang -analyzer-config -Xclang no-false-positives=true \
+// RUN:   -Xclang -analyzer-config-compatibility-mode=false \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-NO-COMPAT
+
+// CHECK-NO-COMPAT: error: unknown analyzer-config 'no-false-positives'
+
+// Test the driver properly using "analyzer-config-compatibility-mode=true",
+// even if -analyze isn't specified.
+// RUN: %clang -Xclang -analyzer-config -Xclang remember=TheVasa %s
+
+// expected-no-diagnostics
+
+int main() {}
Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -2360,9 +2360,6 @@
   // Treat blocks as analysis entry points.
   CmdArgs.push_back("-analyzer-opt-analyze-nested-blocks");
 
-  // Enable compatilibily mode to avoid analyzer-config related errors.
-  

r349824 - [driver] [analyzer] Fix a backward compatibility issue after r348038.

2018-12-20 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Thu Dec 20 13:26:40 2018
New Revision: 349824

URL: http://llvm.org/viewvc/llvm-project?rev=349824=rev
Log:
[driver] [analyzer] Fix a backward compatibility issue after r348038.

Since r348038 we emit an error every time an -analyzer-config option is not
found. The driver, however, suppresses this error with another flag,
-analyzer-config-compatibility-mode, so backwards compatibility is maintained,
while analyzer developers still enjoy the new typo-free experience.

The backwards compatibility turns out to be still broken when the -analyze
action is not specified; it is still possible to specify -analyzer-config
in that case. This should be fixed now.

Patch by Kristóf Umann!

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

rdar://problem/46504165

Added:
cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Analysis/invalid-analyzer-config-value.c

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=349824=349823=349824=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Thu Dec 20 13:26:40 2018
@@ -2360,9 +2360,6 @@ static void RenderAnalyzerOptions(const
   // Treat blocks as analysis entry points.
   CmdArgs.push_back("-analyzer-opt-analyze-nested-blocks");
 
-  // Enable compatilibily mode to avoid analyzer-config related errors.
-  CmdArgs.push_back("-analyzer-config-compatibility-mode=true");
-
   // Add default argument set.
   if (!Args.hasArg(options::OPT__analyzer_no_default_checks)) {
 CmdArgs.push_back("-analyzer-checker=core");
@@ -3738,6 +3735,16 @@ void Clang::ConstructJob(Compilation ,
   if (isa(JA))
 RenderAnalyzerOptions(Args, CmdArgs, Triple, Input);
 
+  // Enable compatilibily mode to avoid analyzer-config related errors.
+  // Since we can't access frontend flags through hasArg, let's manually 
iterate
+  // through them.
+  for (size_t Index = 0; Index < Args.size(); ++Index) {
+if (StringRef(Args.getArgString(Index)).contains("-analyzer-config")) {
+  CmdArgs.push_back("-analyzer-config-compatibility-mode=true");
+  break;
+}
+  }
+
   CheckCodeGenerationOptions(D, Args);
 
   unsigned FunctionAlignment = ParseFunctionAlignment(TC, Args);

Added: cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c?rev=349824=auto
==
--- cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c (added)
+++ cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c Thu Dec 20 
13:26:40 2018
@@ -0,0 +1,79 @@
+// Same as invalid-analyzer-config-value.c but without -analyzer-config
+// in the file name, so that argument string pattern matching
+// didn't accidentally match it.
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config notes-as-events=yesplease \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-BOOL-INPUT
+
+// CHECK-BOOL-INPUT: (frontend): invalid input for analyzer-config option
+// CHECK-BOOL-INPUT-SAME:'notes-as-events', that expects a boolean 
value
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config notes-as-events=yesplease
+
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config max-inlinable-size=400km/h \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-UINT-INPUT
+
+// CHECK-UINT-INPUT: (frontend): invalid input for analyzer-config option
+// CHECK-UINT-INPUT-SAME:'max-inlinable-size', that expects an unsigned
+// CHECK-UINT-INPUT-SAME:value
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config max-inlinable-size=400km/h
+
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config ctu-dir=0123012301230123 \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-FILENAME-INPUT
+
+// CHECK-FILENAME-INPUT: (frontend): invalid input for analyzer-config option
+// CHECK-FILENAME-INPUT-SAME:'ctu-dir', that expects a filename
+// CHECK-FILENAME-INPUT-SAME:value
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config ctu-dir=0123012301230123
+
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config no-false-positives=true \
+// RUN:   2>&1 | FileCheck %s 

[PATCH] D52117: Generate llvm.loop.parallel_accesses instead of llvm.mem.parallel_loop_access metadata.

2018-12-20 Thread Michael Kruse via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC349823: [CodeGen] Generate llvm.loop.parallel_accesses 
instead of llvm.mem. (authored by Meinersbur, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D52117?vs=178944=179141#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D52117

Files:
  lib/CodeGen/CGLoopInfo.cpp
  lib/CodeGen/CGLoopInfo.h
  test/CodeGenCXX/pragma-loop-safety-imperfectly_nested.cpp
  test/CodeGenCXX/pragma-loop-safety-nested.cpp
  test/CodeGenCXX/pragma-loop-safety-outer.cpp
  test/CodeGenCXX/pragma-loop-safety.cpp
  test/OpenMP/for_codegen.cpp
  test/OpenMP/for_simd_codegen.cpp
  test/OpenMP/loops_explicit_clauses_codegen.cpp
  test/OpenMP/ordered_codegen.cpp
  test/OpenMP/parallel_for_simd_codegen.cpp
  test/OpenMP/schedule_codegen.cpp
  test/OpenMP/simd_codegen.cpp
  test/OpenMP/simd_metadata.c
  test/OpenMP/target_parallel_for_simd_codegen.cpp
  test/OpenMP/target_simd_codegen.cpp
  test/OpenMP/taskloop_simd_codegen.cpp

Index: lib/CodeGen/CGLoopInfo.h
===
--- lib/CodeGen/CGLoopInfo.h
+++ lib/CodeGen/CGLoopInfo.h
@@ -84,6 +84,9 @@
   /// Get the set of attributes active for this loop.
   const LoopAttributes () const { return Attrs; }
 
+  /// Return this loop's access group or nullptr if it does not have one.
+  llvm::MDNode *getAccessGroup() const { return AccGroup; }
+
 private:
   /// Loop ID metadata.
   llvm::MDNode *LoopID;
@@ -91,6 +94,8 @@
   llvm::BasicBlock *Header;
   /// The attributes for this loop.
   LoopAttributes Attrs;
+  /// The access group for memory accesses parallel to this loop.
+  llvm::MDNode *AccGroup = nullptr;
 };
 
 /// A stack of loop information corresponding to loop nesting levels.
Index: lib/CodeGen/CGLoopInfo.cpp
===
--- lib/CodeGen/CGLoopInfo.cpp
+++ lib/CodeGen/CGLoopInfo.cpp
@@ -21,7 +21,7 @@
 
 static MDNode *createMetadata(LLVMContext , const LoopAttributes ,
   const llvm::DebugLoc ,
-  const llvm::DebugLoc ) {
+  const llvm::DebugLoc , MDNode *) {
 
   if (!Attrs.IsParallel && Attrs.VectorizeWidth == 0 &&
   Attrs.InterleaveCount == 0 && Attrs.UnrollCount == 0 &&
@@ -122,6 +122,12 @@
 Args.push_back(MDNode::get(Ctx, Vals));
   }
 
+  if (Attrs.IsParallel) {
+AccGroup = MDNode::getDistinct(Ctx, {});
+Args.push_back(MDNode::get(
+Ctx, {MDString::get(Ctx, "llvm.loop.parallel_accesses"), AccGroup}));
+  }
+
   // Set the first operand to itself.
   MDNode *LoopID = MDNode::get(Ctx, Args);
   LoopID->replaceOperandWith(0, LoopID);
@@ -150,7 +156,8 @@
 LoopInfo::LoopInfo(BasicBlock *Header, const LoopAttributes ,
const llvm::DebugLoc , const llvm::DebugLoc )
 : LoopID(nullptr), Header(Header), Attrs(Attrs) {
-  LoopID = createMetadata(Header->getContext(), Attrs, StartLoc, EndLoc);
+  LoopID =
+  createMetadata(Header->getContext(), Attrs, StartLoc, EndLoc, AccGroup);
 }
 
 void LoopInfoStack::push(BasicBlock *Header, const llvm::DebugLoc ,
@@ -328,6 +335,21 @@
 }
 
 void LoopInfoStack::InsertHelper(Instruction *I) const {
+  if (I->mayReadOrWriteMemory()) {
+SmallVector AccessGroups;
+for (const LoopInfo  : Active) {
+  // Here we assume that every loop that has an access group is parallel.
+  if (MDNode *Group = AL.getAccessGroup())
+AccessGroups.push_back(Group);
+}
+MDNode *UnionMD = nullptr;
+if (AccessGroups.size() == 1)
+  UnionMD = cast(AccessGroups[0]);
+else if (AccessGroups.size() >= 2)
+  UnionMD = MDNode::get(I->getContext(), AccessGroups);
+I->setMetadata("llvm.access.group", UnionMD);
+  }
+
   if (!hasInfo())
 return;
 
@@ -343,18 +365,4 @@
   }
 return;
   }
-
-  if (I->mayReadOrWriteMemory()) {
-SmallVector ParallelLoopIDs;
-for (const LoopInfo  : Active)
-  if (AL.getAttributes().IsParallel)
-ParallelLoopIDs.push_back(AL.getLoopID());
-
-MDNode *ParallelMD = nullptr;
-if (ParallelLoopIDs.size() == 1)
-  ParallelMD = cast(ParallelLoopIDs[0]);
-else if (ParallelLoopIDs.size() >= 2)
-  ParallelMD = MDNode::get(I->getContext(), ParallelLoopIDs);
-I->setMetadata("llvm.mem.parallel_loop_access", ParallelMD);
-  }
 }
Index: test/OpenMP/target_simd_codegen.cpp
===
--- test/OpenMP/target_simd_codegen.cpp
+++ test/OpenMP/target_simd_codegen.cpp
@@ -342,7 +342,7 @@
 // CHECK-64:[[AA_CADDR:%.+]] = bitcast i[[SZ]]* [[AA_ADDR]] to i32*
 // CHECK-64:[[AA:%.+]] = load i32, i32* [[AA_CADDR]], align
 // CHECK-32:[[AA:%.+]] = load i32, i32* [[AA_ADDR]], align
-// CHECK:   !llvm.mem.parallel_loop_access
+// CHECK:   !llvm.access.group
 // CHECK:   !llvm.loop
 // 

r349823 - [CodeGen] Generate llvm.loop.parallel_accesses instead of llvm.mem.parallel_loop_access metadata.

2018-12-20 Thread Michael Kruse via cfe-commits
Author: meinersbur
Date: Thu Dec 20 13:24:54 2018
New Revision: 349823

URL: http://llvm.org/viewvc/llvm-project?rev=349823=rev
Log:
[CodeGen] Generate llvm.loop.parallel_accesses instead of 
llvm.mem.parallel_loop_access metadata.

Instead of generating llvm.mem.parallel_loop_access metadata, generate
llvm.access.group on instructions and llvm.loop.parallel_accesses on
loops. There is one access group per generated loop.

This is clang part of D52116/r349725.

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

Added:
cfe/trunk/test/CodeGenCXX/pragma-loop-safety-imperfectly_nested.cpp
Modified:
cfe/trunk/lib/CodeGen/CGLoopInfo.cpp
cfe/trunk/lib/CodeGen/CGLoopInfo.h
cfe/trunk/test/CodeGenCXX/pragma-loop-safety-nested.cpp
cfe/trunk/test/CodeGenCXX/pragma-loop-safety-outer.cpp
cfe/trunk/test/CodeGenCXX/pragma-loop-safety.cpp
cfe/trunk/test/OpenMP/for_codegen.cpp
cfe/trunk/test/OpenMP/for_simd_codegen.cpp
cfe/trunk/test/OpenMP/loops_explicit_clauses_codegen.cpp
cfe/trunk/test/OpenMP/ordered_codegen.cpp
cfe/trunk/test/OpenMP/parallel_for_simd_codegen.cpp
cfe/trunk/test/OpenMP/schedule_codegen.cpp
cfe/trunk/test/OpenMP/simd_codegen.cpp
cfe/trunk/test/OpenMP/simd_metadata.c
cfe/trunk/test/OpenMP/target_parallel_for_simd_codegen.cpp
cfe/trunk/test/OpenMP/target_simd_codegen.cpp
cfe/trunk/test/OpenMP/taskloop_simd_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGLoopInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGLoopInfo.cpp?rev=349823=349822=349823=diff
==
--- cfe/trunk/lib/CodeGen/CGLoopInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGLoopInfo.cpp Thu Dec 20 13:24:54 2018
@@ -21,7 +21,7 @@ using namespace llvm;
 
 static MDNode *createMetadata(LLVMContext , const LoopAttributes ,
   const llvm::DebugLoc ,
-  const llvm::DebugLoc ) {
+  const llvm::DebugLoc , MDNode *) 
{
 
   if (!Attrs.IsParallel && Attrs.VectorizeWidth == 0 &&
   Attrs.InterleaveCount == 0 && Attrs.UnrollCount == 0 &&
@@ -122,6 +122,12 @@ static MDNode *createMetadata(LLVMContex
 Args.push_back(MDNode::get(Ctx, Vals));
   }
 
+  if (Attrs.IsParallel) {
+AccGroup = MDNode::getDistinct(Ctx, {});
+Args.push_back(MDNode::get(
+Ctx, {MDString::get(Ctx, "llvm.loop.parallel_accesses"), AccGroup}));
+  }
+
   // Set the first operand to itself.
   MDNode *LoopID = MDNode::get(Ctx, Args);
   LoopID->replaceOperandWith(0, LoopID);
@@ -150,7 +156,8 @@ void LoopAttributes::clear() {
 LoopInfo::LoopInfo(BasicBlock *Header, const LoopAttributes ,
const llvm::DebugLoc , const llvm::DebugLoc 
)
 : LoopID(nullptr), Header(Header), Attrs(Attrs) {
-  LoopID = createMetadata(Header->getContext(), Attrs, StartLoc, EndLoc);
+  LoopID =
+  createMetadata(Header->getContext(), Attrs, StartLoc, EndLoc, AccGroup);
 }
 
 void LoopInfoStack::push(BasicBlock *Header, const llvm::DebugLoc ,
@@ -328,6 +335,21 @@ void LoopInfoStack::pop() {
 }
 
 void LoopInfoStack::InsertHelper(Instruction *I) const {
+  if (I->mayReadOrWriteMemory()) {
+SmallVector AccessGroups;
+for (const LoopInfo  : Active) {
+  // Here we assume that every loop that has an access group is parallel.
+  if (MDNode *Group = AL.getAccessGroup())
+AccessGroups.push_back(Group);
+}
+MDNode *UnionMD = nullptr;
+if (AccessGroups.size() == 1)
+  UnionMD = cast(AccessGroups[0]);
+else if (AccessGroups.size() >= 2)
+  UnionMD = MDNode::get(I->getContext(), AccessGroups);
+I->setMetadata("llvm.access.group", UnionMD);
+  }
+
   if (!hasInfo())
 return;
 
@@ -343,18 +365,4 @@ void LoopInfoStack::InsertHelper(Instruc
   }
 return;
   }
-
-  if (I->mayReadOrWriteMemory()) {
-SmallVector ParallelLoopIDs;
-for (const LoopInfo  : Active)
-  if (AL.getAttributes().IsParallel)
-ParallelLoopIDs.push_back(AL.getLoopID());
-
-MDNode *ParallelMD = nullptr;
-if (ParallelLoopIDs.size() == 1)
-  ParallelMD = cast(ParallelLoopIDs[0]);
-else if (ParallelLoopIDs.size() >= 2)
-  ParallelMD = MDNode::get(I->getContext(), ParallelLoopIDs);
-I->setMetadata("llvm.mem.parallel_loop_access", ParallelMD);
-  }
 }

Modified: cfe/trunk/lib/CodeGen/CGLoopInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGLoopInfo.h?rev=349823=349822=349823=diff
==
--- cfe/trunk/lib/CodeGen/CGLoopInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGLoopInfo.h Thu Dec 20 13:24:54 2018
@@ -84,6 +84,9 @@ public:
   /// Get the set of attributes active for this loop.
   const LoopAttributes () const { return Attrs; }
 
+  /// Return this loop's access group or nullptr if it does not have one.
+  llvm::MDNode *getAccessGroup() const { return AccGroup; }
+
 private:
 

[PATCH] D55953: Android is not GNU, so don't claim that it is.

2018-12-20 Thread Dan Albert via Phabricator via cfe-commits
danalbert created this revision.
danalbert added reviewers: pirama, srhines.

Repository:
  rC Clang

https://reviews.llvm.org/D55953

Files:
  lib/Basic/Targets/OSTargets.h
  test/Preprocessor/init.c


Index: test/Preprocessor/init.c
===
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -9057,6 +9057,7 @@
 // RUN: %clang_cc1 -triple arm-linux-androideabi -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix ANDROID %s
 // ANDROID-NOT:#define __ANDROID_API__
 // ANDROID:#define __ANDROID__ 1
+// ANDROID-NOT:#define __gnu_linux__
 //
 // RUN: %clang_cc1 -x c++ -triple i686-linux-android -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix I386-ANDROID-CXX %s
 // I386-ANDROID-CXX:#define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 8U
@@ -9067,6 +9068,7 @@
 // RUN: %clang_cc1 -triple arm-linux-androideabi20 -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix ANDROID20 %s
 // ANDROID20:#define __ANDROID_API__ 20
 // ANDROID20:#define __ANDROID__ 1
+// ANDROID-NOT:#define __gnu_linux__
 //
 // RUN: %clang_cc1 -triple lanai-unknown-unknown -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix LANAI %s
 // LANAI: #define __lanai__ 1
Index: lib/Basic/Targets/OSTargets.h
===
--- lib/Basic/Targets/OSTargets.h
+++ lib/Basic/Targets/OSTargets.h
@@ -345,7 +345,6 @@
 // Linux defines; list based off of gcc output
 DefineStd(Builder, "unix", Opts);
 DefineStd(Builder, "linux", Opts);
-Builder.defineMacro("__gnu_linux__");
 Builder.defineMacro("__ELF__");
 if (Triple.isAndroid()) {
   Builder.defineMacro("__ANDROID__", "1");
@@ -355,6 +354,8 @@
   this->PlatformMinVersion = VersionTuple(Maj, Min, Rev);
   if (Maj)
 Builder.defineMacro("__ANDROID_API__", Twine(Maj));
+} else {
+Builder.defineMacro("__gnu_linux__");
 }
 if (Opts.POSIXThreads)
   Builder.defineMacro("_REENTRANT");


Index: test/Preprocessor/init.c
===
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -9057,6 +9057,7 @@
 // RUN: %clang_cc1 -triple arm-linux-androideabi -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix ANDROID %s
 // ANDROID-NOT:#define __ANDROID_API__
 // ANDROID:#define __ANDROID__ 1
+// ANDROID-NOT:#define __gnu_linux__
 //
 // RUN: %clang_cc1 -x c++ -triple i686-linux-android -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix I386-ANDROID-CXX %s
 // I386-ANDROID-CXX:#define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 8U
@@ -9067,6 +9068,7 @@
 // RUN: %clang_cc1 -triple arm-linux-androideabi20 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix ANDROID20 %s
 // ANDROID20:#define __ANDROID_API__ 20
 // ANDROID20:#define __ANDROID__ 1
+// ANDROID-NOT:#define __gnu_linux__
 //
 // RUN: %clang_cc1 -triple lanai-unknown-unknown -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix LANAI %s
 // LANAI: #define __lanai__ 1
Index: lib/Basic/Targets/OSTargets.h
===
--- lib/Basic/Targets/OSTargets.h
+++ lib/Basic/Targets/OSTargets.h
@@ -345,7 +345,6 @@
 // Linux defines; list based off of gcc output
 DefineStd(Builder, "unix", Opts);
 DefineStd(Builder, "linux", Opts);
-Builder.defineMacro("__gnu_linux__");
 Builder.defineMacro("__ELF__");
 if (Triple.isAndroid()) {
   Builder.defineMacro("__ANDROID__", "1");
@@ -355,6 +354,8 @@
   this->PlatformMinVersion = VersionTuple(Maj, Min, Rev);
   if (Maj)
 Builder.defineMacro("__ANDROID_API__", Twine(Maj));
+} else {
+Builder.defineMacro("__gnu_linux__");
 }
 if (Opts.POSIXThreads)
   Builder.defineMacro("_REENTRANT");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47757: [Sema] Produce diagnostics when unavailable aligned allocation/deallocation functions are called

2018-12-20 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added inline comments.
This revision is now accepted and ready to land.



Comment at: lib/Sema/SemaExpr.cpp:54
 /// emitting diagnostics.
 bool Sema::CanUseDecl(NamedDecl *D, bool TreatUnavailableAsInvalid) {
   // See if this is an auto-typed variable whose initializer we are parsing.

Does this also need to be updated?


Repository:
  rC Clang

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

https://reviews.llvm.org/D47757



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


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

2018-12-20 Thread Mateusz Maćkowski via Phabricator via cfe-commits
m4tx updated this revision to Diff 179138.
m4tx marked an inline comment as done.

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

https://reviews.llvm.org/D55793

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/DuplicatedAccessSpecifiersCheck.cpp
  clang-tidy/readability/DuplicatedAccessSpecifiersCheck.h
  clang-tidy/readability/ReadabilityTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-duplicated-access-specifiers.rst
  test/clang-tidy/readability-duplicated-access-specifiers.cpp

Index: test/clang-tidy/readability-duplicated-access-specifiers.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-duplicated-access-specifiers.cpp
@@ -0,0 +1,116 @@
+// RUN: %check_clang_tidy %s readability-duplicated-access-specifiers %t
+
+class FooPublic {
+public:
+  int a;
+public: // comment-0
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: duplicated access specifier [readability-duplicated-access-specifiers]
+  // CHECK-MESSAGES: :[[@LINE-4]]:1: note: previously declared here
+  // CHECK-FIXES: {{^}}// comment-0{{$}}
+  int b;
+private:
+  int c;
+};
+
+struct StructPublic {
+public:
+  int a;
+public: // comment-1
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: duplicated access specifier [readability-duplicated-access-specifiers]
+  // CHECK-MESSAGES: :[[@LINE-4]]:1: note: previously declared here
+  // CHECK-FIXES: {{^}}// comment-1{{$}}
+  int b;
+private:
+  int c;
+};
+
+union UnionPublic {
+public:
+  int a;
+public: // comment-2
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: duplicated access specifier [readability-duplicated-access-specifiers]
+  // CHECK-MESSAGES: :[[@LINE-4]]:1: note: previously declared here
+  // CHECK-FIXES: {{^}}// comment-2{{$}}
+  int b;
+private:
+  int c;
+};
+
+class FooProtected {
+protected:
+  int a;
+protected: // comment-3
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: duplicated access specifier [readability-duplicated-access-specifiers]
+  // CHECK-MESSAGES: :[[@LINE-4]]:1: note: previously declared here
+  // CHECK-FIXES: {{^}}// comment-3{{$}}
+  int b;
+private:
+  int c;
+};
+
+class FooPrivate {
+private:
+  int a;
+private: // comment-4
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: duplicated access specifier [readability-duplicated-access-specifiers]
+  // CHECK-MESSAGES: :[[@LINE-4]]:1: note: previously declared here
+  // CHECK-FIXES: {{^}}// comment-4{{$}}
+  int b;
+public:
+  int c;
+};
+
+class FooMacro {
+private:
+  int a;
+#if defined(ZZ)
+  public:
+  int b;
+#endif
+private: // comment-5
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: duplicated access specifier [readability-duplicated-access-specifiers]
+  // CHECK-MESSAGES: :[[@LINE-8]]:1: note: previously declared here
+  // CHECK-FIXES: {{^}}// comment-5{{$}}
+  int c;
+protected:
+  int d;
+public:
+  int e;
+};
+
+class Valid {
+private:
+  int a;
+public:
+  int b;
+private:
+  int c;
+protected:
+  int d;
+public:
+  int e;
+};
+
+class ValidInnerClass {
+public:
+  int a;
+
+  class Inner {
+  public:
+int b;
+  };
+};
+
+#define MIXIN private: int b;
+
+class ValidMacro {
+private:
+  int a;
+MIXIN
+private:
+  int c;
+protected:
+  int d;
+public:
+  int e;
+};
Index: docs/clang-tidy/checks/readability-duplicated-access-specifiers.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-duplicated-access-specifiers.rst
@@ -0,0 +1,26 @@
+.. title:: clang-tidy - readability-duplicated-access-specifiers
+
+readability-duplicated-access-specifiers
+
+
+Finds classes, structs and unions containing duplicated member access specifiers
+that can be removed.
+
+Examples:
+
+.. code-block:: c++
+
+  class Foo {
+  public:
+int x;
+int y;
+  public:
+int z;
+  protected:
+int a;
+  public:
+int c;
+  }
+
+In the example above, the second ``public`` declaration can be removed without
+any changes of behavior.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -238,6 +238,7 @@
readability-container-size-empty
readability-delete-null-pointer
readability-deleted-default
+   readability-duplicated-access-specifiers
readability-else-after-return
readability-function-size
readability-identifier-naming
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -192,6 +192,12 @@
   Checks for functions with a ``const``-qualified return type and recommends
   removal of the ``const`` keyword.
 
+- New :doc:`readability-duplicated-access-specifiers
+  ` check.
+
+  Finds classes, structs, and unions that contain duplicated member
+  access specifiers.
+
 - New 

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

2018-12-20 Thread Mateusz Maćkowski via Phabricator via cfe-commits
m4tx marked 4 inline comments as done.
m4tx added a comment.

In D55793#1335274 , @lebedev.ri wrote:

> In D55793#1335249 , @m4tx wrote:
>
> > In D55793#1333661 , @lebedev.ri 
> > wrote:
> >
> > > Please add tests with preprocessor (`#if ...`) that will show that it 
> > > ignores disabled code. e.g.:
> > >
> > >   class ProbablyValid {
> > >   private:
> > > int a;
> > >   #if defined(ZZ)
> > >   public:
> > > int b;
> > >   #endif
> > >   private:
> > > int c;
> > >   protected:
> > > int d;
> > >   public:
> > > int e;
> > >   };
> > >
> >
> >
> > Is this actually possible?
> >  It seems that macros are ran through the preprocessor before one can 
> > fiddle with them in clang-tidy.
> >  In other words, `int b` is not at all present in the AST.
>
>
> .. and by "ignores" i meant that it **will** be diagnosing this code, since 
> it did not know anything about the code within the preprocessor-disabled 
> section.
>
> > However, I added a code to detect macro expansions, so duplicated access 
> > specifiers are ignored if at least one of them comes from a macro. If there 
> > is a way to cover your case as well, please let me know, because even after 
> > looking at the code of other checks I haven't found out a solution for this.


Ok, thanks for the clarification. I've added the test in the latest diff!




Comment at: clang-tidy/readability/DuplicatedAccessSpecifiersCheck.cpp:51
+  diag(ASDecl->getLocation(), "duplicated access specifier")
+  << MatchedDecl
+  << FixItHint::CreateRemoval(ASDecl->getSourceRange());

aaron.ballman wrote:
> There is no %0 in the diagnostic string, so I'm not certain what this 
> argument is trying to print out. Did you mean `ASDecl->getSourceRange()` for 
> the underlining?
Sorry, this is another line I forgot to remove. Thanks for pointing this out!

By the way, does the underlining work in clang-tidy's `diag()` function? I see 
it is used outside the project, but here only `FixItHint`s seem to generate 
underline in the generated messages.


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

https://reviews.llvm.org/D55793



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


[PATCH] D55823: [analyzer] Fix backward compatibility issue after D53280 'Emit an error for invalid -analyzer-config inputs'

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

Thanks! Sorry about being a little slow with this, I'm sadly busier than I 
expected, but I'll definitely think about a nicer solution.


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

https://reviews.llvm.org/D55823



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


[PATCH] D55865: [ObjC] Add a new attribute to opt-out of implicit callee retain/release in ARC

2018-12-20 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3492
+def warn_ignored_objc_externally_retained : Warning<
+  "'objc_externally_retained' can only be applied to strong retainable "
+  "object pointer types with automatic storage">, InGroup;

rjmccall wrote:
> erik.pilkington wrote:
> > aaron.ballman wrote:
> > > This wording isn't quite right -- it doesn't apply to types, it applies 
> > > to variables of those types. How about: `... to local variables or 
> > > parameters of strong, retainable object pointer type`? or something along 
> > > those lines?
> > Sure, that is a bit more clear.
> I'd split this into two diagnostics:
> - "...can only be applied to local variables and parameters of retainable 
> type" (if the type or decl kind is wrong)
> - "...can only be applied to variables with strong ownership" (if the 
> qualifier is wrong)
Sure, I guess a lot of information is crammed into this one. I coalesced the 
two you suggested into one with a %select.



Comment at: clang/lib/CodeGen/CGExpr.cpp:1946
+if (isInit && isPseudoStrong)
+  Lifetime = Qualifiers::OCL_ExplicitNone;
+

rjmccall wrote:
> Where are we allowing assignments into pseudo-strong variables?
We're not, I removed this.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:6117
+  // to ensure that the variable is 'const' so that we can error on
+  // modification, which can otherwise overrelease.
+  VD->setType(Ty.withConst());

aaron.ballman wrote:
> erik.pilkington wrote:
> > aaron.ballman wrote:
> > > overrelease -> over-release
> > > 
> > > Btw, this isn't a bit of a hack, it's a huge hack, IMO. Instead, can we 
> > > simply err if the user hasn't specified `const` explicitly? I'm not a fan 
> > > of "we're hiding this rather important language detail behind an 
> > > attribute that can be ignored". This is especially worrisome because it 
> > > means the variable is const only when ARC is enabled, which seems like 
> > > surprising behavioral differences for that compiler flag.
> > An important part of this feature is that it could applied to parameters 
> > with `#pragma clang attribute` over code that has been audited to be safe. 
> > If we require adding `const` to every parameter, then that falls apart :/. 
> > 
> > For better or for worse, this is also consistent with other cases of 
> > pseudo-strong in the language, i.e.:
> > ```
> > void f(NSArray *A) {
> >   for (id Elem in A)
> > Elem = nil; // fine in -fno-objc-arc, error in -fobjc-arc because Elem 
> > is implicitly const.
> > }
> > ```
> > An important part of this feature is that it could applied to parameters 
> > with #pragma clang attribute over code that has been audited to be safe. If 
> > we require adding const to every parameter, then that falls apart :/.
> 
> Thanks for letting me know about that use case; it adds some helpful context. 
> However, I don't see why this falls apart -- if you're auditing the code, you 
> could add the `const` qualifiers at that time, couldn't you? 
> 
> Alternatively, if we warned instead of erred on the absence of `const`, then 
> this could be automated through clang-tidy by checking declarations that are 
> marked with the attribute but are not marked `const` and use the fix-it 
> machinery to update the code.
> 
> > For better or for worse, this is also consistent with other cases of 
> > pseudo-strong in the language,
> 
> Yes, but it's weird behavior for an attribute. The attribute is applied to 
> the *declaration* but then it silently modifies the *type* as well, but only 
> for that one declaration (which is at odds with the usual rules for 
> double-square bracket attributes and what they appertain to based on 
> syntactic location). Sometimes, this will lead to good behavior (such as 
> semantic checks and when doing AST matching over const-qualified types) and 
> sometimes it will lead to confusing behavior (pretty-printing the code is 
> going to stick const qualifers where none are written, diagnostics will talk 
> about const qualifiers that aren't written in the source, etc).
> 
> Also, doesn't this cause ABI issues? If you write the attribute on a 
> parameter, the presence or absence of that attribute is now part of the ABI 
> for the function call because the parameter type will be mangled as being 
> const-qualified. (Perhaps that's more of a feature than a bug -- I imagine 
> you want both sides of the ABI to agree whether ARC is enabled or not?)
> 
> I'm wondering if this is weird enough that it should be using a keyword 
> spelling instead of an attribute spelling? However, I'm not certain if that 
> works with `#pragma clang attribute`.
> Thanks for letting me know about that use case; it adds some helpful context. 
> However, I don't see why this falls apart -- if you're auditing the code, you 
> could add the const qualifiers at that time, couldn't 

[PATCH] D55865: [ObjC] Add a new attribute to opt-out of implicit callee retain/release in ARC

2018-12-20 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington updated this revision to Diff 179137.
erik.pilkington marked 8 inline comments as done.
erik.pilkington added a comment.

Address some review comments. Thanks!


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

https://reviews.llvm.org/D55865

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/CodeGenObjC/externally-retained.m
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaObjC/externally-retained.m

Index: clang/test/SemaObjC/externally-retained.m
===
--- /dev/null
+++ clang/test/SemaObjC/externally-retained.m
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fobjc-runtime=macosx-10.13.0 -fblocks -fobjc-arc %s -verify
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fobjc-runtime=macosx-10.13.0 -fblocks -fobjc-arc -xobjective-c++ %s -verify
+
+#define EXT_RET __attribute__((objc_externally_retained))
+
+@interface ObjCTy
+@end
+
+void test1() {
+  EXT_RET int a; // expected-warning{{'objc_externally_retained' can only be applied to}}
+  EXT_RET __weak ObjCTy *b; // expected-warning{{'objc_externally_retained' can only be applied to}}
+  EXT_RET __weak int (^c)(); // expected-warning{{'objc_externally_retained' can only be applied to}}
+
+  EXT_RET int (^d)() = ^{return 0;};
+  EXT_RET ObjCTy *e = 0;
+  EXT_RET __strong ObjCTy *f = 0;
+
+  e = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
+  f = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
+  d = ^{ return 0; }; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
+}
+
+void test2(ObjCTy *a);
+
+void test2(EXT_RET ObjCTy *a) {
+  a = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
+}
+
+EXT_RET ObjCTy *test3; // expected-warning{{'objc_externally_retained' can only be applied to}}
+
+@interface X // expected-warning{{defined without specifying a base class}} expected-note{{add a super class}}
+-(void)m: (ObjCTy *) p;
+@end
+@implementation X
+-(void)m: (ObjCTy *) EXT_RET p {
+  p = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
+}
+@end
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -94,6 +94,7 @@
 // CHECK-NEXT: ObjCBridgeRelated (SubjectMatchRule_record)
 // CHECK-NEXT: ObjCException (SubjectMatchRule_objc_interface)
 // CHECK-NEXT: ObjCExplicitProtocolImpl (SubjectMatchRule_objc_protocol)
+// CHECK-NEXT: ObjCExternallyRetained (SubjectMatchRule_variable)
 // CHECK-NEXT: ObjCMethodFamily (SubjectMatchRule_objc_method)
 // CHECK-NEXT: ObjCPreciseLifetime (SubjectMatchRule_variable)
 // CHECK-NEXT: ObjCRequiresPropertyDefs (SubjectMatchRule_objc_interface)
Index: clang/test/CodeGenObjC/externally-retained.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/externally-retained.m
@@ -0,0 +1,121 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fobjc-arc -fblocks -Wno-objc-root-class -O0 %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fobjc-arc -fblocks -Wno-objc-root-class -O0 -xobjective-c++ -std=c++11 %s -S -emit-llvm -o - | FileCheck %s --check-prefix CHECKXX --dump-input-on-failure
+
+#define EXT_RET __attribute__((objc_externally_retained))
+
+@interface ObjTy @end
+
+ObjTy *global;
+
+#if __cplusplus
+// Suppress name mangling in C++ mode for the sake of check lines.
+extern "C" void param(ObjTy *p);
+extern "C" void local();
+extern "C" void in_init();
+extern "C" void anchor();
+extern "C" void block_capture(ObjTy *);
+extern "C" void esc(void (^)());
+extern "C" void escp(void (^)(ObjTy *));
+extern "C" void block_param();
+#endif
+
+void param(EXT_RET ObjTy *p) {
+  // CHECK-LABEL: define void @param
+  // CHECK-NOT: llvm.objc.
+  // CHECK ret
+}
+
+void local() {
+  EXT_RET ObjTy *local = global;
+  // CHECK-LABEL: define void @local
+  // CHECK-NOT: llvm.objc.
+  // CHECK: ret
+}
+
+void in_init() {
+  // Test that we do the right thing when a variable appears in it's own
+  // initializer. Here, we release the value stored in 'wat' after overwriting
+  // it, in case it was somehow set to point to a non-null object while it's
+  // initializer is being 

r349820 - Make the "too many braces in scalar initialization" extension cause

2018-12-20 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Dec 20 12:58:53 2018
New Revision: 349820

URL: http://llvm.org/viewvc/llvm-project?rev=349820=rev
Log:
Make the "too many braces in scalar initialization" extension cause
SFINAE failures.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/test/SemaCXX/cxx0x-initializer-scalars.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=349820=349819=349820=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Dec 20 12:58:53 
2018
@@ -4880,7 +4880,7 @@ def warn_braces_around_scalar_init : War
   "braces around scalar initializer">, 
InGroup>;
 def ext_many_braces_around_scalar_init : ExtWarn<
   "too many braces around scalar initializer">,
-  InGroup>;
+  InGroup>, SFINAEFailure;
 def ext_complex_component_init : Extension<
   "complex initialization specifying real and imaginary components "
   "is an extension">, InGroup>;

Modified: cfe/trunk/test/SemaCXX/cxx0x-initializer-scalars.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-initializer-scalars.cpp?rev=349820=349819=349820=diff
==
--- cfe/trunk/test/SemaCXX/cxx0x-initializer-scalars.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx0x-initializer-scalars.cpp Thu Dec 20 12:58:53 
2018
@@ -127,3 +127,26 @@ namespace PR12118 {
 static_assert(sizeof(f({0})) == sizeof(one), "bad overload");
   }
 }
+
+namespace excess_braces_sfinae {
+  using valid = int&;
+  using invalid = float&;
+
+  template valid braces1(decltype(T{0})*);
+  template invalid braces1(...);
+
+  template valid braces2(decltype(T{{0}})*);
+  template invalid braces2(...);
+
+  template valid braces3(decltype(T{{{0}}})*);
+  template invalid braces3(...);
+
+  valid a = braces1(0);
+  invalid b = braces2(0);
+  invalid c = braces3(0);
+
+  struct X { int n; };
+  valid d = braces1(0);
+  valid e = braces2(0);
+  invalid f = braces3(0);
+}


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


[PATCH] D55823: [analyzer] Fix backward compatibility issue after D53280 'Emit an error for invalid -analyzer-config inputs'

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

Re-remove the first argument append.

Add a test in which file name doesn't match our search.


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

https://reviews.llvm.org/D55823

Files:
  lib/Driver/ToolChains/Clang.cpp
  test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
  test/Analysis/invalid-analyzer-config-value.c

Index: test/Analysis/invalid-analyzer-config-value.c
===
--- test/Analysis/invalid-analyzer-config-value.c
+++ test/Analysis/invalid-analyzer-config-value.c
@@ -66,6 +66,10 @@
 
 // CHECK-NO-COMPAT: error: unknown analyzer-config 'no-false-positives'
 
+// Test the driver properly using "analyzer-config-compatibility-mode=true",
+// even if -analyze isn't specified.
+// RUN: %clang -Xclang -analyzer-config -Xclang remember=TheVasa %s
+
 // expected-no-diagnostics
 
 int main() {}
Index: test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
===
--- /dev/null
+++ test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
@@ -0,0 +1,79 @@
+// Same as invalid-analyzer-config-value.c but without -analyzer-config
+// in the file name, so that argument string pattern matching
+// didn't accidentally match it.
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config notes-as-events=yesplease \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-BOOL-INPUT
+
+// CHECK-BOOL-INPUT: (frontend): invalid input for analyzer-config option
+// CHECK-BOOL-INPUT-SAME:'notes-as-events', that expects a boolean value
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config notes-as-events=yesplease
+
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config max-inlinable-size=400km/h \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-UINT-INPUT
+
+// CHECK-UINT-INPUT: (frontend): invalid input for analyzer-config option
+// CHECK-UINT-INPUT-SAME:'max-inlinable-size', that expects an unsigned
+// CHECK-UINT-INPUT-SAME:value
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config max-inlinable-size=400km/h
+
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config ctu-dir=0123012301230123 \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-FILENAME-INPUT
+
+// CHECK-FILENAME-INPUT: (frontend): invalid input for analyzer-config option
+// CHECK-FILENAME-INPUT-SAME:'ctu-dir', that expects a filename
+// CHECK-FILENAME-INPUT-SAME:value
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config ctu-dir=0123012301230123
+
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config no-false-positives=true \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-UNKNOWN-CFG
+
+// CHECK-UNKNOWN-CFG: (frontend): unknown analyzer-config 'no-false-positives'
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config no-false-positives=true
+
+
+// Test the driver properly using "analyzer-config-compatibility-mode=true",
+// no longer causing an error on input error.
+// RUN: %clang --analyze %s
+
+// RUN: not %clang --analyze %s \
+// RUN:   -Xclang -analyzer-config -Xclang no-false-positives=true \
+// RUN:   -Xclang -analyzer-config-compatibility-mode=false \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-NO-COMPAT
+
+// CHECK-NO-COMPAT: error: unknown analyzer-config 'no-false-positives'
+
+// Test the driver properly using "analyzer-config-compatibility-mode=true",
+// even if -analyze isn't specified.
+// RUN: %clang -Xclang -analyzer-config -Xclang remember=TheVasa %s
+
+// expected-no-diagnostics
+
+int main() {}
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -2360,9 +2360,6 @@
   // Treat blocks as analysis entry points.
   CmdArgs.push_back("-analyzer-opt-analyze-nested-blocks");
 
-  // Enable compatilibily mode to avoid analyzer-config related errors.
-  CmdArgs.push_back("-analyzer-config-compatibility-mode=true");
-
   // Add default argument set.
   if (!Args.hasArg(options::OPT__analyzer_no_default_checks)) {
 CmdArgs.push_back("-analyzer-checker=core");
@@ -3694,6 +3691,16 @@
   if (isa(JA))
 RenderAnalyzerOptions(Args, CmdArgs, Triple, Input);
 
+  // Enable compatilibily mode to avoid analyzer-config related errors.
+  // 

[PATCH] D55823: [analyzer] Fix backward compatibility issue after D53280 'Emit an error for invalid -analyzer-config inputs'

2018-12-20 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus marked an inline comment as done.
Szelethus added a comment.

Sure! I'm on my phone, and will be for a little while, can you commit on my 
behalf?




Comment at: lib/Driver/ToolChains/Clang.cpp:3700
+  // through them.
+  for (size_t Index = 0; Index < Args.size(); ++Index) {
+if (StringRef(Args.getArgString(Index)).contains("-analyzer-config")) {

george.karpenkov wrote:
> NoQ wrote:
> > Needs an LLVM-style loop!~ :)
> Shouldn't this be under else- for the previous branch? Otherwise it seems 
> that the option would be added twice.
I originally deleted that line, but I lost in somewhere :/


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

https://reviews.llvm.org/D55823



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


[PATCH] D55823: [analyzer] Fix backward compatibility issue after D53280 'Emit an error for invalid -analyzer-config inputs'

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

@Szelethus: Ok if we commit this real quick and then see if there's a better 
solution?


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

https://reviews.llvm.org/D55823



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


[PATCH] D55823: [analyzer] Fix backward compatibility issue after D53280 'Emit an error for invalid -analyzer-config inputs'

2018-12-20 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added inline comments.



Comment at: lib/Driver/ToolChains/Clang.cpp:3700
+  // through them.
+  for (size_t Index = 0; Index < Args.size(); ++Index) {
+if (StringRef(Args.getArgString(Index)).contains("-analyzer-config")) {

NoQ wrote:
> Needs an LLVM-style loop!~ :)
Shouldn't this be under else- for the previous branch? Otherwise it seems that 
the option would be added twice.


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

https://reviews.llvm.org/D55823



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


[PATCH] D55850: [OpenCL] Allow address spaces as method qualifiers

2018-12-20 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia marked an inline comment as done.
Anastasia added inline comments.



Comment at: lib/Parse/ParseDecl.cpp:6162
+}
+  }
+

rjmccall wrote:
> Anastasia wrote:
> > rjmccall wrote:
> > > This is enforcing a restriction that users write `const __private`, which 
> > > seems unreasonable.  It looks like `ParseTypeQualifierList` takes a flag 
> > > saying not to parse attributes; try adding a new option to that enum 
> > > allowing address-space attributes.
> > > 
> > > Collecting the attributes on the type-qualifiers `DeclSpec` rather than 
> > > adding them as function attributes seems correct.
> > Do you mean `ParseTypeQualifierListOpt`? That already parses the address 
> > spaces unconditionally. The problem is however that we are using local 
> > `DeclSpec` - `DS` variable here during the function qualifiers parsing 
> > because the `DeclSpec` member of the `Declarator` corresponds to the return 
> > type as far as I understand it. Therefore I am propagating missing address 
> > space attributes from the local `DS` variable into `FnAttrs` to be used in 
> > the function type info.
> > 
> > With current patch both of the following two forms:
> >   struct C {
> > void foo() __local const;
> >   };
> > and 
> >   struct C {
> > void foo() const __local;
> >   };
> > would be parsed correctly generating identical IR
> >   declare void @_ZNU3AS3K1C3fooEv(%struct.C addrspace(3)*)
> > 
> > 
> > 
> Oh, I see, sorry.  Why filter on attributes at all, then?  We should *only* 
> be parsing qualifier attributes in that list.
> 
> I actually think it would be reasonable to change 
> `DeclaratorChunk::FunctionTypeInfo` to just store a `DeclSpec` for all the 
> qualifiers; we're already duplicating an unfortunate amount of the logic from 
> `DeclSpec`, like remembering `SourceLocation`s for all the qualifiers.  
> You'll have to store it out-of-line, but we already store e.g. parameters out 
> of line, so the machinery for allocating and destroying it already exists.  
> Just make sure we don't actually allocate anything in the common case where 
> there aren't any qualifiers (i.e. for C and non-member C++ functions).
> 
> Also, I suspect that the use of `CXXThisScopeRAII` below this needs to be 
> updated to pull *all* the qualifiers out of `DS`.  Maybe Sema should have a 
> function for that.
I have uploaded a separate patch for this:
https://reviews.llvm.org/D55948

I think I can't avoid storing `DeclSpec` for non-memeber functions in C++ 
because we still use them to give diagnostics about the qualifiers. For example:
  test.cpp:1:12: error: non-member function cannot have 'const' qualifier
  void foo() const;

As for `CXXThisScopeRAII`, we seem to be adding other qualifiers to the 
`QualType` directly (while building it), so there seems to be no function to 
collect them into `Qualifiers`. I can, however, add code to collect address 
space qualifiers here. I guess we don't have any other missing qualifiers to 
collect?



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

https://reviews.llvm.org/D55850



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


[PATCH] D55949: Correctly handle function pointers returning a type marked nodiscard

2018-12-20 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: rsmith, Quuxplusone, erik.pilkington.

When a function returns a type and that type was declared `[[nodiscard]]`, we 
diagnose any unused results from that call as though the function were marked 
nodiscard. The same behavior should apply to calls through a function pointer.

This addresses PR31526.


https://reviews.llvm.org/D55949

Files:
  lib/AST/Expr.cpp
  lib/Sema/SemaStmt.cpp
  test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp


Index: test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
===
--- test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
+++ test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
@@ -32,6 +32,35 @@
   // OK, warning suppressed.
   (void)fp();
 }
+
+namespace PR31526 {
+typedef E (*fp1)();
+typedef S (*fp2)();
+
+typedef S S_alias;
+typedef S_alias (*fp3)();
+
+typedef fp2 fp2_alias;
+
+void f() {
+  fp1 one;
+  fp2 two;
+  fp3 three;
+  fp2_alias four;
+
+  one(); // expected-warning {{ignoring return value of function declared with 
'nodiscard' attribute}}
+  two(); // expected-warning {{ignoring return value of function declared with 
'nodiscard' attribute}}
+  three(); // expected-warning {{ignoring return value of function declared 
with 'nodiscard' attribute}}
+  four(); // expected-warning {{ignoring return value of function declared 
with 'nodiscard' attribute}}
+
+  // These are all okay because of the explicit cast to void.
+  (void)one();
+  (void)two();
+  (void)three();
+  (void)four();
+}
+} // namespace PR31526
+
 #ifdef EXT
 // expected-warning@4 {{use of the 'nodiscard' attribute is a C++17 extension}}
 // expected-warning@8 {{use of the 'nodiscard' attribute is a C++17 extension}}
Index: lib/Sema/SemaStmt.cpp
===
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -270,6 +270,12 @@
 Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
 return;
   }
+  if (const TagDecl *TD = CE->getCallReturnType(Context)->getAsTagDecl()) {
+if (const Attr *A = TD->getAttr()) {
+  Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
+  return;
+}
+  }
   if (ShouldSuppress)
 return;
   if (FD->hasAttr()) {
Index: lib/AST/Expr.cpp
===
--- lib/AST/Expr.cpp
+++ lib/AST/Expr.cpp
@@ -2278,6 +2278,13 @@
   bool HasWarnUnusedResultAttr = Func ? Func->hasUnusedResultAttr()
   : 
FD->hasAttr();
 
+  // If there is no FunctionDecl for the call, check the return type of the
+  // callee to see if it was declared with the WarnUnusedResult attribute.
+  if (!Func && !HasWarnUnusedResultAttr) {
+if (const TagDecl *TD = CE->getCallReturnType(Ctx)->getAsTagDecl())
+  HasWarnUnusedResultAttr = TD->hasAttr();
+  }
+
   // If the callee has attribute pure, const, or warn_unused_result, warn
   // about it. void foo() { strlen("bar"); } should warn.
   //


Index: test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
===
--- test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
+++ test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
@@ -32,6 +32,35 @@
   // OK, warning suppressed.
   (void)fp();
 }
+
+namespace PR31526 {
+typedef E (*fp1)();
+typedef S (*fp2)();
+
+typedef S S_alias;
+typedef S_alias (*fp3)();
+
+typedef fp2 fp2_alias;
+
+void f() {
+  fp1 one;
+  fp2 two;
+  fp3 three;
+  fp2_alias four;
+
+  one(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+  two(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+  three(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+  four(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+
+  // These are all okay because of the explicit cast to void.
+  (void)one();
+  (void)two();
+  (void)three();
+  (void)four();
+}
+} // namespace PR31526
+
 #ifdef EXT
 // expected-warning@4 {{use of the 'nodiscard' attribute is a C++17 extension}}
 // expected-warning@8 {{use of the 'nodiscard' attribute is a C++17 extension}}
Index: lib/Sema/SemaStmt.cpp
===
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -270,6 +270,12 @@
 Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
 return;
   }
+  if (const TagDecl *TD = CE->getCallReturnType(Context)->getAsTagDecl()) {
+if (const Attr *A = TD->getAttr()) {
+  Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
+  return;
+}
+  }
   if (ShouldSuppress)
 return;
   if (FD->hasAttr()) {
Index: 

r349816 - Fix the example checker plugin after r349812.

2018-12-20 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Thu Dec 20 12:35:01 2018
New Revision: 349816

URL: http://llvm.org/viewvc/llvm-project?rev=349816=rev
Log:
Fix the example checker plugin after r349812.

Modified:
cfe/trunk/examples/analyzer-plugin/MainCallChecker.cpp

Modified: cfe/trunk/examples/analyzer-plugin/MainCallChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/analyzer-plugin/MainCallChecker.cpp?rev=349816=349815=349816=diff
==
--- cfe/trunk/examples/analyzer-plugin/MainCallChecker.cpp (original)
+++ cfe/trunk/examples/analyzer-plugin/MainCallChecker.cpp Thu Dec 20 12:35:01 
2018
@@ -45,7 +45,9 @@ void MainCallChecker::checkPreStmt(const
 // Register plugin!
 extern "C"
 void clang_registerCheckers (CheckerRegistry ) {
-  registry.addChecker("example.MainCallChecker", "Disallows 
calls to functions called main");
+  registry.addChecker(
+  "example.MainCallChecker", "Disallows calls to functions called main",
+  "");
 }
 
 extern "C"


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


r349815 - Fix build failures from r349812 due to a missing argument.

2018-12-20 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Thu Dec 20 12:32:59 2018
New Revision: 349815

URL: http://llvm.org/viewvc/llvm-project?rev=349815=rev
Log:
Fix build failures from r349812 due to a missing argument.

Modified:
cfe/trunk/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp

Modified: cfe/trunk/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp?rev=349815=349814=349815=diff
==
--- cfe/trunk/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp (original)
+++ cfe/trunk/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp Thu Dec 
20 12:32:59 2018
@@ -59,7 +59,8 @@ public:
 Compiler.getAnalyzerOpts()->CheckersControlList = {
 {"custom.CustomChecker", true}};
 AnalysisConsumer->AddCheckerRegistrationFn([](CheckerRegistry ) {
-  Registry.addChecker("custom.CustomChecker", 
"Description");
+  Registry.addChecker("custom.CustomChecker", "Description",
+ "");
 });
 return std::move(AnalysisConsumer);
   }


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


[PATCH] D51641: [VFS] Cache the current working directory for the real FS.

2018-12-20 Thread Pavel Labath via Phabricator via cfe-commits
labath added subscribers: JDevlieghere, labath.
labath added a comment.

Might I ask what was the motivation for this change? Performance optimalization?

I am asking this because this makes the RealFileSystem return bogus values for 
the CWD if it changes through means other than the 
VFS::setCurrentWorkingDirectory (which is something that, as a library, we can 
never rule out). We ran into problems with this in lldb where our tests use 
lldb as a library, and they are driven by a python scripts (which does some CWD 
changing as a part of test discovery).

If I understand the long scary comment in the `setCurrentWorkingDirectory` 
function correctly, the RealFileSystem wants to be independent of the OS notion 
of CWD. However, right now it's not doing either job very well (sharing the CWD 
with the OS nor being independent of it), because all other RFS functions will 
use the real OS CWD (as it is at the moment of the call), only 
`getCurrentWorkingDirectory` will return whatever was the last CWD set through 
the appropriate setter.


Repository:
  rC Clang

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

https://reviews.llvm.org/D51641



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


[PATCH] D55869: Convert some ObjC retain/release msgSends to runtime calls

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

This should be fine for the GNUstep runtime (the GCC runtime doesn't support 
ARC at all).  My main concern is that it will break already-released versions 
of the runtime built with a newer version of clang.  I can easily enable a new 
flag in the next release, but doing so for older ones is more problematic.


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

https://reviews.llvm.org/D55869



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


[PATCH] D55948: Modify DeclaratorChuck::getFunction to use DeclSpec for qualifiers

2018-12-20 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia created this revision.
Anastasia added a reviewer: rjmccall.
Herald added a subscriber: jfb.

Rather than duplicating data fields, use DeclSpec directly to store qualifiers 
for the functions/methods.

This change is discussed in the following comment:
https://reviews.llvm.org/D55850#inline-495037


https://reviews.llvm.org/D55948

Files:
  include/clang/Sema/DeclSpec.h
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseDeclCXX.cpp
  lib/Parse/ParseExpr.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaLambda.cpp
  lib/Sema/SemaType.cpp

Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -724,12 +724,8 @@
   /*NumArgs=*/0,
   /*EllipsisLoc=*/NoLoc,
   /*RParenLoc=*/NoLoc,
-  /*TypeQuals=*/0,
   /*RefQualifierIsLvalueRef=*/true,
   /*RefQualifierLoc=*/NoLoc,
-  /*ConstQualifierLoc=*/NoLoc,
-  /*VolatileQualifierLoc=*/NoLoc,
-  /*RestrictQualifierLoc=*/NoLoc,
   /*MutableLoc=*/NoLoc, EST_None,
   /*ESpecRange=*/SourceRange(),
   /*Exceptions=*/nullptr,
@@ -4460,7 +4456,7 @@
   // does not have a K identifier list), then the arguments are part
   // of the type, otherwise the argument list is ().
   const DeclaratorChunk::FunctionTypeInfo  = DeclType.Fun;
-  IsQualifiedFunction = FTI.TypeQuals || FTI.hasRefQualifier();
+  IsQualifiedFunction = (FTI.TypeDeclSpec && FTI.TypeDeclSpec->getTypeQualifiers()) || FTI.hasRefQualifier();
 
   // Check for auto functions and trailing return type and adjust the
   // return type accordingly.
@@ -4698,7 +4694,7 @@
 EPI.ExtInfo = EI;
 EPI.Variadic = FTI.isVariadic;
 EPI.HasTrailingReturn = FTI.hasTrailingReturnType();
-EPI.TypeQuals.addCVRUQualifiers(FTI.TypeQuals);
+EPI.TypeQuals.addCVRUQualifiers(FTI.TypeDeclSpec ? FTI.TypeDeclSpec->getTypeQualifiers() : 0);
 EPI.RefQualifier = !FTI.hasRefQualifier()? RQ_None
 : FTI.RefQualifierIsLValueRef? RQ_LValue
 : RQ_RValue;
@@ -5026,11 +5022,11 @@
 assert(Chunk.Kind == DeclaratorChunk::Function);
 if (Chunk.Fun.hasRefQualifier())
   RemovalLocs.push_back(Chunk.Fun.getRefQualifierLoc());
-if (Chunk.Fun.TypeQuals & Qualifiers::Const)
+if (Chunk.Fun.TypeDeclSpec->getTypeQualifiers() & Qualifiers::Const)
   RemovalLocs.push_back(Chunk.Fun.getConstQualifierLoc());
-if (Chunk.Fun.TypeQuals & Qualifiers::Volatile)
+if (Chunk.Fun.TypeDeclSpec->getTypeQualifiers() & Qualifiers::Volatile)
   RemovalLocs.push_back(Chunk.Fun.getVolatileQualifierLoc());
-if (Chunk.Fun.TypeQuals & Qualifiers::Restrict)
+if (Chunk.Fun.TypeDeclSpec->getTypeQualifiers() & Qualifiers::Restrict)
   RemovalLocs.push_back(Chunk.Fun.getRestrictQualifierLoc());
 if (!RemovalLocs.empty()) {
   llvm::sort(RemovalLocs,
Index: lib/Sema/SemaLambda.cpp
===
--- lib/Sema/SemaLambda.cpp
+++ lib/Sema/SemaLambda.cpp
@@ -884,8 +884,9 @@
 //   This function call operator is declared const (9.3.1) if and only if
 //   the lambda-expression's parameter-declaration-clause is not followed
 //   by mutable. It is neither virtual nor declared volatile. [...]
-if (!FTI.hasMutableQualifier())
-  FTI.TypeQuals |= DeclSpec::TQ_const;
+if (!FTI.hasMutableQualifier()) {
+  FTI.TypeDeclSpec->SetTypeQual(DeclSpec::TQ_const, SourceLocation());
+}
 
 MethodTyInfo = GetTypeForDeclarator(ParamInfo, CurScope);
 assert(MethodTyInfo && "no type from lambda-declarator");
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -8172,16 +8172,16 @@
   }
 
   DeclaratorChunk::FunctionTypeInfo  = D.getFunctionTypeInfo();
-  if (FTI.TypeQuals != 0) {
-if (FTI.TypeQuals & Qualifiers::Const)
+  if (FTI.TypeDeclSpec->getTypeQualifiers() != 0) {
+if (FTI.TypeDeclSpec->getTypeQualifiers() & Qualifiers::Const)
   Diag(D.getIdentifierLoc(), diag::err_invalid_qualified_constructor)
-<< "const" << SourceRange(D.getIdentifierLoc());
-if (FTI.TypeQuals & Qualifiers::Volatile)
+  << "const" << SourceRange(D.getIdentifierLoc());
+if (FTI.TypeDeclSpec->getTypeQualifiers() & Qualifiers::Volatile)
   Diag(D.getIdentifierLoc(), diag::err_invalid_qualified_constructor)
-<< "volatile" << SourceRange(D.getIdentifierLoc());
-if (FTI.TypeQuals & Qualifiers::Restrict)
+  << "volatile" << SourceRange(D.getIdentifierLoc());
+if (FTI.TypeDeclSpec->getTypeQualifiers() & Qualifiers::Restrict)
   Diag(D.getIdentifierLoc(), diag::err_invalid_qualified_constructor)
-<< "restrict" << 

[PATCH] D55927: [gn build] Add build file for clang/lib/Driver

2018-12-20 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D55927



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


[PATCH] D55792: Allow direct navigation to static analysis checker documentation through SARIF exports

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

Thanks for the reviews! I've commit in r349812.


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

https://reviews.llvm.org/D55792



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


  1   2   >