r251783 - [MS ABI] Don't zero-initialize vbptrs in bases

2015-11-02 Thread David Majnemer via cfe-commits
Author: majnemer
Date: Mon Nov  2 03:01:44 2015
New Revision: 251783

URL: http://llvm.org/viewvc/llvm-project?rev=251783&view=rev
Log:
[MS ABI] Don't zero-initialize vbptrs in bases

Certain CXXConstructExpr nodes require zero-initialization before a
constructor is called.  We had a bug in the case where the constructor
is called on a virtual base: we zero-initialized the base's vbptr field.
A complementary bug is present in MSVC where no zero-initialization
occurs for the subobject at all.

This fixes PR25370.

Modified:
cfe/trunk/lib/CodeGen/CGCXXABI.cpp
cfe/trunk/lib/CodeGen/CGCXXABI.h
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXXABI.cpp?rev=251783&r1=251782&r2=251783&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXXABI.cpp Mon Nov  2 03:01:44 2015
@@ -326,3 +326,7 @@ CGCXXABI::emitTerminateForUnexpectedExce
 CatchTypeInfo CGCXXABI::getCatchAllTypeInfo() {
   return CatchTypeInfo{nullptr, 0};
 }
+
+std::vector CGCXXABI::getVBPtrOffsets(const CXXRecordDecl *RD) {
+  return std::vector();
+}

Modified: cfe/trunk/lib/CodeGen/CGCXXABI.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXXABI.h?rev=251783&r1=251782&r2=251783&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCXXABI.h (original)
+++ cfe/trunk/lib/CodeGen/CGCXXABI.h Mon Nov  2 03:01:44 2015
@@ -425,6 +425,9 @@ public:
   virtual size_t getSrcArgforCopyCtor(const CXXConstructorDecl *,
   FunctionArgList &Args) const = 0;
 
+  /// Gets the offsets of all the virtual base pointers in a given class.
+  virtual std::vector getVBPtrOffsets(const CXXRecordDecl *RD);
+
   /// Gets the pure virtual member call function.
   virtual StringRef GetPureVirtualCallName() = 0;
 

Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=251783&r1=251782&r2=251783&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Mon Nov  2 03:01:44 2015
@@ -15,6 +15,7 @@
 #include "CGCUDARuntime.h"
 #include "CGCXXABI.h"
 #include "CGDebugInfo.h"
+#include "CGRecordLayout.h"
 #include "CGObjCRuntime.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
 #include "clang/Frontend/CodeGenOptions.h"
@@ -356,7 +357,35 @@ static void EmitNullBaseClassInitializat
   DestPtr = CGF.Builder.CreateElementBitCast(DestPtr, CGF.Int8Ty);
 
   const ASTRecordLayout &Layout = CGF.getContext().getASTRecordLayout(Base);
-  llvm::Value *SizeVal = CGF.CGM.getSize(Layout.getNonVirtualSize());
+  CharUnits NVSize = Layout.getNonVirtualSize();
+
+  // We cannot simply zero-initialize the entire base sub-object if vbptrs are
+  // present, they are initialized by the most derived class before calling the
+  // constructor.
+  SmallVector, 1> Stores;
+  Stores.emplace_back(CharUnits::Zero(), NVSize);
+
+  // Each store is split by the existence of a vbptr.
+  CharUnits VBPtrWidth = CGF.getPointerSize();
+  std::vector VBPtrOffsets =
+  CGF.CGM.getCXXABI().getVBPtrOffsets(Base);
+  for (CharUnits VBPtrOffset : VBPtrOffsets) {
+std::pair LastStore = Stores.pop_back_val();
+CharUnits LastStoreOffset = LastStore.first;
+CharUnits LastStoreSize = LastStore.second;
+
+CharUnits SplitBeforeOffset = LastStoreOffset;
+CharUnits SplitBeforeSize = VBPtrOffset - SplitBeforeOffset;
+assert(!SplitBeforeSize.isNegative() && "negative store size!");
+if (!SplitBeforeSize.isZero())
+  Stores.emplace_back(SplitBeforeOffset, SplitBeforeSize);
+
+CharUnits SplitAfterOffset = VBPtrOffset + VBPtrWidth;
+CharUnits SplitAfterSize = LastStoreSize - SplitAfterOffset;
+assert(!SplitAfterSize.isNegative() && "negative store size!");
+if (!SplitAfterSize.isZero())
+  Stores.emplace_back(SplitAfterOffset, SplitAfterSize);
+  }
 
   // If the type contains a pointer to data member we can't memset it to zero.
   // Instead, create a null constant and copy it to the destination.
@@ -364,14 +393,12 @@ static void EmitNullBaseClassInitializat
   // like -1, which happens to be the pattern used by member-pointers.
   // TODO: isZeroInitializable can be over-conservative in the case where a
   // virtual base contains a member pointer.
-  if (!CGF.CGM.getTypes().isZeroInitializable(Base)) {
-llvm::Constant *NullConstant = CGF.CGM.EmitNullConstantForBase(Base);
-
-llvm::GlobalVariable *NullVariable = 
-  new llvm::GlobalVariable(CGF.CGM.getModule(), NullConstant->getType(),
-   /*isConstant=*

Re: Porting Clang to a new architecture

2015-11-02 Thread Ariel Arelovich via cfe-commits
Yes!

Thank you. I've begun reading up on this, and it is effectively what I want
to do. I working on modifying LLVM code.

One question that I still can't answer is the whole standard libraries. Are
these precompiled for a given backend? Do I need to write them for my
proposed arquitecture?

Or by simply writing a  new backend everything else is done by the front
end?

I have tried asking on the cfe-devs but the list is more technical than
anything else so I don't get nay answers.

I would appreciate if anyone could point me in the direction where to read
about this. (c standard libraries in a new arquitecture)

On Sun, Nov 1, 2015 at 9:45 PM, Justin Bogner  wrote:

> Ariel Arelovich via cfe-commits  writes:
> > Great.
> >
> > So this is what I wanted to know. I think understand what you are saying.
> > You are saying that most of the work that I would need to do from the AST
> > (I'm assuming that this stands from Abstract Syntax Tree) is allready
> being
> > done by LLVM and I should look to modify for a my new arquitecture.
> Right?
>
> This is close, but a little bit off. Clang generates an AST, but then
> transforms it further into the LLVM intermediate language[1]. LLVM can
> generate code for a number of target architectures from this language.
> It sounds to me like what you want to do is write an LLVM backend for
> your target. There is some documentation[2] on how to do that, which
> should give you an idea of what you would need to do to leverage LLVM
> for your project.
>
> [1]: http://llvm.org/docs/LangRef.html
> [2]: http://llvm.org/docs/WritingAnLLVMBackend.html
>
> > If I take the AST and process it myself to generate the opcodes, I'm
> > essentially writing LLVM just less efficient (no optimizations) and
> > specific for the new architecure, right?
> >
> >
> >
> > On Mon, Oct 26, 2015 at 12:32 PM, Saleem Abdulrasool <
> compn...@compnerd.org>
> > wrote:
> >
> >> On Monday, October 26, 2015, Ariel Arelovich via cfe-commits <
> >> cfe-commits@lists.llvm.org> wrote:
> >>
> >>> Hi:
> >>>
> >>> Where I'm working I've been asked to look into developing a C (by this
> I
> >>> mean C89 C standard) compiler a new processor architecture being
> created
> >>> inhouse.
> >>>
> >>> On looking at the options and brushing up on compiler theory, I came up
> >>> with Flex/Bison, Writing the compiler from scratch or use Clang. I
> liked
> >>> this option better because parsing and and analyzing c code to
> genereate
> >>> somthing intermediate, and do this from scratch, seemed like
> reinventing
> >>> the wheel (an incredibly complex wheel, at that).
> >>>
> >>> I've figured that if Clang, works with the standard compiler flow (that
> >>> I've seen everywhere), it takes a C program and transforms it until it
> gets
> >>> a intermediate language (which is machine independant). The Dragon
> Book,
> >>> even calls this the output of the compiler Front End. From what I've
> read
> >>> from the documentation This is what Clang is: a compiler front end.
> LLVM
> >>> does optimization and translation to opcodes of known architectures. Is
> >>> this correct? Or am I getting this wrong?
> >>>
> >>
> >> Correct.  clang is just the front end for C-like languages.  It will
> parse
> >> and analyze the code (generating the AST).  The IR it generates is the
> LLVM
> >> IR.
> >>
> >> So, my question is: Would it be possible to use Clang in such a way that
> >>> it takes a C program and generates an intermediate language so that I
> can
> >>> work directly on that language to generate opcodes based on the
> >>> architecture that we are currently developing?
> >>>
> >>
> >> Yes.  This is how clang already works.  It sounds like you should be
> >> looking at LLVM, not clang since you are trying to support a new
> >> architecture, not a language feature.
> >>
> >>
> >>>
> >>> Thank you, for any answers.
> >>>
> >>> PD: I know my question might be very hard to answer as it is not very
> >>> specific. All I'm asking for, here, is a simple: "It could be done,
> start
> >>> reading about this and that" or "It will be next to impossible, just
> try
> >>> something else" (with a little explanation as to why, if that were
> >>> possible, please).
> >>>
> >>
> >>
> >> --
> >> Saleem Abdulrasool
> >> compnerd (at) compnerd (dot) org
> >>
> > ___
> > cfe-commits mailing list
> > cfe-commits@lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: Porting Clang to a new architecture

2015-11-02 Thread Joerg Sonnenberger via cfe-commits
On Mon, Oct 26, 2015 at 12:58:46PM -0300, Ariel Arelovich via cfe-commits wrote:
> So this is what I wanted to know. I think understand what you are saying.
> You are saying that most of the work that I would need to do from the AST
> (I'm assuming that this stands from Abstract Syntax Tree) is allready being
> done by LLVM and I should look to modify for a my new arquitecture. Right?

To complement Justin's reply: there are few target specific parts in
clang. It needs some ABI knowledge to layout structures etc correctly
and lower function calls (especially variadic functions) to certain
primitive forms that LLVM's IR can deal with. It may optionally provide
a bunch of intrinsincs (__builtin_* etc) and lower them to
corresponding target intrinsincs in IR. This is primarily used for
special purpose instructions and SIMD operations.

In short, the primary work for adding a new architecture is in LLVM
itself and not so much clang.

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


Re: [PATCH] D14096: [clang-tidy] add new check cppcoreguidelines-pro-type-cstyle-cast

2015-11-02 Thread Joerg Sonnenberger via cfe-commits
On Sun, Nov 01, 2015 at 08:48:53PM -0500, Aaron Ballman via cfe-commits wrote:
> On Sun, Nov 1, 2015 at 2:31 PM, Joerg Sonnenberger via cfe-commits
>  wrote:
> > On Tue, Oct 27, 2015 at 06:10:26PM +, Samuel Benzaquen via cfe-commits 
> > wrote:
> >> sbenza added a comment.
> >>
> >> In http://reviews.llvm.org/D14096#275902, @xazax.hun wrote:
> >>
> >> > There is already a similar check in the Google package. What are the 
> >> > differences between those two checks? What is the reason we can not just 
> >> > register that check into the core guidelines module?
> >>
> >>
> >> That other check discourages c-style cast in favor of C++ style casts, 
> >> even if it is a reinterpret_cast. It simply replaces the cstyle cast with 
> >> an equivalent C++ one. It is basically a stylistic check.
> >>
> >> This check will warn unsafe cstyle casts, while allowing safe ones like 
> >> int->uint casts.
> >> This one is a safety related check.
> >
> > Looking back to the discussion about the C++ style casts, this argument
> > makes no sense. For C++ code, reinterpret_cast is clearly preferable
> > over C-style casts for all but code size reasons. There seems to be no
> > consideration about "safe" uses with reinterpret_cast, so why should 
> > C-style casts
> > be different?
> 
> "Clearly preferable" is kind of debatable, but I don't disagree with
> your statement. That being said, this checker isn't concerned with
> C++-style casts, so I'm not certain I understand what you would like
> to see changed with this checker. Can you elaborate?

Let me reverse that. Do the core guidelines really define a set of
"safe" C-style casts and don't have the equivalent for C++ casts? The
latter is what I took from the follow-up on the introduction of the C++
cast checkers.

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


r251786 - [x86] Front-end part of MCU psABI support

2015-11-02 Thread Andrey Bokhanko via cfe-commits
Author: asbokhan
Date: Mon Nov  2 03:54:17 2015
New Revision: 251786

URL: http://llvm.org/viewvc/llvm-project?rev=251786&view=rev
Log:
[x86] Front-end part of MCU psABI support

This patch implements two things in front-end for MCU psABI support:

1) "long double type is the same as double."
2) "New predefined C/C++ pre-processor symbols: iamcu and iamcu__.

Differential Revision: http://reviews.llvm.org/D14205

Added:
cfe/trunk/test/Preprocessor/elfiamcu-predefines.c
Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/test/CodeGen/x86_32-arguments-iamcu.c

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=251786&r1=251785&r2=251786&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Mon Nov  2 03:54:17 2015
@@ -2335,7 +2335,8 @@ class X86TargetInfo : public TargetInfo
 public:
   X86TargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
 BigEndian = false;
-LongDoubleFormat = &llvm::APFloat::x87DoubleExtended;
+LongDoubleFormat = Triple.isOSIAMCU() ? &llvm::APFloat::IEEEdouble
+  : &llvm::APFloat::x87DoubleExtended;
   }
   unsigned getFloatEvalMethod() const override {
 // X87 evaluates with 80 bits "long double" precision.
@@ -3370,6 +3371,11 @@ void X86TargetInfo::getTargetDefines(con
   }
   if (CPU >= CK_i586)
 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
+
+  if (getTriple().isOSIAMCU()) {
+Builder.defineMacro("__iamcu");
+Builder.defineMacro("__iamcu__");
+  }
 }
 
 bool X86TargetInfo::hasFeature(StringRef Feature) const {

Modified: cfe/trunk/test/CodeGen/x86_32-arguments-iamcu.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/x86_32-arguments-iamcu.c?rev=251786&r1=251785&r2=251786&view=diff
==
--- cfe/trunk/test/CodeGen/x86_32-arguments-iamcu.c (original)
+++ cfe/trunk/test/CodeGen/x86_32-arguments-iamcu.c Mon Nov  2 03:54:17 2015
@@ -56,3 +56,7 @@ st12_t retLargeStruct(int i1, st12_t r)
 // insane.
 // CHECK-LABEL: define i32 @varArgs(i32 inreg %i1, ...)
 int varArgs(int i1, ...) { return i1; }
+
+// CHECK-LABEL: define double @longDoubleArg(double %ld1)
+long double longDoubleArg(long double ld1) { return ld1; }
+

Added: cfe/trunk/test/Preprocessor/elfiamcu-predefines.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/elfiamcu-predefines.c?rev=251786&view=auto
==
--- cfe/trunk/test/Preprocessor/elfiamcu-predefines.c (added)
+++ cfe/trunk/test/Preprocessor/elfiamcu-predefines.c Mon Nov  2 03:54:17 2015
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -E -dM -triple i586-intel-elfiamcu | FileCheck %s
+
+// CHECK: #define __iamcu
+// CHECK: #define __iamcu__
+


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


Re: [PATCH] D14205: [x86] Front-end part of MCU psABI support

2015-11-02 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL251786: [x86] Front-end part of MCU psABI support (authored 
by asbokhan).

Changed prior to commit:
  http://reviews.llvm.org/D14205?vs=38814&id=38878#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D14205

Files:
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/test/CodeGen/x86_32-arguments-iamcu.c
  cfe/trunk/test/Preprocessor/elfiamcu-predefines.c

Index: cfe/trunk/test/CodeGen/x86_32-arguments-iamcu.c
===
--- cfe/trunk/test/CodeGen/x86_32-arguments-iamcu.c
+++ cfe/trunk/test/CodeGen/x86_32-arguments-iamcu.c
@@ -56,3 +56,7 @@
 // insane.
 // CHECK-LABEL: define i32 @varArgs(i32 inreg %i1, ...)
 int varArgs(int i1, ...) { return i1; }
+
+// CHECK-LABEL: define double @longDoubleArg(double %ld1)
+long double longDoubleArg(long double ld1) { return ld1; }
+
Index: cfe/trunk/test/Preprocessor/elfiamcu-predefines.c
===
--- cfe/trunk/test/Preprocessor/elfiamcu-predefines.c
+++ cfe/trunk/test/Preprocessor/elfiamcu-predefines.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -E -dM -triple i586-intel-elfiamcu | FileCheck %s
+
+// CHECK: #define __iamcu
+// CHECK: #define __iamcu__
+
Index: cfe/trunk/lib/Basic/Targets.cpp
===
--- cfe/trunk/lib/Basic/Targets.cpp
+++ cfe/trunk/lib/Basic/Targets.cpp
@@ -2335,7 +2335,8 @@
 public:
   X86TargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
 BigEndian = false;
-LongDoubleFormat = &llvm::APFloat::x87DoubleExtended;
+LongDoubleFormat = Triple.isOSIAMCU() ? &llvm::APFloat::IEEEdouble
+  : &llvm::APFloat::x87DoubleExtended;
   }
   unsigned getFloatEvalMethod() const override {
 // X87 evaluates with 80 bits "long double" precision.
@@ -3370,6 +3371,11 @@
   }
   if (CPU >= CK_i586)
 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
+
+  if (getTriple().isOSIAMCU()) {
+Builder.defineMacro("__iamcu");
+Builder.defineMacro("__iamcu__");
+  }
 }
 
 bool X86TargetInfo::hasFeature(StringRef Feature) const {


Index: cfe/trunk/test/CodeGen/x86_32-arguments-iamcu.c
===
--- cfe/trunk/test/CodeGen/x86_32-arguments-iamcu.c
+++ cfe/trunk/test/CodeGen/x86_32-arguments-iamcu.c
@@ -56,3 +56,7 @@
 // insane.
 // CHECK-LABEL: define i32 @varArgs(i32 inreg %i1, ...)
 int varArgs(int i1, ...) { return i1; }
+
+// CHECK-LABEL: define double @longDoubleArg(double %ld1)
+long double longDoubleArg(long double ld1) { return ld1; }
+
Index: cfe/trunk/test/Preprocessor/elfiamcu-predefines.c
===
--- cfe/trunk/test/Preprocessor/elfiamcu-predefines.c
+++ cfe/trunk/test/Preprocessor/elfiamcu-predefines.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -E -dM -triple i586-intel-elfiamcu | FileCheck %s
+
+// CHECK: #define __iamcu
+// CHECK: #define __iamcu__
+
Index: cfe/trunk/lib/Basic/Targets.cpp
===
--- cfe/trunk/lib/Basic/Targets.cpp
+++ cfe/trunk/lib/Basic/Targets.cpp
@@ -2335,7 +2335,8 @@
 public:
   X86TargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
 BigEndian = false;
-LongDoubleFormat = &llvm::APFloat::x87DoubleExtended;
+LongDoubleFormat = Triple.isOSIAMCU() ? &llvm::APFloat::IEEEdouble
+  : &llvm::APFloat::x87DoubleExtended;
   }
   unsigned getFloatEvalMethod() const override {
 // X87 evaluates with 80 bits "long double" precision.
@@ -3370,6 +3371,11 @@
   }
   if (CPU >= CK_i586)
 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
+
+  if (getTriple().isOSIAMCU()) {
+Builder.defineMacro("__iamcu");
+Builder.defineMacro("__iamcu__");
+  }
 }
 
 bool X86TargetInfo::hasFeature(StringRef Feature) const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: Porting Clang to a new architecture

2015-11-02 Thread Joerg Sonnenberger via cfe-commits
On Mon, Nov 02, 2015 at 06:30:07AM -0300, Ariel Arelovich via cfe-commits wrote:
> One question that I still can't answer is the whole standard libraries. Are
> these precompiled for a given backend? Do I need to write them for my
> proposed arquitecture?
> 
> Or by simply writing a  new backend everything else is done by the front
> end?

Depends on what you mean by standard library. compiler-rt provides
(most) of what LLVM may use in terms of library calls. This is primarily
used for some complex high level functions like complex division and for
things missing from the instruction set, e.g. if there is no 64bit
division operation, a function call will be generated by the backend.
LLVM does not provide a libc. That's a completely different topic.

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


Re: [PATCH] D14205: [x86] Front-end part of MCU psABI support

2015-11-02 Thread Andrey Bokhanko via cfe-commits
andreybokhanko added a comment.

Michael,

Thanks for the review!

As for your comment, I will investigate and fix (if needed).

Andrey



Comment at: lib/Basic/Targets.cpp:2327
@@ -2325,3 +2326,3 @@
 // X87 evaluates with 80 bits "long double" precision.
 return SSELevel == NoSSE ? 2 : 0;
   }

mkuper wrote:
> Do you know if we should also change this to be 0?
Good catch.

Let me investigate and change (if needed) in another patch.


Repository:
  rL LLVM

http://reviews.llvm.org/D14205



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


[PATCH] D14224: Added processing of several AST nodes in ASTNodeImporter.

2015-11-02 Thread Serge Pavlov via cfe-commits
sepavloff created this revision.
sepavloff added a subscriber: cfe-commits.

http://reviews.llvm.org/D14224

Files:
  lib/AST/ASTImporter.cpp
  test/ASTMerge/Inputs/class3.cpp
  test/ASTMerge/Inputs/exprs3.cpp
  test/ASTMerge/class2.cpp
  test/ASTMerge/exprs.cpp

Index: test/ASTMerge/exprs.cpp
===
--- /dev/null
+++ test/ASTMerge/exprs.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++1z -fcxx-exceptions -emit-pch -o %t.1.ast %S/Inputs/exprs3.cpp
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++1z -fcxx-exceptions -ast-merge %t.1.ast -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+static_assert(Ch1 == 'a');
+static_assert(Ch2 == 'b');
+static_assert(Ch3 == 'c');
+
+static_assert(Ch4 == L'd');
+static_assert(Ch5 == L'e');
+static_assert(Ch6 == L'f');
+
+static_assert(C1 == 12);
+static_assert(C2 == 13);
+
+static_assert(C3 == 12);
+static_assert(C4 == 13);
+
+static_assert(C5 == 22L);
+static_assert(C6 == 23L);
+
+static_assert(C7 == 66LL);
+static_assert(C8 == 67ULL);
+
+static_assert(bval1 == true);
+static_assert(bval2 == false);
Index: test/ASTMerge/class2.cpp
===
--- /dev/null
+++ test/ASTMerge/class2.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++1z -emit-pch -o %t.1.ast %S/Inputs/class3.cpp
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++1z -ast-merge %t.1.ast -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+class C3 {
+  int method_1(C2 *x) {
+return x->x;
+  }
+};
Index: test/ASTMerge/Inputs/exprs3.cpp
===
--- /dev/null
+++ test/ASTMerge/Inputs/exprs3.cpp
@@ -0,0 +1,92 @@
+// Integer literals
+const char Ch1 = 'a';
+const signed char Ch2 = 'b';
+const unsigned char Ch3 = 'c';
+
+const wchar_t Ch4 = L'd';
+const signed wchar_t Ch5 = L'e';
+const unsigned wchar_t Ch6 = L'f';
+
+const short C1 = 12;
+const unsigned short C2 = 13;
+
+const int C3 = 12;
+const unsigned int C4 = 13;
+
+const long C5 = 22;
+const unsigned long C6 = 23;
+
+const long long C7 = 66;
+const unsigned long long C8 = 67;
+
+
+// String literals
+const char str1[] = "ABCD";
+const char str2[] = "ABCD" "0123";
+
+const wchar_t wstr1[] = L"DEF";
+const wchar_t wstr2[] = L"DEF" L"123";
+
+
+// Boolean literals
+const bool bval1 = true;
+const bool bval2 = false;
+
+// Floating Literals
+const float F1 = 12.2F;
+const double F2 = 1E4;
+const long double F3 = 1.2E-3L;
+
+
+// nullptr literal
+const void *vptr = nullptr;
+
+
+int glb_1[4] = { 10, 20, 30, 40 };
+
+struct S1 {
+  int a;
+  int b[3];
+};
+
+struct S2 {
+  int c;
+  S1 d;
+};
+
+S2 glb_2 = { 22, .d.a = 44, .d.b[0] = 55, .d.b[1] = 66 };
+
+void func() {
+  throw;
+  char *p = new char[10];
+  delete[] p;
+}
+
+int func_2(int *x, int n) {
+  return x[n];
+}
+
+int func_3(int c, int x, int y) {
+  return c ? x : y;
+}
+
+S1 &func_4(const S1 &x) {
+  return const_cast(x);
+}
+
+S1 &func_5(S1 &x) {
+  return static_cast(x);
+}
+
+S1 &func_6(S1 &x) {
+  return reinterpret_cast(x);
+}
+
+S1 &func_7(S1 &x) {
+  return dynamic_cast(x);
+}
+
+int func_8(int x) {
+  return int(x);
+}
+
Index: test/ASTMerge/Inputs/class3.cpp
===
--- /dev/null
+++ test/ASTMerge/Inputs/class3.cpp
@@ -0,0 +1,23 @@
+class C1 {
+public:
+  C1();
+  ~C1();
+  C1 *method_1() {
+return this;
+  }
+  C1 method_2() {
+return C1();
+  }
+  void method_3() {
+const C1 &ref = C1();
+  }
+};
+
+class C11 : public C1 {
+};
+
+class C2 {
+  int x;
+  friend class C3;
+  static_assert(sizeof(x) == sizeof(int), "Error");
+};
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -169,6 +169,9 @@
 ClassTemplateSpecializationDecl *D);
 Decl *VisitVarTemplateDecl(VarTemplateDecl *D);
 Decl *VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D);
+Decl *VisitFriendDecl(FriendDecl *D);
+Decl *VisitAccessSpecDecl(AccessSpecDecl *D);
+Decl *VisitStaticAssertDecl(StaticAssertDecl *D);
 
 // Importing statements
 DeclGroupRef ImportDeclGroup(DeclGroupRef DG);
@@ -211,20 +214,43 @@
 Stmt *VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S);
 
 // Importing expressions
+bool ImportCastPath(CastExpr *E, CXXCastPath &Path);
+
 Expr *VisitExpr(Expr *E);
 Expr *VisitDeclRefExpr(DeclRefExpr *E);
 Expr *VisitIntegerLiteral(IntegerLiteral *E);
 Expr *VisitCharacterLiteral(CharacterLiteral *E);
+Expr *VisitStringLiteral(StringLiteral *E);
+Expr *VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
+Expr *VisitFloatingLiteral(FloatingLiteral *E);
+Expr *VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
+Expr *VisitCXXThisExpr(CXXThisExpr *E);
+Expr

Re: [PATCH] D14198: Make the modernize-loop-convert's const-detection smarter.

2015-11-02 Thread Angel Garcia via cfe-commits
angelgarcia added a comment.

> Reading just this function, it is unclear what the 'container' is.


It should be clearer now.

> Can't CaptureBuRef be modified?


I added a comment with an explanation.

> But they are aliases. Shouldn't we then go into the const-ness of the


aliases?
I wanted to test that if we take a non-const reference, we recognize that
it is a non-const usage. But if we only do it once, the check handles it
differently because it moves that declaration to the loop's statement. I
added a few tests with this particular case as well (they don't harm).

In the case of const-references, we don't need to go through their usages
to know that they won't be modified. If the reference is non-const, even if
it is used in a const way, I don't think we should do anything about it.
That would only make things more complicated: first, we would need to
traverse the subtree again looking for usages of the reference; then, if we
decide that it is not modified and we take a const-reference of the
container's element, we should also change the declaration of the reference
to make it const.


http://reviews.llvm.org/D14198



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


Re: [PATCH] D14198: Make the modernize-loop-convert's const-detection smarter.

2015-11-02 Thread Angel Garcia via cfe-commits
angelgarcia updated this revision to Diff 38881.
angelgarcia added a comment.

Improve comments and add more tests.


http://reviews.llvm.org/D14198

Files:
  clang-tidy/modernize/LoopConvertCheck.cpp
  test/clang-tidy/modernize-loop-convert-basic.cpp
  test/clang-tidy/modernize-loop-convert-camelback.cpp
  test/clang-tidy/modernize-loop-convert-const.cpp
  test/clang-tidy/modernize-loop-convert-extra.cpp
  test/clang-tidy/modernize-loop-convert-lowercase.cpp
  test/clang-tidy/modernize-loop-convert-uppercase.cpp

Index: test/clang-tidy/modernize-loop-convert-uppercase.cpp
===
--- test/clang-tidy/modernize-loop-convert-uppercase.cpp
+++ test/clang-tidy/modernize-loop-convert-uppercase.cpp
@@ -14,61 +14,61 @@
 printf("%d\n", ARR[I]);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert]
-  // CHECK-FIXES: for (int & ELEM : ARR)
+  // CHECK-FIXES: for (int ELEM : ARR)
   // CHECK-FIXES-NEXT: printf("%d\n", ELEM);
 
   for (int I = 0; I < N; ++I) {
 printf("%d\n", NUMS[I]);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & NUM : NUMS)
+  // CHECK-FIXES: for (int NUM : NUMS)
   // CHECK-FIXES-NEXT: printf("%d\n", NUM);
 
   for (int I = 0; I < N; ++I) {
 printf("%d\n", NUMS_[I]);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & NUM : NUMS_)
+  // CHECK-FIXES: for (int NUM : NUMS_)
   // CHECK-FIXES-NEXT: printf("%d\n", NUM);
 
   int NUM = 0;
   for (int I = 0; I < N; ++I) {
 printf("%d\n", NUMS[I] + NUM);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & ELEM : NUMS)
+  // CHECK-FIXES: for (int ELEM : NUMS)
   // CHECK-FIXES-NEXT: printf("%d\n", ELEM + NUM);
 
   int ELEM = 0;
   for (int I = 0; I < N; ++I) {
 printf("%d\n", NUMS[I] + NUM + ELEM);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & NUMS_I : NUMS)
+  // CHECK-FIXES: for (int NUMS_I : NUMS)
   // CHECK-FIXES-NEXT: printf("%d\n", NUMS_I + NUM + ELEM);
 
   int NUMS_I = 0;
   for (int I = 0; I < N; ++I) {
 printf("%d\n", NUMS[I] + NUM + ELEM + NUMS_I);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & NUMS_ELEM : NUMS)
+  // CHECK-FIXES: for (int NUMS_ELEM : NUMS)
   // CHECK-FIXES-NEXT: printf("%d\n", NUMS_ELEM + NUM + ELEM + NUMS_I);
 
   int NUMS_ELEM = 0;
   for (int I = 0; I < N; ++I) {
 printf("%d\n", NUMS[I] + NUM + ELEM + NUMS_I + NUMS_ELEM);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & GIVE_ME_NAME_0 : NUMS)
+  // CHECK-FIXES: for (int GIVE_ME_NAME_0 : NUMS)
   // CHECK-FIXES-NEXT: printf("%d\n", GIVE_ME_NAME_0 + NUM + ELEM + NUMS_I + NUMS_ELEM);
 
   int GIVE_ME_NAME_0 = 0;
   for (int I = 0; I < N; ++I) {
 printf("%d\n", NUMS[I] + NUM + ELEM + NUMS_I + NUMS_ELEM + GIVE_ME_NAME_0);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & GIVE_ME_NAME_1 : NUMS)
+  // CHECK-FIXES: for (int GIVE_ME_NAME_1 : NUMS)
   // CHECK-FIXES-NEXT: printf("%d\n", GIVE_ME_NAME_1 + NUM + ELEM + NUMS_I + NUMS_ELEM + GIVE_ME_NAME_0);
 
   int NUMS_J = 0;
@@ -79,7 +79,7 @@
   }
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
   // CHECK-MESSAGES: :[[@LINE-5]]:5: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & GIVE_ME_NAME_0 : NUMS)
-  // CHECK-FIXES: for (int & GIVE_ME_NAME_1 : NUMS)
+  // CHECK-FIXES: for (int GIVE_ME_NAME_0 : NUMS)
+  // CHECK-FIXES: for (int GIVE_ME_NAME_1 : NUMS)
   // CHECK-FIXES-NEXT: printf("%d\n", GIVE_ME_NAME_0 + GIVE_ME_NAME_1 + NUM + ELEM + NUMS_I + NUMS_J + NUMS_ELEM);
 }
Index: test/clang-tidy/modernize-loop-convert-lowercase.cpp
===
--- test/clang-tidy/modernize-loop-convert-lowercase.cpp
+++ test/clang-tidy/modernize-loop-convert-lowercase.cpp
@@ -14,61 +14,61 @@
 printf("%d\n", arr[i]);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert]
-  // CHECK-FIXES: for (int & elem : arr)
+  // CHECK-FIXES: for (int elem : arr)
   // CHECK-FIXES-NEXT: printf("%d\n", elem);
 
   for (int i = 0; i < n; ++i) {
 printf("%d\n", nums[i]);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & num : nums)
+  // CHECK-FIXES: for (int num : nums)
   // CHECK-FIXES-NEXT: printf("%d\n", num);
 
   for (int i = 0; i < n; ++i) {
 printf("%d\n", nums_[i]);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & num : nums_)
+  // CHECK-FIXES: for (int 

[clang-tools-extra] r251788 - modernize-use-default supports copy constructor and copy-assignment operator.

2015-11-02 Thread Angel Garcia Gomez via cfe-commits
Author: angelgarcia
Date: Mon Nov  2 04:34:19 2015
New Revision: 251788

URL: http://llvm.org/viewvc/llvm-project?rev=251788&view=rev
Log:
modernize-use-default supports copy constructor and copy-assignment operator.

Summary: the check will now warn when the user provided definitions of this 
functions is equivalent to the explicitly defaulted ones.

Reviewers: klimek

Subscribers: klimek, cfe-commits, alexfh

Differential Revision: http://reviews.llvm.org/D14145

Added:
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-copy.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp?rev=251788&r1=251787&r2=251788&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp Mon Nov  2 
04:34:19 2015
@@ -10,6 +10,7 @@
 #include "UseDefaultCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
 
@@ -17,45 +18,302 @@ namespace clang {
 namespace tidy {
 namespace modernize {
 
-static const char CtorDtor[] = "CtorDtorDecl";
+static const char SpecialFunction[] = "SpecialFunction";
+
+/// \brief Finds the SourceLocation of the colon ':' before the initialization
+/// list in the definition of a constructor.
+static SourceLocation getColonLoc(const ASTContext *Context,
+  const CXXConstructorDecl *Ctor) {
+  // FIXME: First init is the first initialization that is going to be
+  // performed, no matter what was the real order in the source code. If the
+  // order of the inits is wrong in the code, it may result in a false 
negative.
+  SourceLocation FirstInit = (*Ctor->init_begin())->getSourceLocation();
+  SourceLocation LastArg =
+  Ctor->getParamDecl(Ctor->getNumParams() - 1)->getLocEnd();
+  // We need to find the colon between the ')' and the first initializer.
+  bool Invalid = false;
+  StringRef Text = Lexer::getSourceText(
+  CharSourceRange::getCharRange(LastArg, FirstInit),
+  Context->getSourceManager(), Context->getLangOpts(), &Invalid);
+  if (Invalid)
+return SourceLocation();
+
+  size_t ColonPos = Text.rfind(':');
+  if (ColonPos == StringRef::npos)
+return SourceLocation();
+
+  Text = Text.drop_front(ColonPos + 1);
+  if (std::strspn(Text.data(), " \t\r\n") != Text.size()) {
+// If there are comments, preprocessor directives or anything, abort.
+return SourceLocation();
+  }
+  // FIXME: don't remove comments in the middle of the initializers.
+  return LastArg.getLocWithOffset(ColonPos);
+}
+
+/// \brief Finds all the named non-static fields of \p Record.
+static std::set
+getAllNamedFields(const CXXRecordDecl *Record) {
+  std::set Result;
+  for (const auto *Field : Record->fields()) {
+// Static data members are not in this range.
+if (Field->isUnnamedBitfield())
+  continue;
+Result.insert(Field);
+  }
+  return Result;
+}
+
+/// \brief Returns the names of the direct bases of \p Record, both virtual and
+/// non-virtual.
+static std::set getAllDirectBases(const CXXRecordDecl *Record) {
+  std::set Result;
+  for (auto Base : Record->bases()) {
+// CXXBaseSpecifier.
+const auto *BaseType = Base.getTypeSourceInfo()->getType().getTypePtr();
+Result.insert(BaseType);
+  }
+  return Result;
+}
+
+/// \brief Returns a matcher that matches member expressions where the base is
+/// the variable declared as \p Var and the accessed member is the one declared
+/// as \p Field.
+internal::Matcher accessToFieldInVar(const FieldDecl *Field,
+   const ValueDecl *Var) {
+  return ignoringImpCasts(
+  
memberExpr(hasObjectExpression(declRefExpr(to(varDecl(equalsNode(Var),
+ member(fieldDecl(equalsNode(Field);
+}
+
+/// \brief Check that the given constructor has copy signature and that it
+/// copy-initializes all its bases and members.
+static bool isCopyConstructorAndCanBeDefaulted(ASTContext *Context,
+   const CXXConstructorDecl *Ctor) 
{
+  // An explicitly-defaulted constructor cannot have default arguments.
+  if (Ctor->getMinRequiredArguments() != 1)
+return false;
+
+  const auto *Record = Ctor->getParent();
+  const auto *Param = Ctor->getParamDecl(0);
+
+  // Base classes and members that have to be copied.
+  auto BasesToInit = getAllDirectBases(Record);
+  auto FieldsToInit = getAllNamedFields(Record);
+
+  // Ensure that all the bases are copied.
+  for (const auto *Base : BasesToInit) {
+// The initialization of a bas

Re: [PATCH] D13351: [Power PC] add soft float support for ppc32

2015-11-02 Thread Strahinja Petrovic via cfe-commits
spetrovic updated this revision to Diff 38882.
spetrovic marked 5 inline comments as done.
spetrovic added a comment.

Comments addressed.


http://reviews.llvm.org/D13351

Files:
  lib/CodeGen/TargetInfo.cpp
  lib/Driver/Tools.cpp
  lib/Driver/Tools.h
  test/CodeGen/ppc-sfvarargs.c
  test/Driver/ppc-features.cpp

Index: test/Driver/ppc-features.cpp
===
--- test/Driver/ppc-features.cpp
+++ test/Driver/ppc-features.cpp
@@ -12,6 +12,30 @@
 // RUN: not %clang -target mips64-linux-gnu -faltivec -fsyntax-only %s 2>&1 | FileCheck %s
 // RUN: not %clang -target sparc-unknown-solaris -faltivec -fsyntax-only %s 2>&1 | FileCheck %s
 
+// check -msoft-float option for ppc32
+// RUN: %clang -target powerpc-unknown-linux-gnu %s -msoft-float -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-SOFTFLOAT %s
+// CHECK-SOFTFLOAT: "-target-feature" "+soft-float"
+
+// check -mfloat-abi=soft option for ppc32
+// RUN: %clang -target powerpc-unknown-linux-gnu %s -mfloat-abi=soft -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-FLOATABISOFT %s
+// CHECK-FLOATABISOFT: "-target-feature" "+soft-float"
+
+// check -mhard-float option for ppc32
+// RUN: %clang -target powerpc-unknown-linux-gnu %s -mhard-float -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-HARDFLOAT %s
+// CHECK-HARDFLOAT-NOT: "-target-feature" "+soft-float"
+
+// check -mfloat-abi=hard option for ppc32
+// RUN: %clang -target powerpc-unknown-linux-gnu %s -mfloat-abi=hard -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-FLOATABIHARD %s
+// CHECK-FLOATABIHARD-NOT: "-target-feature" "+soft-float"
+
+// check combine -mhard-float -msoft-float option for ppc32
+// RUN: %clang -target powerpc-unknown-linux-gnu %s -mhard-float -msoft-float -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-HARDSOFT %s
+// CHECK-HARDSOFT: "-target-feature" "+soft-float"
+
+// check combine -msoft-float -mhard-float option for ppc32
+// RUN: %clang -target powerpc-unknown-linux-gnu %s -msoft-float -mhard-float -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-SOFTHARD %s
+// CHECK-SOFTHARD-NOT: "-target-feature" "+soft-float"
+
 // CHECK: invalid argument '-faltivec' only allowed with 'ppc/ppc64/ppc64le'
 
 // Check that -fno-altivec and -mno-altivec correctly disable the altivec
Index: test/CodeGen/ppc-sfvarargs.c
===
--- test/CodeGen/ppc-sfvarargs.c
+++ test/CodeGen/ppc-sfvarargs.c
@@ -0,0 +1,17 @@
+// RUN: %clang -O0 --target=powerpc-unknown-linux-gnu -EB -msoft-float -S -emit-llvm %s -o - | FileCheck %s
+
+#include 
+void test(char *fmt, ...) {
+  va_list ap;
+  va_start(ap, fmt);
+  va_arg(ap, double);
+  va_end(ap);
+}
+
+void foo() {
+  double a;
+  test("test",a);
+}
+// CHECK: %{{[0-9]+}} = add i8 %numUsedRegs, 1
+// CHECK: %{{[0-9]+}} = and i8 %{{[0-9]+}}, -2
+// CHECK: %{{[0-9]+}} = mul i8 %{{[0-9]+}}, 4
\ No newline at end of file
Index: lib/Driver/Tools.h
===
--- lib/Driver/Tools.h
+++ lib/Driver/Tools.h
@@ -731,6 +731,16 @@
 
 FloatABI getARMFloatABI(const ToolChain &TC, const llvm::opt::ArgList &Args);
 }
+
+namespace ppc {
+enum class FloatABI {
+  Invalid,
+  Soft,
+  SoftFP,
+  Hard,
+};
+   ppc::FloatABI getPPCFloatABI(const Driver &D, const llvm::opt::ArgList &Args);
+}
 namespace XCore {
 // For XCore, we do not need to instantiate tools for PreProcess, PreCompile and
 // Compile.
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -1325,7 +1325,7 @@
   return "";
 }
 
-static void getPPCTargetFeatures(const ArgList &Args,
+static void getPPCTargetFeatures(const Driver &D, const ArgList &Args,
  std::vector &Features) {
   for (const Arg *A : Args.filtered(options::OPT_m_ppc_Features_Group)) {
 StringRef Name = A->getOption().getName();
@@ -1345,15 +1345,48 @@
 // TODO: Change the LLVM backend option maybe?
 if (Name == "mfcrf")
   Name = "mfocrf";
-
+
 Features.push_back(Args.MakeArgString((IsNegative ? "-" : "+") + Name));
   }
 
+  ppc::FloatABI FloatABI = ppc::getPPCFloatABI(D, Args);
+  if (FloatABI == ppc::FloatABI::Soft)
+Features.push_back("+soft-float");
+  
   // Altivec is a bit weird, allow overriding of the Altivec feature here.
   AddTargetFeature(Args, Features, options::OPT_faltivec,
options::OPT_fno_altivec, "altivec");
 }
 
+ppc::FloatABI ppc::getPPCFloatABI(const Driver &D, const ArgList &Args) {
+  ppc::FloatABI ABI = ppc::FloatABI::Invalid;
+  if (Arg *A = Args.getLastArg(options::OPT_msoft_float,
+  options::OPT_mhard_float,
+  options::OPT_mfloat_abi_EQ)) {
+if (A->getOption().matches(options::OPT_msoft_float))
+  ABI = ppc::FloatABI::Soft;
+else if (A->getOption().matches(options::OPT_mhard_float))
+  ABI = 

[PATCH] D14225: Try to fix buildbots failure.

2015-11-02 Thread Angel Garcia via cfe-commits
angelgarcia created this revision.
angelgarcia added a subscriber: cfe-commits.

Add -fexceptions flag to enable exceptions.

http://reviews.llvm.org/D14225

Files:
  test/clang-tidy/modernize-use-default-copy.cpp
  test/clang-tidy/modernize-use-default.cpp

Index: test/clang-tidy/modernize-use-default.cpp
===
--- test/clang-tidy/modernize-use-default.cpp
+++ test/clang-tidy/modernize-use-default.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s modernize-use-default %t -- -- -std=c++11 
-fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s modernize-use-default %t -- -- -std=c++11 
-fno-delayed-template-parsing  -fexceptions
 
 // Out of line definition.
 class OL {
Index: test/clang-tidy/modernize-use-default-copy.cpp
===
--- test/clang-tidy/modernize-use-default-copy.cpp
+++ test/clang-tidy/modernize-use-default-copy.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s modernize-use-default %t -- -- -std=c++11 
-fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s modernize-use-default %t -- -- -std=c++11 
-fno-delayed-template-parsing -fexceptions
 
 // Out of line definition.
 struct OL {


Index: test/clang-tidy/modernize-use-default.cpp
===
--- test/clang-tidy/modernize-use-default.cpp
+++ test/clang-tidy/modernize-use-default.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s modernize-use-default %t -- -- -std=c++11 -fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s modernize-use-default %t -- -- -std=c++11 -fno-delayed-template-parsing  -fexceptions
 
 // Out of line definition.
 class OL {
Index: test/clang-tidy/modernize-use-default-copy.cpp
===
--- test/clang-tidy/modernize-use-default-copy.cpp
+++ test/clang-tidy/modernize-use-default-copy.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s modernize-use-default %t -- -- -std=c++11 -fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s modernize-use-default %t -- -- -std=c++11 -fno-delayed-template-parsing -fexceptions
 
 // Out of line definition.
 struct OL {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r251790 - Try to fix buildbots failure.

2015-11-02 Thread Angel Garcia Gomez via cfe-commits
Author: angelgarcia
Date: Mon Nov  2 04:54:50 2015
New Revision: 251790

URL: http://llvm.org/viewvc/llvm-project?rev=251790&view=rev
Log:
Try to fix buildbots failure.

Summary: Add -fexceptions flag to enable exceptions.

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D14225

Modified:
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-copy.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-copy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-copy.cpp?rev=251790&r1=251789&r2=251790&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-copy.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-copy.cpp Mon 
Nov  2 04:54:50 2015
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s modernize-use-default %t -- -- -std=c++11 
-fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s modernize-use-default %t -- -- -std=c++11 
-fno-delayed-template-parsing -fexceptions
 
 // Out of line definition.
 struct OL {

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp?rev=251790&r1=251789&r2=251790&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp Mon Nov  
2 04:54:50 2015
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s modernize-use-default %t -- -- -std=c++11 
-fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s modernize-use-default %t -- -- -std=c++11 
-fno-delayed-template-parsing  -fexceptions
 
 // Out of line definition.
 class OL {


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


Re: [PATCH] D14225: Try to fix buildbots failure.

2015-11-02 Thread Angel Garcia via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL251790: Try to fix buildbots failure. (authored by 
angelgarcia).

Changed prior to commit:
  http://reviews.llvm.org/D14225?vs=38885&id=38886#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D14225

Files:
  clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-copy.cpp
  clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp

Index: clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-copy.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-copy.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-copy.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s modernize-use-default %t -- -- -std=c++11 
-fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s modernize-use-default %t -- -- -std=c++11 
-fno-delayed-template-parsing -fexceptions
 
 // Out of line definition.
 struct OL {
Index: clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s modernize-use-default %t -- -- -std=c++11 
-fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s modernize-use-default %t -- -- -std=c++11 
-fno-delayed-template-parsing  -fexceptions
 
 // Out of line definition.
 class OL {


Index: clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-copy.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-copy.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-copy.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s modernize-use-default %t -- -- -std=c++11 -fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s modernize-use-default %t -- -- -std=c++11 -fno-delayed-template-parsing -fexceptions
 
 // Out of line definition.
 struct OL {
Index: clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s modernize-use-default %t -- -- -std=c++11 -fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s modernize-use-default %t -- -- -std=c++11 -fno-delayed-template-parsing  -fexceptions
 
 // Out of line definition.
 class OL {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D14204: Fix crash in redundant-void-arg check.

2015-11-02 Thread Angel Garcia via cfe-commits
angelgarcia updated this revision to Diff 38887.
angelgarcia added a comment.

Use Lexer::makeFileCharRange (and a few changes due to clang-format).

It seems to work as well.


http://reviews.llvm.org/D14204

Files:
  clang-tidy/modernize/RedundantVoidArgCheck.cpp
  test/clang-tidy/modernize-redundant-void-arg.cpp

Index: test/clang-tidy/modernize-redundant-void-arg.cpp
===
--- test/clang-tidy/modernize-redundant-void-arg.cpp
+++ test/clang-tidy/modernize-redundant-void-arg.cpp
@@ -417,3 +417,13 @@
   // CHECK-MESSAGES: [[@LINE-2]]:45: warning: {{.*}} in lambda expression
   // CHECK-FIXES: {{^  }}auto void_returner = []() -> void (*)() { return f1; 
};{{$}}
 }
+
+#define F(A, B)\
+  struct F_##A##_##B { \
+F_##A##_##B(void); \
+  };   \
+  F_##A##_##B::F_##A##_##B(void)
+
+F(Foo, Bar) {
+
+}
Index: clang-tidy/modernize/RedundantVoidArgCheck.cpp
===
--- clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -47,8 +47,8 @@
 
 void RedundantVoidArgCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(functionDecl(isExpansionInMainFile(), parameterCountIs(0),
-  unless(isImplicit()),
-  unless(isExternC())).bind(FunctionId),
+  unless(isImplicit()), unless(isExternC()))
+ .bind(FunctionId),
  this);
   Finder->addMatcher(typedefDecl(isExpansionInMainFile()).bind(TypedefId),
  this);
@@ -77,9 +77,10 @@
   cxxReinterpretCastExpr(isExpansionInMainFile(), 
CastDestinationIsFunction)
   .bind(NamedCastId),
   this);
-  Finder->addMatcher(cxxConstCastExpr(isExpansionInMainFile(),
-   
CastDestinationIsFunction).bind(NamedCastId),
- this);
+  Finder->addMatcher(
+  cxxConstCastExpr(isExpansionInMainFile(), CastDestinationIsFunction)
+  .bind(NamedCastId),
+  this);
   Finder->addMatcher(lambdaExpr(isExpansionInMainFile()).bind(LambdaId), this);
 }
 
@@ -128,11 +129,14 @@
 void RedundantVoidArgCheck::removeVoidArgumentTokens(
 const ast_matchers::MatchFinder::MatchResult &Result, SourceRange Range,
 StringRef GrammarLocation) {
-  std::string DeclText =
-  Lexer::getSourceText(CharSourceRange::getTokenRange(Range),
-   *Result.SourceManager,
-   Result.Context->getLangOpts()).str();
-  Lexer PrototypeLexer(Range.getBegin(), Result.Context->getLangOpts(),
+  CharSourceRange CharRange = Lexer::makeFileCharRange(
+  CharSourceRange::getTokenRange(Range), *Result.SourceManager,
+  Result.Context->getLangOpts());
+
+  std::string DeclText = Lexer::getSourceText(CharRange, *Result.SourceManager,
+  Result.Context->getLangOpts())
+ .str();
+  Lexer PrototypeLexer(CharRange.getBegin(), Result.Context->getLangOpts(),
DeclText.data(), DeclText.data(),
DeclText.data() + DeclText.size());
   enum TokenState {


Index: test/clang-tidy/modernize-redundant-void-arg.cpp
===
--- test/clang-tidy/modernize-redundant-void-arg.cpp
+++ test/clang-tidy/modernize-redundant-void-arg.cpp
@@ -417,3 +417,13 @@
   // CHECK-MESSAGES: [[@LINE-2]]:45: warning: {{.*}} in lambda expression
   // CHECK-FIXES: {{^  }}auto void_returner = []() -> void (*)() { return f1; };{{$}}
 }
+
+#define F(A, B)\
+  struct F_##A##_##B { \
+F_##A##_##B(void); \
+  };   \
+  F_##A##_##B::F_##A##_##B(void)
+
+F(Foo, Bar) {
+
+}
Index: clang-tidy/modernize/RedundantVoidArgCheck.cpp
===
--- clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -47,8 +47,8 @@
 
 void RedundantVoidArgCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(functionDecl(isExpansionInMainFile(), parameterCountIs(0),
-  unless(isImplicit()),
-  unless(isExternC())).bind(FunctionId),
+  unless(isImplicit()), unless(isExternC()))
+ .bind(FunctionId),
  this);
   Finder->addMatcher(typedefDecl(isExpansionInMainFile()).bind(TypedefId),
  this);
@@ -77,9 +77,10 @@
   cxxReinterpretCastExpr(isExpansionInMainFile(), CastDestinationIsFunction)
   .bind(NamedCastId),
   this);
-  Finder->addMatcher(cxxConstCastExpr(isExpansionInMainFile(),
-   CastDestinationIsFunction).bind(NamedCastId),
- this);
+  Finder->addMatcher(
+  cx

Re: [PATCH] D14204: Fix crash in redundant-void-arg check.

2015-11-02 Thread Alexander Kornienko via cfe-commits
alexfh added a comment.

In http://reviews.llvm.org/D14204#278833, @angelgarcia wrote:

> Use Lexer::makeFileCharRange (and a few changes due to clang-format).
>
> It seems to work as well.


Can you add a test where a void argument is removed in a macro (which would be 
the whole point of using the makeFileCharRange instead of just bailing out on 
all macros)?

E.g. does this work in a simple case like this one?

  #define M(x) x
  M(void f(void) {})
  // CHECK-FIXES: M(void f() {})


http://reviews.llvm.org/D14204



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


Re: [PATCH] D13351: [Power PC] add soft float support for ppc32

2015-11-02 Thread Strahinja Petrovic via cfe-commits
spetrovic updated this revision to Diff 3.
spetrovic added a comment.

added test case


http://reviews.llvm.org/D13351

Files:
  lib/CodeGen/TargetInfo.cpp
  lib/Driver/Tools.cpp
  lib/Driver/Tools.h
  test/CodeGen/ppc-sfvarargs.c
  test/Driver/ppc-features.cpp

Index: test/Driver/ppc-features.cpp
===
--- test/Driver/ppc-features.cpp
+++ test/Driver/ppc-features.cpp
@@ -12,6 +12,34 @@
 // RUN: not %clang -target mips64-linux-gnu -faltivec -fsyntax-only %s 2>&1 | FileCheck %s
 // RUN: not %clang -target sparc-unknown-solaris -faltivec -fsyntax-only %s 2>&1 | FileCheck %s
 
+// check -msoft-float option for ppc32
+// RUN: %clang -target powerpc-unknown-linux-gnu %s -msoft-float -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-SOFTFLOAT %s
+// CHECK-SOFTFLOAT: "-target-feature" "+soft-float"
+
+// check -mfloat-abi=soft option for ppc32
+// RUN: %clang -target powerpc-unknown-linux-gnu %s -mfloat-abi=soft -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-FLOATABISOFT %s
+// CHECK-FLOATABISOFT: "-target-feature" "+soft-float"
+
+// check -mhard-float option for ppc32
+// RUN: %clang -target powerpc-unknown-linux-gnu %s -mhard-float -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-HARDFLOAT %s
+// CHECK-HARDFLOAT-NOT: "-target-feature" "+soft-float"
+
+// check -mfloat-abi=hard option for ppc32
+// RUN: %clang -target powerpc-unknown-linux-gnu %s -mfloat-abi=hard -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-FLOATABIHARD %s
+// CHECK-FLOATABIHARD-NOT: "-target-feature" "+soft-float"
+
+// check combine -mhard-float -msoft-float option for ppc32
+// RUN: %clang -target powerpc-unknown-linux-gnu %s -mhard-float -msoft-float -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-HARDSOFT %s
+// CHECK-HARDSOFT: "-target-feature" "+soft-float"
+
+// check combine -msoft-float -mhard-float option for ppc32
+// RUN: %clang -target powerpc-unknown-linux-gnu %s -msoft-float -mhard-float -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-SOFTHARD %s
+// CHECK-SOFTHARD-NOT: "-target-feature" "+soft-float"
+
+// check -mfloat-abi=x option
+// RUN: %clang -target powerpc-unknown-linux-gnu %s -mfloat-abi=x -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-ERRMSG %s
+// CHECK-ERRMSG: clang: error: invalid float ABI '-mfloat-abi=x'
+
 // CHECK: invalid argument '-faltivec' only allowed with 'ppc/ppc64/ppc64le'
 
 // Check that -fno-altivec and -mno-altivec correctly disable the altivec
Index: test/CodeGen/ppc-sfvarargs.c
===
--- test/CodeGen/ppc-sfvarargs.c
+++ test/CodeGen/ppc-sfvarargs.c
@@ -0,0 +1,17 @@
+// RUN: %clang -O0 --target=powerpc-unknown-linux-gnu -EB -msoft-float -S -emit-llvm %s -o - | FileCheck %s
+
+#include 
+void test(char *fmt, ...) {
+  va_list ap;
+  va_start(ap, fmt);
+  va_arg(ap, double);
+  va_end(ap);
+}
+
+void foo() {
+  double a;
+  test("test",a);
+}
+// CHECK: %{{[0-9]+}} = add i8 %numUsedRegs, 1
+// CHECK: %{{[0-9]+}} = and i8 %{{[0-9]+}}, -2
+// CHECK: %{{[0-9]+}} = mul i8 %{{[0-9]+}}, 4
\ No newline at end of file
Index: lib/Driver/Tools.h
===
--- lib/Driver/Tools.h
+++ lib/Driver/Tools.h
@@ -731,6 +731,16 @@
 
 FloatABI getARMFloatABI(const ToolChain &TC, const llvm::opt::ArgList &Args);
 }
+
+namespace ppc {
+enum class FloatABI {
+  Invalid,
+  Soft,
+  SoftFP,
+  Hard,
+};
+   ppc::FloatABI getPPCFloatABI(const Driver &D, const llvm::opt::ArgList &Args);
+}
 namespace XCore {
 // For XCore, we do not need to instantiate tools for PreProcess, PreCompile and
 // Compile.
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -1325,7 +1325,7 @@
   return "";
 }
 
-static void getPPCTargetFeatures(const ArgList &Args,
+static void getPPCTargetFeatures(const Driver &D, const ArgList &Args,
  std::vector &Features) {
   for (const Arg *A : Args.filtered(options::OPT_m_ppc_Features_Group)) {
 StringRef Name = A->getOption().getName();
@@ -1345,15 +1345,48 @@
 // TODO: Change the LLVM backend option maybe?
 if (Name == "mfcrf")
   Name = "mfocrf";
-
+
 Features.push_back(Args.MakeArgString((IsNegative ? "-" : "+") + Name));
   }
 
+  ppc::FloatABI FloatABI = ppc::getPPCFloatABI(D, Args);
+  if (FloatABI == ppc::FloatABI::Soft)
+Features.push_back("+soft-float");
+  
   // Altivec is a bit weird, allow overriding of the Altivec feature here.
   AddTargetFeature(Args, Features, options::OPT_faltivec,
options::OPT_fno_altivec, "altivec");
 }
 
+ppc::FloatABI ppc::getPPCFloatABI(const Driver &D, const ArgList &Args) {
+  ppc::FloatABI ABI = ppc::FloatABI::Invalid;
+  if (Arg *A = Args.getLastArg(options::OPT_msoft_float,
+  options::OPT_mhard_float,
+  options::OPT_mfloat_ab

Re: [PATCH] D14204: Fix crash in redundant-void-arg check.

2015-11-02 Thread Angel Garcia via cfe-commits
angelgarcia updated this revision to Diff 38889.
angelgarcia added a comment.

Sorry, I forgot. That case works just fine.


http://reviews.llvm.org/D14204

Files:
  clang-tidy/modernize/RedundantVoidArgCheck.cpp
  test/clang-tidy/modernize-redundant-void-arg.cpp

Index: test/clang-tidy/modernize-redundant-void-arg.cpp
===
--- test/clang-tidy/modernize-redundant-void-arg.cpp
+++ test/clang-tidy/modernize-redundant-void-arg.cpp
@@ -417,3 +417,19 @@
   // CHECK-MESSAGES: [[@LINE-2]]:45: warning: {{.*}} in lambda expression
   // CHECK-FIXES: {{^  }}auto void_returner = []() -> void (*)() { return f1; 
};{{$}}
 }
+
+#define M(x) x
+
+M(void inmacro(void) {})
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} in function definition
+// CHECK-FIXES: M(void inmacro() {})
+
+#define F(A, B)\
+  struct F_##A##_##B { \
+F_##A##_##B(void); \
+  };   \
+  F_##A##_##B::F_##A##_##B(void)
+
+F(Foo, Bar) {
+
+}
Index: clang-tidy/modernize/RedundantVoidArgCheck.cpp
===
--- clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -47,8 +47,8 @@
 
 void RedundantVoidArgCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(functionDecl(isExpansionInMainFile(), parameterCountIs(0),
-  unless(isImplicit()),
-  unless(isExternC())).bind(FunctionId),
+  unless(isImplicit()), unless(isExternC()))
+ .bind(FunctionId),
  this);
   Finder->addMatcher(typedefDecl(isExpansionInMainFile()).bind(TypedefId),
  this);
@@ -77,9 +77,10 @@
   cxxReinterpretCastExpr(isExpansionInMainFile(), 
CastDestinationIsFunction)
   .bind(NamedCastId),
   this);
-  Finder->addMatcher(cxxConstCastExpr(isExpansionInMainFile(),
-   
CastDestinationIsFunction).bind(NamedCastId),
- this);
+  Finder->addMatcher(
+  cxxConstCastExpr(isExpansionInMainFile(), CastDestinationIsFunction)
+  .bind(NamedCastId),
+  this);
   Finder->addMatcher(lambdaExpr(isExpansionInMainFile()).bind(LambdaId), this);
 }
 
@@ -128,11 +129,14 @@
 void RedundantVoidArgCheck::removeVoidArgumentTokens(
 const ast_matchers::MatchFinder::MatchResult &Result, SourceRange Range,
 StringRef GrammarLocation) {
-  std::string DeclText =
-  Lexer::getSourceText(CharSourceRange::getTokenRange(Range),
-   *Result.SourceManager,
-   Result.Context->getLangOpts()).str();
-  Lexer PrototypeLexer(Range.getBegin(), Result.Context->getLangOpts(),
+  CharSourceRange CharRange = Lexer::makeFileCharRange(
+  CharSourceRange::getTokenRange(Range), *Result.SourceManager,
+  Result.Context->getLangOpts());
+
+  std::string DeclText = Lexer::getSourceText(CharRange, *Result.SourceManager,
+  Result.Context->getLangOpts())
+ .str();
+  Lexer PrototypeLexer(CharRange.getBegin(), Result.Context->getLangOpts(),
DeclText.data(), DeclText.data(),
DeclText.data() + DeclText.size());
   enum TokenState {


Index: test/clang-tidy/modernize-redundant-void-arg.cpp
===
--- test/clang-tidy/modernize-redundant-void-arg.cpp
+++ test/clang-tidy/modernize-redundant-void-arg.cpp
@@ -417,3 +417,19 @@
   // CHECK-MESSAGES: [[@LINE-2]]:45: warning: {{.*}} in lambda expression
   // CHECK-FIXES: {{^  }}auto void_returner = []() -> void (*)() { return f1; };{{$}}
 }
+
+#define M(x) x
+
+M(void inmacro(void) {})
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} in function definition
+// CHECK-FIXES: M(void inmacro() {})
+
+#define F(A, B)\
+  struct F_##A##_##B { \
+F_##A##_##B(void); \
+  };   \
+  F_##A##_##B::F_##A##_##B(void)
+
+F(Foo, Bar) {
+
+}
Index: clang-tidy/modernize/RedundantVoidArgCheck.cpp
===
--- clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -47,8 +47,8 @@
 
 void RedundantVoidArgCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(functionDecl(isExpansionInMainFile(), parameterCountIs(0),
-  unless(isImplicit()),
-  unless(isExternC())).bind(FunctionId),
+  unless(isImplicit()), unless(isExternC()))
+ .bind(FunctionId),
  this);
   Finder->addMatcher(typedefDecl(isExpansionInMainFile()).bind(TypedefId),
  this);
@@ -77,9 +77,10 @@
   cxxReinterpretCastExpr(isExpansionInMainFile(), CastDestinat

Re: [PATCH] D14204: Fix crash in redundant-void-arg check.

2015-11-02 Thread Alexander Kornienko via cfe-commits
alexfh accepted this revision.
alexfh added a reviewer: alexfh.
alexfh added a comment.
This revision is now accepted and ready to land.

Thanks! Looks good!


http://reviews.llvm.org/D14204



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


Re: [PATCH] D14204: Fix crash in redundant-void-arg check.

2015-11-02 Thread Angel Garcia via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL251792: Fix crash in redundant-void-arg check. (authored by 
angelgarcia).

Changed prior to commit:
  http://reviews.llvm.org/D14204?vs=38889&id=38890#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D14204

Files:
  clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp

Index: clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -47,8 +47,8 @@
 
 void RedundantVoidArgCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(functionDecl(isExpansionInMainFile(), parameterCountIs(0),
-  unless(isImplicit()),
-  unless(isExternC())).bind(FunctionId),
+  unless(isImplicit()), unless(isExternC()))
+ .bind(FunctionId),
  this);
   Finder->addMatcher(typedefDecl(isExpansionInMainFile()).bind(TypedefId),
  this);
@@ -77,9 +77,10 @@
   cxxReinterpretCastExpr(isExpansionInMainFile(), 
CastDestinationIsFunction)
   .bind(NamedCastId),
   this);
-  Finder->addMatcher(cxxConstCastExpr(isExpansionInMainFile(),
-   
CastDestinationIsFunction).bind(NamedCastId),
- this);
+  Finder->addMatcher(
+  cxxConstCastExpr(isExpansionInMainFile(), CastDestinationIsFunction)
+  .bind(NamedCastId),
+  this);
   Finder->addMatcher(lambdaExpr(isExpansionInMainFile()).bind(LambdaId), this);
 }
 
@@ -128,11 +129,14 @@
 void RedundantVoidArgCheck::removeVoidArgumentTokens(
 const ast_matchers::MatchFinder::MatchResult &Result, SourceRange Range,
 StringRef GrammarLocation) {
-  std::string DeclText =
-  Lexer::getSourceText(CharSourceRange::getTokenRange(Range),
-   *Result.SourceManager,
-   Result.Context->getLangOpts()).str();
-  Lexer PrototypeLexer(Range.getBegin(), Result.Context->getLangOpts(),
+  CharSourceRange CharRange = Lexer::makeFileCharRange(
+  CharSourceRange::getTokenRange(Range), *Result.SourceManager,
+  Result.Context->getLangOpts());
+
+  std::string DeclText = Lexer::getSourceText(CharRange, *Result.SourceManager,
+  Result.Context->getLangOpts())
+ .str();
+  Lexer PrototypeLexer(CharRange.getBegin(), Result.Context->getLangOpts(),
DeclText.data(), DeclText.data(),
DeclText.data() + DeclText.size());
   enum TokenState {
Index: clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp
@@ -417,3 +417,19 @@
   // CHECK-MESSAGES: [[@LINE-2]]:45: warning: {{.*}} in lambda expression
   // CHECK-FIXES: {{^  }}auto void_returner = []() -> void (*)() { return f1; 
};{{$}}
 }
+
+#define M(x) x
+
+M(void inmacro(void) {})
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} in function definition
+// CHECK-FIXES: M(void inmacro() {})
+
+#define F(A, B)\
+  struct F_##A##_##B { \
+F_##A##_##B(void); \
+  };   \
+  F_##A##_##B::F_##A##_##B(void)
+
+F(Foo, Bar) {
+
+}


Index: clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -47,8 +47,8 @@
 
 void RedundantVoidArgCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(functionDecl(isExpansionInMainFile(), parameterCountIs(0),
-  unless(isImplicit()),
-  unless(isExternC())).bind(FunctionId),
+  unless(isImplicit()), unless(isExternC()))
+ .bind(FunctionId),
  this);
   Finder->addMatcher(typedefDecl(isExpansionInMainFile()).bind(TypedefId),
  this);
@@ -77,9 +77,10 @@
   cxxReinterpretCastExpr(isExpansionInMainFile(), CastDestinationIsFunction)
   .bind(NamedCastId),
   this);
-  Finder->addMatcher(cxxConstCastExpr(isExpansionInMainFile(),
-   CastDestinationIsFunction).bind(NamedCastId),
- this);
+  Finder->addMatcher(
+  cxxConstCastExpr(isExpansionInMainFile(), CastDestinationIsFu

[clang-tools-extra] r251792 - Fix crash in redundant-void-arg check.

2015-11-02 Thread Angel Garcia Gomez via cfe-commits
Author: angelgarcia
Date: Mon Nov  2 05:39:17 2015
New Revision: 251792

URL: http://llvm.org/viewvc/llvm-project?rev=251792&view=rev
Log:
Fix crash in redundant-void-arg check.

Summary:
When applying this check to the unit tests, it would hit an assertion:
llvm/tools/clang/lib/Lex/Lexer.cpp:1056: clang::SourceLocation 
clang::Lexer::getSourceLocation(const char*, unsigned int) const: Assertion `PP 
&& "This doesn't work on raw lexers"' failed.

Reviewers: klimek, LegalizeAdulthood, alexfh

Subscribers: cfe-commits, alexfh

Differential Revision: http://reviews.llvm.org/D14204

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp?rev=251792&r1=251791&r2=251792&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp Mon 
Nov  2 05:39:17 2015
@@ -47,8 +47,8 @@ namespace modernize {
 
 void RedundantVoidArgCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(functionDecl(isExpansionInMainFile(), parameterCountIs(0),
-  unless(isImplicit()),
-  unless(isExternC())).bind(FunctionId),
+  unless(isImplicit()), unless(isExternC()))
+ .bind(FunctionId),
  this);
   Finder->addMatcher(typedefDecl(isExpansionInMainFile()).bind(TypedefId),
  this);
@@ -77,9 +77,10 @@ void RedundantVoidArgCheck::registerMatc
   cxxReinterpretCastExpr(isExpansionInMainFile(), 
CastDestinationIsFunction)
   .bind(NamedCastId),
   this);
-  Finder->addMatcher(cxxConstCastExpr(isExpansionInMainFile(),
-   
CastDestinationIsFunction).bind(NamedCastId),
- this);
+  Finder->addMatcher(
+  cxxConstCastExpr(isExpansionInMainFile(), CastDestinationIsFunction)
+  .bind(NamedCastId),
+  this);
   Finder->addMatcher(lambdaExpr(isExpansionInMainFile()).bind(LambdaId), this);
 }
 
@@ -128,11 +129,14 @@ void RedundantVoidArgCheck::processFunct
 void RedundantVoidArgCheck::removeVoidArgumentTokens(
 const ast_matchers::MatchFinder::MatchResult &Result, SourceRange Range,
 StringRef GrammarLocation) {
-  std::string DeclText =
-  Lexer::getSourceText(CharSourceRange::getTokenRange(Range),
-   *Result.SourceManager,
-   Result.Context->getLangOpts()).str();
-  Lexer PrototypeLexer(Range.getBegin(), Result.Context->getLangOpts(),
+  CharSourceRange CharRange = Lexer::makeFileCharRange(
+  CharSourceRange::getTokenRange(Range), *Result.SourceManager,
+  Result.Context->getLangOpts());
+
+  std::string DeclText = Lexer::getSourceText(CharRange, *Result.SourceManager,
+  Result.Context->getLangOpts())
+ .str();
+  Lexer PrototypeLexer(CharRange.getBegin(), Result.Context->getLangOpts(),
DeclText.data(), DeclText.data(),
DeclText.data() + DeclText.size());
   enum TokenState {

Modified: 
clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp?rev=251792&r1=251791&r2=251792&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp 
Mon Nov  2 05:39:17 2015
@@ -417,3 +417,19 @@ void test_lambda_functions() {
   // CHECK-MESSAGES: [[@LINE-2]]:45: warning: {{.*}} in lambda expression
   // CHECK-FIXES: {{^  }}auto void_returner = []() -> void (*)() { return f1; 
};{{$}}
 }
+
+#define M(x) x
+
+M(void inmacro(void) {})
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} in function definition
+// CHECK-FIXES: M(void inmacro() {})
+
+#define F(A, B)\
+  struct F_##A##_##B { \
+F_##A##_##B(void); \
+  };   \
+  F_##A##_##B::F_##A##_##B(void)
+
+F(Foo, Bar) {
+
+}


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


[PATCH] D14229: Remove unreachable that was reached in modernize-use-nullptr.

2015-11-02 Thread Angel Garcia via cfe-commits
angelgarcia created this revision.
angelgarcia added a reviewer: alexfh.
angelgarcia added subscribers: cfe-commits, klimek.

When traversing the parent map, the check assumed that all the nodes would be 
either Stmt or Decl. After r251101, this is no longer true: there can be 
TypeLoc and NestedNameSpecifierLoc nodes.

http://reviews.llvm.org/D14229

Files:
  clang-tidy/modernize/UseNullptrCheck.cpp
  test/clang-tidy/modernize-use-nullptr.cpp

Index: test/clang-tidy/modernize-use-nullptr.cpp
===
--- test/clang-tidy/modernize-use-nullptr.cpp
+++ test/clang-tidy/modernize-use-nullptr.cpp
@@ -184,3 +184,15 @@
   // CHECK-FIXES: a[2] = {ENTRY(nullptr), {nullptr}};
 #undef ENTRY
 }
+
+// One of the ancestor of the cast is a NestedNameSpecifierLoc.
+class NoDef;
+char function(NoDef *p);
+#define F(x) \
+(sizeof(function(x)) == 1)
+template
+class C {};
+C c;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use nullptr
+// CHECK-FIXES: C c;
+#undef F
Index: clang-tidy/modernize/UseNullptrCheck.cpp
===
--- clang-tidy/modernize/UseNullptrCheck.cpp
+++ clang-tidy/modernize/UseNullptrCheck.cpp
@@ -435,12 +435,14 @@
 Loc = D->getLocStart();
   else if (const auto *S = Parent.get())
 Loc = S->getLocStart();
-  else
-llvm_unreachable("Expected to find Decl or Stmt containing ancestor");
 
-  if (!expandsFrom(Loc, MacroLoc)) {
-Result = Parent;
-return true;
+  // TypeLoc and NestedNameSpecifierLoc are members of the parent map. Skip
+  // them and keep going up.
+  if (Loc.isValid()) {
+if (!expandsFrom(Loc, MacroLoc)) {
+  Result = Parent;
+  return true;
+}
   }
   Start = Parent;
 }


Index: test/clang-tidy/modernize-use-nullptr.cpp
===
--- test/clang-tidy/modernize-use-nullptr.cpp
+++ test/clang-tidy/modernize-use-nullptr.cpp
@@ -184,3 +184,15 @@
   // CHECK-FIXES: a[2] = {ENTRY(nullptr), {nullptr}};
 #undef ENTRY
 }
+
+// One of the ancestor of the cast is a NestedNameSpecifierLoc.
+class NoDef;
+char function(NoDef *p);
+#define F(x) \
+(sizeof(function(x)) == 1)
+template
+class C {};
+C c;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use nullptr
+// CHECK-FIXES: C c;
+#undef F
Index: clang-tidy/modernize/UseNullptrCheck.cpp
===
--- clang-tidy/modernize/UseNullptrCheck.cpp
+++ clang-tidy/modernize/UseNullptrCheck.cpp
@@ -435,12 +435,14 @@
 Loc = D->getLocStart();
   else if (const auto *S = Parent.get())
 Loc = S->getLocStart();
-  else
-llvm_unreachable("Expected to find Decl or Stmt containing ancestor");
 
-  if (!expandsFrom(Loc, MacroLoc)) {
-Result = Parent;
-return true;
+  // TypeLoc and NestedNameSpecifierLoc are members of the parent map. Skip
+  // them and keep going up.
+  if (Loc.isValid()) {
+if (!expandsFrom(Loc, MacroLoc)) {
+  Result = Parent;
+  return true;
+}
   }
   Start = Parent;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12761: MPI-Checker patch for Clang Static Analyzer

2015-11-02 Thread Alexander Droste via cfe-commits
Alexander_Droste marked 26 inline comments as done.
Alexander_Droste added a comment.

http://reviews.llvm.org/D12761



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


Re: [PATCH] D14229: Remove unreachable that was reached in modernize-use-nullptr.

2015-11-02 Thread Alexander Kornienko via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

Looks good with one nit.



Comment at: test/clang-tidy/modernize-use-nullptr.cpp:191
@@ +190,3 @@
+char function(NoDef *p);
+#define F(x) \
+(sizeof(function(x)) == 1)

nit: Merge the lines maybe? 


http://reviews.llvm.org/D14229



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


Re: [PATCH] D14179: Remove some legacy mingw-w64 gcc struct info

2015-11-02 Thread Martell Malone via cfe-commits
martell added a subscriber: chapuni.
martell added a comment.

Ohh wow thats dated Dec 12 2013
I assume this would be suitable for 3.7.x then also.
This was originally introduced by @chapuni in http://reviews.llvm.org/rL126186
No test case seems to be present for this so I think this should be good to 
commit.
@rnk LGTY ?


http://reviews.llvm.org/D14179



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


[libcxx] r251802 - Remove undefined behavior from some tests. Thanks to Walter Brown for the heads-up.

2015-11-02 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Mon Nov  2 09:25:53 2015
New Revision: 251802

URL: http://llvm.org/viewvc/llvm-project?rev=251802&view=rev
Log:
Remove undefined behavior from some tests. Thanks to Walter Brown for the 
heads-up.

Modified:

libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp

libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp

Modified: 
libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp?rev=251802&r1=251801&r2=251802&view=diff
==
--- 
libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp
 Mon Nov  2 09:25:53 2015
@@ -20,13 +20,15 @@
 struct B
 {
 static int count_;
+static int population_;
 int data_;
-explicit B() : data_(1) {}
-B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
-~B() {data_ = 0;}
+explicit B() : data_(1) { ++population_; }
+B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_; ++population_; 
}
+~B() {data_ = 0; --population_; }
 };
 
 int B::count_ = 0;
+int B::population_ = 0;
 
 struct Nasty
 {
@@ -45,6 +47,7 @@ int main()
 char pool[sizeof(B)*N] = {0};
 B* bp = (B*)pool;
 B b[N];
+assert(B::population_ == N);
 try
 {
 std::uninitialized_copy(b, b+N, bp);
@@ -52,14 +55,15 @@ int main()
 }
 catch (...)
 {
-for (int i = 0; i < N; ++i)
-assert(bp[i].data_ == 0);
+assert(B::population_ == N);
 }
 B::count_ = 0;
 std::uninitialized_copy(b, b+2, bp);
 for (int i = 0; i < 2; ++i)
 assert(bp[i].data_ == 1);
+   assert(B::population_ == N + 2);
 }
+
 {
 const int N = 5;
 char pool[sizeof(Nasty)*N] = {0};

Modified: 
libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp?rev=251802&r1=251801&r2=251802&view=diff
==
--- 
libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp
 Mon Nov  2 09:25:53 2015
@@ -20,12 +20,14 @@
 struct B
 {
 static int count_;
+static int population_;
 int data_;
-explicit B() : data_(1) {}
-B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
-~B() {data_ = 0;}
+explicit B() : data_(1) { ++population_; }
+B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_; ++population_; 
}
+~B() {data_ = 0; --population_; }
 };
 
+int B::population_ = 0;
 int B::count_ = 0;
 
 struct Nasty
@@ -45,6 +47,7 @@ int main()
 char pool[sizeof(B)*N] = {0};
 B* bp = (B*)pool;
 B b[N];
+assert(B::population_ == N);
 try
 {
 std::uninitialized_copy_n(b, 5, bp);
@@ -52,14 +55,15 @@ int main()
 }
 catch (...)
 {
-for (int i = 0; i < N; ++i)
-assert(bp[i].data_ == 0);
+assert(B::population_ == N);
 }
 B::count_ = 0;
 std::uninitialized_copy_n(b, 2, bp);
 for (int i = 0; i < 2; ++i)
 assert(bp[i].data_ == 1);
+assert(B::population_ == N + 2);
 }
+
 {
 const int N = 5;
 char pool[sizeof(Nasty)*N] = {0};


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


Re: [PATCH] D14229: Remove unreachable that was reached in modernize-use-nullptr.

2015-11-02 Thread Angel Garcia via cfe-commits
angelgarcia updated this revision to Diff 38918.
angelgarcia added a comment.

Merge lines.


http://reviews.llvm.org/D14229

Files:
  clang-tidy/modernize/UseNullptrCheck.cpp
  test/clang-tidy/modernize-use-nullptr.cpp

Index: test/clang-tidy/modernize-use-nullptr.cpp
===
--- test/clang-tidy/modernize-use-nullptr.cpp
+++ test/clang-tidy/modernize-use-nullptr.cpp
@@ -184,3 +184,14 @@
   // CHECK-FIXES: a[2] = {ENTRY(nullptr), {nullptr}};
 #undef ENTRY
 }
+
+// One of the ancestor of the cast is a NestedNameSpecifierLoc.
+class NoDef;
+char function(NoDef *p);
+#define F(x) (sizeof(function(x)) == 1)
+template
+class C {};
+C c;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use nullptr
+// CHECK-FIXES: C c;
+#undef F
Index: clang-tidy/modernize/UseNullptrCheck.cpp
===
--- clang-tidy/modernize/UseNullptrCheck.cpp
+++ clang-tidy/modernize/UseNullptrCheck.cpp
@@ -435,12 +435,14 @@
 Loc = D->getLocStart();
   else if (const auto *S = Parent.get())
 Loc = S->getLocStart();
-  else
-llvm_unreachable("Expected to find Decl or Stmt containing ancestor");
 
-  if (!expandsFrom(Loc, MacroLoc)) {
-Result = Parent;
-return true;
+  // TypeLoc and NestedNameSpecifierLoc are members of the parent map. Skip
+  // them and keep going up.
+  if (Loc.isValid()) {
+if (!expandsFrom(Loc, MacroLoc)) {
+  Result = Parent;
+  return true;
+}
   }
   Start = Parent;
 }


Index: test/clang-tidy/modernize-use-nullptr.cpp
===
--- test/clang-tidy/modernize-use-nullptr.cpp
+++ test/clang-tidy/modernize-use-nullptr.cpp
@@ -184,3 +184,14 @@
   // CHECK-FIXES: a[2] = {ENTRY(nullptr), {nullptr}};
 #undef ENTRY
 }
+
+// One of the ancestor of the cast is a NestedNameSpecifierLoc.
+class NoDef;
+char function(NoDef *p);
+#define F(x) (sizeof(function(x)) == 1)
+template
+class C {};
+C c;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use nullptr
+// CHECK-FIXES: C c;
+#undef F
Index: clang-tidy/modernize/UseNullptrCheck.cpp
===
--- clang-tidy/modernize/UseNullptrCheck.cpp
+++ clang-tidy/modernize/UseNullptrCheck.cpp
@@ -435,12 +435,14 @@
 Loc = D->getLocStart();
   else if (const auto *S = Parent.get())
 Loc = S->getLocStart();
-  else
-llvm_unreachable("Expected to find Decl or Stmt containing ancestor");
 
-  if (!expandsFrom(Loc, MacroLoc)) {
-Result = Parent;
-return true;
+  // TypeLoc and NestedNameSpecifierLoc are members of the parent map. Skip
+  // them and keep going up.
+  if (Loc.isValid()) {
+if (!expandsFrom(Loc, MacroLoc)) {
+  Result = Parent;
+  return true;
+}
   }
   Start = Parent;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r251803 - Remove unreachable that was reached in modernize-use-nullptr.

2015-11-02 Thread Angel Garcia Gomez via cfe-commits
Author: angelgarcia
Date: Mon Nov  2 09:28:06 2015
New Revision: 251803

URL: http://llvm.org/viewvc/llvm-project?rev=251803&view=rev
Log:
Remove unreachable that was reached in modernize-use-nullptr.

Summary: When traversing the parent map, the check assumed that all the nodes 
would be either Stmt or Decl. After r251101, this is no longer true: there can 
be TypeLoc and NestedNameSpecifierLoc nodes.

Reviewers: alexfh

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D14229

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp?rev=251803&r1=251802&r2=251803&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp Mon Nov  2 
09:28:06 2015
@@ -435,12 +435,14 @@ private:
 Loc = D->getLocStart();
   else if (const auto *S = Parent.get())
 Loc = S->getLocStart();
-  else
-llvm_unreachable("Expected to find Decl or Stmt containing ancestor");
 
-  if (!expandsFrom(Loc, MacroLoc)) {
-Result = Parent;
-return true;
+  // TypeLoc and NestedNameSpecifierLoc are members of the parent map. Skip
+  // them and keep going up.
+  if (Loc.isValid()) {
+if (!expandsFrom(Loc, MacroLoc)) {
+  Result = Parent;
+  return true;
+}
   }
   Start = Parent;
 }

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp?rev=251803&r1=251802&r2=251803&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp Mon Nov  
2 09:28:06 2015
@@ -184,3 +184,14 @@ void test_macro_args() {
   // CHECK-FIXES: a[2] = {ENTRY(nullptr), {nullptr}};
 #undef ENTRY
 }
+
+// One of the ancestor of the cast is a NestedNameSpecifierLoc.
+class NoDef;
+char function(NoDef *p);
+#define F(x) (sizeof(function(x)) == 1)
+template
+class C {};
+C c;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use nullptr
+// CHECK-FIXES: C c;
+#undef F


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


[libcxx] r251804 - Remove undefined behavior from some tests. Same pattern as the unitialized_copy tests

2015-11-02 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Mon Nov  2 09:29:13 2015
New Revision: 251804

URL: http://llvm.org/viewvc/llvm-project?rev=251804&view=rev
Log:
Remove undefined behavior from some tests. Same pattern as the unitialized_copy 
tests

Modified:

libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp

libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp

Modified: 
libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp?rev=251804&r1=251803&r2=251804&view=diff
==
--- 
libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp
 Mon Nov  2 09:29:13 2015
@@ -19,13 +19,15 @@
 struct B
 {
 static int count_;
+static int population_;
 int data_;
-explicit B() : data_(1) {}
-B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
-~B() {data_ = 0;}
+explicit B() : data_(1) { ++population_; }
+B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_; ++population_; 
}
+~B() {data_ = 0; --population_; }
 };
 
 int B::count_ = 0;
+int B::population_ = 0;
 
 struct Nasty
 {
@@ -43,6 +45,7 @@ int main()
 const int N = 5;
 char pool[sizeof(B)*N] = {0};
 B* bp = (B*)pool;
+assert(B::population_ == 0);
 try
 {
 std::uninitialized_fill_n(bp, 5, B());
@@ -50,14 +53,14 @@ int main()
 }
 catch (...)
 {
-for (int i = 0; i < N; ++i)
-assert(bp[i].data_ == 0);
+assert(B::population_ == 0);
 }
 B::count_ = 0;
 B* r = std::uninitialized_fill_n(bp, 2, B());
 assert(r == bp + 2);
 for (int i = 0; i < 2; ++i)
 assert(bp[i].data_ == 1);
+assert(B::population_ == 2);
 }
 {
 {

Modified: 
libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp?rev=251804&r1=251803&r2=251804&view=diff
==
--- 
libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp
 Mon Nov  2 09:29:13 2015
@@ -20,13 +20,15 @@
 struct B
 {
 static int count_;
+static int population_;
 int data_;
-explicit B() : data_(1) {}
-B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
-~B() {data_ = 0;}
+explicit B() : data_(1) { ++population_; }
+B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_; ++population_; 
}
+~B() {data_ = 0; --population_; }
 };
 
 int B::count_ = 0;
+int B::population_ = 0;
 
 struct Nasty
 {
@@ -44,6 +46,7 @@ int main()
 const int N = 5;
 char pool[sizeof(B)*N] = {0};
 B* bp = (B*)pool;
+assert(B::population_ == 0);
 try
 {
 std::uninitialized_fill(bp, bp+N, B());
@@ -51,13 +54,13 @@ int main()
 }
 catch (...)
 {
-for (int i = 0; i < N; ++i)
-assert(bp[i].data_ == 0);
+assert(B::population_ == 0);
 }
 B::count_ = 0;
 std::uninitialized_fill(bp, bp+2, B());
 for (int i = 0; i < 2; ++i)
 assert(bp[i].data_ == 1);
+assert(B::population_ == 2);
 }
 {
 const int N = 5;


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


[PATCH] D14238: Fix another crash in the redundant-void-arg check.

2015-11-02 Thread Angel Garcia via cfe-commits
angelgarcia created this revision.
angelgarcia added a reviewer: alexfh.
angelgarcia added subscribers: cfe-commits, klimek.

The check was assuming that a definition of a function always has a body, but a 
declaration that explicitly defaults or deletes a function is a definition too.

http://reviews.llvm.org/D14238

Files:
  clang-tidy/modernize/RedundantVoidArgCheck.cpp
  test/clang-tidy/modernize-redundant-void-arg.cpp

Index: test/clang-tidy/modernize-redundant-void-arg.cpp
===
--- test/clang-tidy/modernize-redundant-void-arg.cpp
+++ test/clang-tidy/modernize-redundant-void-arg.cpp
@@ -433,3 +433,9 @@
 F(Foo, Bar) {
 
 }
+
+struct DefinitionWithNoBody {
+  DefinitionWithNoBody(void) = delete;
+  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: {{.*}} in function definition
+  // CHECK-FIXES: DefinitionWithNoBody() = delete;
+};
Index: clang-tidy/modernize/RedundantVoidArgCheck.cpp
===
--- clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -116,9 +116,12 @@
 const MatchFinder::MatchResult &Result, const FunctionDecl *Function) {
   SourceLocation Start = Function->getLocStart();
   if (Function->isThisDeclarationADefinition()) {
-SourceLocation BeforeBody =
-Function->getBody()->getLocStart().getLocWithOffset(-1);
-removeVoidArgumentTokens(Result, SourceRange(Start, BeforeBody),
+SourceLocation End;
+if (Function->hasBody())
+  End = Function->getBody()->getLocStart().getLocWithOffset(-1);
+else
+  End = Function->getLocEnd();
+removeVoidArgumentTokens(Result, SourceRange(Start, End),
  "function definition");
   } else {
 removeVoidArgumentTokens(Result, Function->getSourceRange(),


Index: test/clang-tidy/modernize-redundant-void-arg.cpp
===
--- test/clang-tidy/modernize-redundant-void-arg.cpp
+++ test/clang-tidy/modernize-redundant-void-arg.cpp
@@ -433,3 +433,9 @@
 F(Foo, Bar) {
 
 }
+
+struct DefinitionWithNoBody {
+  DefinitionWithNoBody(void) = delete;
+  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: {{.*}} in function definition
+  // CHECK-FIXES: DefinitionWithNoBody() = delete;
+};
Index: clang-tidy/modernize/RedundantVoidArgCheck.cpp
===
--- clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -116,9 +116,12 @@
 const MatchFinder::MatchResult &Result, const FunctionDecl *Function) {
   SourceLocation Start = Function->getLocStart();
   if (Function->isThisDeclarationADefinition()) {
-SourceLocation BeforeBody =
-Function->getBody()->getLocStart().getLocWithOffset(-1);
-removeVoidArgumentTokens(Result, SourceRange(Start, BeforeBody),
+SourceLocation End;
+if (Function->hasBody())
+  End = Function->getBody()->getLocStart().getLocWithOffset(-1);
+else
+  End = Function->getLocEnd();
+removeVoidArgumentTokens(Result, SourceRange(Start, End),
  "function definition");
   } else {
 removeVoidArgumentTokens(Result, Function->getSourceRange(),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D14014: Checker of proper vfork usage

2015-11-02 Thread Yury Gribov via cfe-commits
ygribov updated this revision to Diff 38926.
ygribov marked 2 inline comments as done.
ygribov added a comment.

Updated after review.


http://reviews.llvm.org/D14014

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
  lib/StaticAnalyzer/Checkers/VforkChecker.cpp
  lib/StaticAnalyzer/Core/CheckerHelpers.cpp
  test/Analysis/Inputs/system-header-simulator.h
  test/Analysis/vfork.c

Index: test/Analysis/vfork.c
===
--- /dev/null
+++ test/Analysis/vfork.c
@@ -0,0 +1,114 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.unix.Vfork -verify %s
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.unix.Vfork -verify -x c++ %s
+
+#include "Inputs/system-header-simulator.h"
+
+void foo();
+
+// Ensure that child process is properly checked.
+int f1(int x) {
+  pid_t pid = vfork();
+  if (pid != 0)
+return 0;
+
+  switch (x) {
+  case 0:
+// Ensure that modifying pid is ok.
+pid = 1; // no-warning
+// Ensure that calling whitelisted routines is ok.
+execl("", "", 0); // no-warning
+_exit(1); // no-warning
+break;
+  case 1:
+// Ensure that writing variables is prohibited.
+x = 0; // expected-warning{{This assignment is prohibited after a successful vfork}}
+break;
+  case 2:
+// Ensure that calling functions is prohibited.
+foo(); // expected-warning{{This function call is prohibited after a successful vfork}}
+break;
+  default:
+// Ensure that returning from function is prohibited.
+return 0;
+  }
+
+  while(1);
+} // expected-warning{{Return from this function is prohibited after a successful vfork}}
+
+// Same as previous but without explicit pid variable.
+int f2(int x) {
+  pid_t pid = vfork();
+
+  switch (x) {
+  case 0:
+// Ensure that writing pid is ok.
+pid = 1; // no-warning
+// Ensure that calling whitelisted routines is ok.
+execl("", "", 0); // no-warning
+_exit(1); // no-warning
+break;
+  case 1:
+// Ensure that writing variables is prohibited.
+x = 0; // expected-warning{{This assignment is prohibited after a successful vfork}}
+break;
+  case 2:
+// Ensure that calling functions is prohibited.
+foo(); // expected-warning{{This function call is prohibited after a successful vfork}}
+break;
+  default:
+// Ensure that returning from function is prohibited.
+return 0;
+  }
+
+  while(1);
+} // expected-warning{{Return from this function is prohibited after a successful vfork}}
+
+// Ensure that parent process isn't restricted.
+int f3(int x) {
+  if (vfork() == 0)
+_exit(1);
+  x = 0; // no-warning
+  foo(); // no-warning
+  return 0;
+} // no-warning
+
+// Unbound pids are special so test them separately.
+void f4(int x) {
+  switch (x) {
+  case 0:
+vfork();
+x = 0; // expected-warning{{This assignment is prohibited after a successful vfork}}
+break;
+
+  case 1:
+{
+  char args[2];
+  switch (vfork()) {
+  case 0:
+args[0] = 0; // expected-warning{{This assignment is prohibited after a successful vfork}}
+exit(1);
+  }
+  break;
+}
+
+  case 2:
+{
+  pid_t pid;
+  if ((pid = vfork()) == 0)
+while(1); // no-warning
+  break;
+}
+  }
+  while(1);
+} //no-warning
+
+
+void f5() {
+  // See "libxtables: move some code to avoid cautions in vfork man page"
+  // (http://lists.netfilter.org/pipermail/netfilter-buglog/2014-October/003280.html).
+  if (vfork() == 0) {
+execl("prog", "arg1", 0); // no-warning
+exit(1);  // expected-warning{{This function call is prohibited after a successful vfork}}
+  }
+}
+
Index: test/Analysis/Inputs/system-header-simulator.h
===
--- test/Analysis/Inputs/system-header-simulator.h
+++ test/Analysis/Inputs/system-header-simulator.h
@@ -86,3 +86,13 @@
   char * p;
 } SomeStruct;
 void fakeSystemHeaderCall(SomeStruct *);
+
+typedef int pid_t;
+pid_t fork(void);
+pid_t vfork(void);
+int execl(const char *path, const char *arg, ...);
+
+void exit(int status) __attribute__ ((__noreturn__));
+void _exit(int status) __attribute__ ((__noreturn__));
+void _Exit(int status) __attribute__ ((__noreturn__));
+
Index: lib/StaticAnalyzer/Core/CheckerHelpers.cpp
===
--- lib/StaticAnalyzer/Core/CheckerHelpers.cpp
+++ lib/StaticAnalyzer/Core/CheckerHelpers.cpp
@@ -12,6 +12,7 @@
 //===--===//
 
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/Expr.h"
 
 // Recursively find any substatements containing macros
@@ -70,3 +71,26 @@
 
   return false;
 }
+
+// Extract lhs and rhs from assi

Re: [PATCH] D14014: Checker of proper vfork usage

2015-11-02 Thread Yury Gribov via cfe-commits
ygribov marked 5 inline comments as done.
ygribov added a comment.

http://reviews.llvm.org/D14014



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


Re: [PATCH] D14014: Checker of proper vfork usage

2015-11-02 Thread Yury Gribov via cfe-commits
ygribov added inline comments.


Comment at: lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp:118
@@ +117,3 @@
+std::tie(VD, Init) = parseAssignment(S);
+if (VD && Init)
+  S = Init;

Semantics is slightly changed for assignment case here: originally S would have 
been changed iff Init is not NULL but now I also require valid VarDecl on LHS. 
Frankly I'm not sure if it's a serious change (probably not).


http://reviews.llvm.org/D14014



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


Re: [PATCH] D14238: Fix another crash in the redundant-void-arg check.

2015-11-02 Thread Alexander Kornienko via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

Thanks for the fix! LG


http://reviews.llvm.org/D14238



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


[clang-tools-extra] r251807 - Fix another crash in the redundant-void-arg check.

2015-11-02 Thread Angel Garcia Gomez via cfe-commits
Author: angelgarcia
Date: Mon Nov  2 10:18:23 2015
New Revision: 251807

URL: http://llvm.org/viewvc/llvm-project?rev=251807&view=rev
Log:
Fix another crash in the redundant-void-arg check.

Summary: The check was assuming that a definition of a function always has a 
body, but a declaration that explicitly defaults or deletes a function is a 
definition too.

Reviewers: alexfh

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D14238

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp?rev=251807&r1=251806&r2=251807&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp Mon 
Nov  2 10:18:23 2015
@@ -116,9 +116,12 @@ void RedundantVoidArgCheck::processFunct
 const MatchFinder::MatchResult &Result, const FunctionDecl *Function) {
   SourceLocation Start = Function->getLocStart();
   if (Function->isThisDeclarationADefinition()) {
-SourceLocation BeforeBody =
-Function->getBody()->getLocStart().getLocWithOffset(-1);
-removeVoidArgumentTokens(Result, SourceRange(Start, BeforeBody),
+SourceLocation End;
+if (Function->hasBody())
+  End = Function->getBody()->getLocStart().getLocWithOffset(-1);
+else
+  End = Function->getLocEnd();
+removeVoidArgumentTokens(Result, SourceRange(Start, End),
  "function definition");
   } else {
 removeVoidArgumentTokens(Result, Function->getSourceRange(),

Modified: 
clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp?rev=251807&r1=251806&r2=251807&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp 
Mon Nov  2 10:18:23 2015
@@ -433,3 +433,9 @@ M(void inmacro(void) {})
 F(Foo, Bar) {
 
 }
+
+struct DefinitionWithNoBody {
+  DefinitionWithNoBody(void) = delete;
+  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: {{.*}} in function definition
+  // CHECK-FIXES: DefinitionWithNoBody() = delete;
+};


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


Re: r251712 - Support watchOS and tvOS in compiler-rt builds

2015-11-02 Thread Tim Northover via cfe-commits

> On 30 Oct 2015, at 14:37, Alexey Samsonov  wrote:
> Do we need to port this to CMake as well?

Yep, we're working on it. Sorry about that, I was cross-referencing a slightly 
stale patch to produce the final split commits, and missed the CMake bits we’ve 
got here. Should be sorted soon.

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


Re: [PATCH] D13786: [Sema] Implement __make_integer_seq

2015-11-02 Thread David Majnemer via cfe-commits
majnemer added a comment.

Ping.


http://reviews.llvm.org/D13786



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


Re: [PATCH] D11944: Nativize filename in FileManager::getFile().

2015-11-02 Thread Manuel Klimek via cfe-commits
klimek added a reviewer: bkramer.
klimek added a comment.

+Benjamin to share another yak :D


http://reviews.llvm.org/D11944



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


Re: [PATCH] D14198: Make the modernize-loop-convert's const-detection smarter.

2015-11-02 Thread Manuel Klimek via cfe-commits
klimek added inline comments.


Comment at: clang-tidy/modernize/LoopConvertCheck.cpp:371-374
@@ -370,1 +370,6 @@
 
+/// \brief Returns false when it can be guaranteed that no element of the
+/// container we are iterating over is going to be modified due to this
+/// expression.
+static bool canBeModified(ASTContext *Context, const Expr *E) {
+  auto Parents = Context->getParents(*E);

Not sure that is clearer. The comment should rather say what "E" is regarding 
the container.


http://reviews.llvm.org/D14198



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


Re: [PATCH] D5767: Template Instantiation Observer + a few other templight-related changes

2015-11-02 Thread Manuel Klimek via cfe-commits
klimek added a comment.

Ok, just let me know when you have an updated patch out for review for 
submission, so I can make sure we'll get the reviews done in a timely fashion. 
I really want to see this go in :)


http://reviews.llvm.org/D5767



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


Re: [PATCH] D14198: Make the modernize-loop-convert's const-detection smarter.

2015-11-02 Thread Manuel Klimek via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

LG. Much better, thanks!


http://reviews.llvm.org/D14198



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


[clang-tools-extra] r251808 - Make the modernize-loop-convert's const-detection smarter.

2015-11-02 Thread Angel Garcia Gomez via cfe-commits
Author: angelgarcia
Date: Mon Nov  2 11:02:52 2015
New Revision: 251808

URL: http://llvm.org/viewvc/llvm-project?rev=251808&view=rev
Log:
Make the modernize-loop-convert's const-detection smarter.

Summary:
Now, it detects that several kinds of usages are can't modify the elements. 
Examples:
-When an usage is a call to a const member function or operator of the element.
-If the element is used as an argument to a function or constructor that takes 
a const-reference or a value.
-LValue to RValue conversion, if the element is a fundamental type (which 
allows the use of most of the builtin operators).

Reviewers: klimek

Subscribers: cfe-commits, alexfh

Differential Revision: http://reviews.llvm.org/D14198

Added:
clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-const.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-camelback.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-lowercase.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-uppercase.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp?rev=251808&r1=251807&r2=251808&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp Mon Nov  
2 11:02:52 2015
@@ -368,11 +368,38 @@ static bool isDirectMemberExpr(const Exp
   return false;
 }
 
+/// \brief Given an expression that represents an usage of an element from the
+/// containter that we are iterating over, returns false when it can be
+/// guaranteed this element cannot be modified as a result of this usage.
+static bool canBeModified(ASTContext *Context, const Expr *E) {
+  auto Parents = Context->getParents(*E);
+  if (Parents.size() != 1)
+return true;
+  if (const auto *Cast = Parents[0].get()) {
+if ((Cast->getCastKind() == CK_NoOp &&
+ Cast->getType() == E->getType().withConst()) ||
+(Cast->getCastKind() == CK_LValueToRValue &&
+ !Cast->getType().isNull() && Cast->getType()->isFundamentalType()))
+  return false;
+  }
+  // FIXME: Make this function more generic.
+  return true;
+}
+
 /// \brief Returns true when it can be guaranteed that the elements of the
 /// container are not being modified.
-static bool usagesAreConst(const UsageResult &Usages) {
-  // FIXME: Make this function more generic.
-  return Usages.empty();
+static bool usagesAreConst(ASTContext *Context, const UsageResult &Usages) {
+  for (const Usage &U : Usages) {
+// Lambda captures are just redeclarations (VarDecl) of the same variable,
+// not expressions. If we want to know if a variable that is captured by
+// reference can be modified in an usage inside the lambda's body, we need
+// to find the expression corresponding to that particular usage, later in
+// this loop.
+if (U.Kind != Usage::UK_CaptureByCopy && U.Kind != Usage::UK_CaptureByRef 
&&
+canBeModified(Context, U.Expression))
+  return false;
+  }
+  return true;
 }
 
 /// \brief Returns true if the elements of the container are never accessed
@@ -568,9 +595,8 @@ void LoopConvertCheck::doConversion(
   Descriptor.ElemType.isTriviallyCopyableType(*Context) &&
   // TypeInfo::Width is in bits.
   Context->getTypeInfo(Descriptor.ElemType).Width <= 8 * MaxCopySize;
-  bool UseCopy =
-  CanCopy && ((VarNameFromAlias && !AliasVarIsRef) ||
-  (Descriptor.DerefByConstRef && IsCheapToCopy));
+  bool UseCopy = CanCopy && ((VarNameFromAlias && !AliasVarIsRef) ||
+ (Descriptor.DerefByConstRef && IsCheapToCopy));
 
   if (!UseCopy) {
 if (Descriptor.DerefByConstRef) {
@@ -618,7 +644,7 @@ void LoopConvertCheck::getArrayLoopQuali
   RangeDescriptor &Descriptor) {
   // On arrays and pseudoarrays, we must figure out the qualifiers from the
   // usages.
-  if (usagesAreConst(Usages) ||
+  if (usagesAreConst(Context, Usages) ||
   containerIsConst(ContainerExpr, Descriptor.ContainerNeedsDereference)) {
 Descriptor.DerefByConstRef = true;
   }

Modified: 
clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp?rev=251808&r1=251807&r2=251808&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp 
(original)
+++ clang-tools-extra/tr

Re: [PATCH] D14198: Make the modernize-loop-convert's const-detection smarter.

2015-11-02 Thread Angel Garcia via cfe-commits
angelgarcia updated this revision to Diff 38930.
angelgarcia added a comment.

OK, is it better now?


http://reviews.llvm.org/D14198

Files:
  clang-tidy/modernize/LoopConvertCheck.cpp
  test/clang-tidy/modernize-loop-convert-basic.cpp
  test/clang-tidy/modernize-loop-convert-camelback.cpp
  test/clang-tidy/modernize-loop-convert-const.cpp
  test/clang-tidy/modernize-loop-convert-extra.cpp
  test/clang-tidy/modernize-loop-convert-lowercase.cpp
  test/clang-tidy/modernize-loop-convert-uppercase.cpp

Index: test/clang-tidy/modernize-loop-convert-uppercase.cpp
===
--- test/clang-tidy/modernize-loop-convert-uppercase.cpp
+++ test/clang-tidy/modernize-loop-convert-uppercase.cpp
@@ -14,61 +14,61 @@
 printf("%d\n", ARR[I]);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert]
-  // CHECK-FIXES: for (int & ELEM : ARR)
+  // CHECK-FIXES: for (int ELEM : ARR)
   // CHECK-FIXES-NEXT: printf("%d\n", ELEM);
 
   for (int I = 0; I < N; ++I) {
 printf("%d\n", NUMS[I]);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & NUM : NUMS)
+  // CHECK-FIXES: for (int NUM : NUMS)
   // CHECK-FIXES-NEXT: printf("%d\n", NUM);
 
   for (int I = 0; I < N; ++I) {
 printf("%d\n", NUMS_[I]);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & NUM : NUMS_)
+  // CHECK-FIXES: for (int NUM : NUMS_)
   // CHECK-FIXES-NEXT: printf("%d\n", NUM);
 
   int NUM = 0;
   for (int I = 0; I < N; ++I) {
 printf("%d\n", NUMS[I] + NUM);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & ELEM : NUMS)
+  // CHECK-FIXES: for (int ELEM : NUMS)
   // CHECK-FIXES-NEXT: printf("%d\n", ELEM + NUM);
 
   int ELEM = 0;
   for (int I = 0; I < N; ++I) {
 printf("%d\n", NUMS[I] + NUM + ELEM);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & NUMS_I : NUMS)
+  // CHECK-FIXES: for (int NUMS_I : NUMS)
   // CHECK-FIXES-NEXT: printf("%d\n", NUMS_I + NUM + ELEM);
 
   int NUMS_I = 0;
   for (int I = 0; I < N; ++I) {
 printf("%d\n", NUMS[I] + NUM + ELEM + NUMS_I);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & NUMS_ELEM : NUMS)
+  // CHECK-FIXES: for (int NUMS_ELEM : NUMS)
   // CHECK-FIXES-NEXT: printf("%d\n", NUMS_ELEM + NUM + ELEM + NUMS_I);
 
   int NUMS_ELEM = 0;
   for (int I = 0; I < N; ++I) {
 printf("%d\n", NUMS[I] + NUM + ELEM + NUMS_I + NUMS_ELEM);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & GIVE_ME_NAME_0 : NUMS)
+  // CHECK-FIXES: for (int GIVE_ME_NAME_0 : NUMS)
   // CHECK-FIXES-NEXT: printf("%d\n", GIVE_ME_NAME_0 + NUM + ELEM + NUMS_I + NUMS_ELEM);
 
   int GIVE_ME_NAME_0 = 0;
   for (int I = 0; I < N; ++I) {
 printf("%d\n", NUMS[I] + NUM + ELEM + NUMS_I + NUMS_ELEM + GIVE_ME_NAME_0);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & GIVE_ME_NAME_1 : NUMS)
+  // CHECK-FIXES: for (int GIVE_ME_NAME_1 : NUMS)
   // CHECK-FIXES-NEXT: printf("%d\n", GIVE_ME_NAME_1 + NUM + ELEM + NUMS_I + NUMS_ELEM + GIVE_ME_NAME_0);
 
   int NUMS_J = 0;
@@ -79,7 +79,7 @@
   }
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
   // CHECK-MESSAGES: :[[@LINE-5]]:5: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & GIVE_ME_NAME_0 : NUMS)
-  // CHECK-FIXES: for (int & GIVE_ME_NAME_1 : NUMS)
+  // CHECK-FIXES: for (int GIVE_ME_NAME_0 : NUMS)
+  // CHECK-FIXES: for (int GIVE_ME_NAME_1 : NUMS)
   // CHECK-FIXES-NEXT: printf("%d\n", GIVE_ME_NAME_0 + GIVE_ME_NAME_1 + NUM + ELEM + NUMS_I + NUMS_J + NUMS_ELEM);
 }
Index: test/clang-tidy/modernize-loop-convert-lowercase.cpp
===
--- test/clang-tidy/modernize-loop-convert-lowercase.cpp
+++ test/clang-tidy/modernize-loop-convert-lowercase.cpp
@@ -14,61 +14,61 @@
 printf("%d\n", arr[i]);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert]
-  // CHECK-FIXES: for (int & elem : arr)
+  // CHECK-FIXES: for (int elem : arr)
   // CHECK-FIXES-NEXT: printf("%d\n", elem);
 
   for (int i = 0; i < n; ++i) {
 printf("%d\n", nums[i]);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & num : nums)
+  // CHECK-FIXES: for (int num : nums)
   // CHECK-FIXES-NEXT: printf("%d\n", num);
 
   for (int i = 0; i < n; ++i) {
 printf("%d\n", nums_[i]);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & num : nums_)
+  // CHECK-FIXES: for (int num : nums_)
  

Re: [PATCH] D13973: CFG: Delay creating Dtors for CompoundStmts which end in ReturnStmt

2015-11-02 Thread Jordan Rose via cfe-commits
jordan_rose added a subscriber: dcoughlin.
jordan_rose added a comment.

Hm. On the one hand, getting this right seems like a nice property, and even 
adding another loop wouldn't change the order of growth. On the other hand, not 
having the extra destructors seems like the same sort of property as not having 
unreachable statements, and if you //do// have unreachable statements then also 
having unreachable destructors seems reasonably consistent.

Devin, what would you think?


http://reviews.llvm.org/D13973



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


r251810 - Sink some PTHManager includes out of Preprocessor.h

2015-11-02 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Mon Nov  2 11:53:55 2015
New Revision: 251810

URL: http://llvm.org/viewvc/llvm-project?rev=251810&view=rev
Log:
Sink some PTHManager includes out of Preprocessor.h

This reduces the number of .cpp files needed to be rebuilt after
touching OnDiskHashTable from 120 to 21 for me.

Modified:
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Frontend/CacheTokens.cpp
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/lib/Lex/PPLexerChange.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=251810&r1=251809&r2=251810&view=diff
==
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Mon Nov  2 11:53:55 2015
@@ -24,7 +24,6 @@
 #include "clang/Lex/ModuleMap.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/PTHLexer.h"
-#include "clang/Lex/PTHManager.h"
 #include "clang/Lex/TokenLexer.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
@@ -57,6 +56,7 @@ class CodeCompletionHandler;
 class DirectoryLookup;
 class PreprocessingRecord;
 class ModuleLoader;
+class PTHManager;
 class PreprocessorOptions;
 
 /// \brief Stores token information for comparing actual tokens with

Modified: cfe/trunk/lib/Frontend/CacheTokens.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CacheTokens.cpp?rev=251810&r1=251809&r2=251810&view=diff
==
--- cfe/trunk/lib/Frontend/CacheTokens.cpp (original)
+++ cfe/trunk/lib/Frontend/CacheTokens.cpp Mon Nov  2 11:53:55 2015
@@ -19,6 +19,7 @@
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Lex/PTHManager.h"
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=251810&r1=251809&r2=251810&view=diff
==
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Mon Nov  2 11:53:55 2015
@@ -20,6 +20,7 @@
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Frontend/FrontendOptions.h"
 #include "clang/Lex/HeaderSearch.h"
+#include "clang/Lex/PTHManager.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Serialization/ASTReader.h"

Modified: cfe/trunk/lib/Lex/PPLexerChange.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=251810&r1=251809&r2=251810&view=diff
==
--- cfe/trunk/lib/Lex/PPLexerChange.cpp (original)
+++ cfe/trunk/lib/Lex/PPLexerChange.cpp Mon Nov  2 11:53:55 2015
@@ -18,6 +18,7 @@
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/LexDiagnostic.h"
 #include "clang/Lex/MacroInfo.h"
+#include "clang/Lex/PTHManager.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=251810&r1=251809&r2=251810&view=diff
==
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Mon Nov  2 11:53:55 2015
@@ -38,6 +38,7 @@
 #include "clang/Lex/MacroArgs.h"
 #include "clang/Lex/MacroInfo.h"
 #include "clang/Lex/ModuleLoader.h"
+#include "clang/Lex/PTHManager.h"
 #include "clang/Lex/Pragma.h"
 #include "clang/Lex/PreprocessingRecord.h"
 #include "clang/Lex/PreprocessorOptions.h"


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


r251813 - Clang format a few prior patches (NFC)

2015-11-02 Thread Teresa Johnson via cfe-commits
Author: tejohnson
Date: Mon Nov  2 12:03:12 2015
New Revision: 251813

URL: http://llvm.org/viewvc/llvm-project?rev=251813&view=rev
Log:
Clang format a few prior patches (NFC)

I had clang formatted my earlier patches using the wrong style.
Reformatted with the LLVM style.

Modified:
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/Tools.cpp

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=251813&r1=251812&r2=251813&view=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Mon Nov  2 12:03:12 2015
@@ -378,7 +378,8 @@ void Driver::setLTOMode(const llvm::opt:
   StringRef LTOName("full");
 
   const Arg *A = Args.getLastArg(options::OPT_flto_EQ);
-  if (A) LTOName = A->getValue();
+  if (A)
+LTOName = A->getValue();
 
   LTOMode = llvm::StringSwitch(LTOName)
 .Case("full", LTOK_Full)

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=251813&r1=251812&r2=251813&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Mon Nov  2 12:03:12 2015
@@ -1672,7 +1672,8 @@ static void AddGoldPlugin(const ToolChai
   if (!CPU.empty())
 CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=mcpu=") + CPU));
 
-  if (IsThinLTO) CmdArgs.push_back("-plugin-opt=thinlto");
+  if (IsThinLTO)
+CmdArgs.push_back("-plugin-opt=thinlto");
 }
 
 /// This is a helper function for validating the optional refinement step


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


Re: [PATCH] D14014: Checker of proper vfork usage

2015-11-02 Thread Anna Zaks via cfe-commits
zaks.anna added a comment.

Thanks for addressing all the comments. A couple of additional ones below.



Comment at: test/Analysis/vfork.c:60
@@ +59,3 @@
+// Ensure that returning from function is prohibited.
+return 0;
+  }

Shouldn't the warning appear here as well?

You need to register for ReturnStmt callback instead of the checkEndFunction.


Comment at: test/Analysis/vfork.c:64
@@ +63,3 @@
+  while(1);
+} // expected-warning{{Return from this function is prohibited after a 
successful vfork}}
+

I think "from this function" is redundant in this particular error message. 
"Return from this function is prohibited after a successful vfork" -> "Return 
is prohibited after a successful vfork; call _exit() instead."


http://reviews.llvm.org/D14014



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


Re: [PATCH] D13786: [Sema] Implement __make_integer_seq

2015-11-02 Thread Richard Smith via cfe-commits
rsmith added inline comments.


Comment at: lib/AST/ASTDumper.cpp:1340-1344
@@ +1339,7 @@
+  dumpName(D);
+  switch (D->getBuiltinTemplateKind()) {
+  case BTK__make_integer_seq:
+OS << " __make_integer_seq";
+break;
+  }
+  dumpTemplateParameters(D->getTemplateParameters());

This seems redundant given that you dumped the name on the prior line.


Comment at: lib/AST/DeclTemplate.cpp:1204
@@ +1203,3 @@
+
+  // Ints...
+  TypeSourceInfo *TI =

I think you mean `T ...Ints` (and likewise in comments below).


Comment at: lib/AST/DeclTemplate.cpp:1229
@@ +1228,3 @@
+
+  // Ints...
+  TypeSourceInfo *TInfo = C.getTrivialTypeSourceInfo(

This should be `T N` or similar, right? (In particular, it's not a pack.)


Comment at: lib/Sema/SemaTemplate.cpp:2176-2178
@@ -2173,1 +2175,5 @@
"type of non-dependent specialization is not a RecordType");
+  } else if (auto *BTD = dyn_cast(Template)) {
+switch (BTD->getBuiltinTemplateKind()) {
+case BTK__make_integer_seq:
+  // Specializations of __make_integer_seq are treated like

Factor this out into a separate function to compute the canonical type for a 
builtin template; `CheckTemplateIdType` is long enough already :)


Comment at: lib/Sema/SemaTemplate.cpp:2210
@@ +2209,3 @@
+Expr *E =
+BuildExpressionFromIntegralTemplateArgument(TA, SourceLocation())
+.getAs();

Maybe use the location from the third template argument here?


Comment at: lib/Serialization/ASTReaderDecl.cpp:1861
@@ +1860,3 @@
+void ASTDeclReader::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) {
+  llvm_unreachable("BuiltinTemplates are not serialized");
+}

So what happens when we serialize an AST that references a builtin template? 
It's probably best to treat them as predefined declarations (look for existing 
references to `PREDEF_DECL_*` to see how this should fit in).


http://reviews.llvm.org/D13786



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


r251821 - Fix va_arg on watchOS.

2015-11-02 Thread Tim Northover via cfe-commits
Author: tnorthover
Date: Mon Nov  2 13:32:23 2015
New Revision: 251821

URL: http://llvm.org/viewvc/llvm-project?rev=251821&view=rev
Log:
Fix va_arg on watchOS.

As in other contexts, alignments can go up to 16 bytes in a va_list.

Modified:
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/test/CodeGen/armv7k-abi.c

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=251821&r1=251820&r2=251821&view=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Mon Nov  2 13:32:23 2015
@@ -5301,6 +5301,10 @@ Address ARMABIInfo::EmitVAArg(CodeGenFun
  getABIKind() == ARMABIInfo::AAPCS) {
 TyAlignForABI = std::max(TyAlignForABI, CharUnits::fromQuantity(4));
 TyAlignForABI = std::min(TyAlignForABI, CharUnits::fromQuantity(8));
+  } else if (getABIKind() == ARMABIInfo::AAPCS16_VFP) {
+// ARMv7k allows type alignment up to 16 bytes.
+TyAlignForABI = std::max(TyAlignForABI, CharUnits::fromQuantity(4));
+TyAlignForABI = std::min(TyAlignForABI, CharUnits::fromQuantity(16));
   } else {
 TyAlignForABI = CharUnits::fromQuantity(4);
   }

Modified: cfe/trunk/test/CodeGen/armv7k-abi.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/armv7k-abi.c?rev=251821&r1=251820&r2=251821&view=diff
==
--- cfe/trunk/test/CodeGen/armv7k-abi.c (original)
+++ cfe/trunk/test/CodeGen/armv7k-abi.c Mon Nov  2 13:32:23 2015
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -triple thumbv7k-apple-watchos2.0 -target-abi aapcs16 %s -o 
- -emit-llvm | FileCheck %s
+// RUN: %clang_cc1 -triple thumbv7k-apple-watchos2.0 -target-abi aapcs16 
-target-cpu cortex-a7 %s -o - -emit-llvm | FileCheck %s
+
+#include 
 
 // Make sure 64 and 128 bit types are naturally aligned by the v7k ABI:
 
@@ -80,9 +82,12 @@ typedef struct {
 // CHECK: define [2 x i32] @return_oddly_sized_struct()
 OddlySizedStruct return_oddly_sized_struct() {}
 
-// CHECK: define double @test_va_arg(i8* %l)
-// CHECK:   load double, double*
-double test_va_arg(__builtin_va_list l) {
-  return __builtin_va_arg(l, double);
+// CHECK: define <4 x float> @test_va_arg_vec(i8* %l)
+// CHECK:   [[ALIGN_TMP:%.*]] = add i32 {{%.*}}, 15
+// CHECK:   [[ALIGNED:%.*]] = and i32 [[ALIGN_TMP]], -16
+// CHECK:   [[ALIGNED_I8:%.*]] = inttoptr i32 [[ALIGNED]] to i8*
+// CHECK:   [[ALIGNED_VEC:%.*]] = bitcast i8* [[ALIGNED_I8]] to <4 x float>
+// CHECK:   load <4 x float>, <4 x float>* [[ALIGNED_VEC]], align 16
+float32x4_t test_va_arg_vec(__builtin_va_list l) {
+  return __builtin_va_arg(l, float32x4_t);
 }
-


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


Re: [PATCH] D14096: [clang-tidy] add new check cppcoreguidelines-pro-type-cstyle-cast

2015-11-02 Thread Matthias Gehre via cfe-commits
mgehre added inline comments.


Comment at: clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp:79
@@ +78,3 @@
+  MatchedCast->getSubExprAsWritten()->IgnoreImpCasts();
+  std::string CastText = ("dynamic_cast<" + DestTypeString + ">").str();
+  if (!isa(SubExpr)) {

aaron.ballman wrote:
> How does this handle a case like:
> ```
> SomeClass::type *derived = (SomeClass::type *)someBase;
> ```
> Will it leave the spelling as "SomeClass::type *", or replace it with the 
> underlying type from the typedef? (I suspect it leaves it as-is, but it would 
> be good to have tests for more complex code patterns.)
I copied the fixit part from the google c-style cast check. I will add some 
more test for it.


http://reviews.llvm.org/D14096



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


Re: [clang-tools-extra] r250824 - Apply modernize-use-default to clang-tools-extra.

2015-11-02 Thread Alexander Kornienko via cfe-commits
On Tue, Oct 20, 2015 at 5:56 AM, Angel Garcia Gomez via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: angelgarcia
> Date: Tue Oct 20 07:56:27 2015
> New Revision: 250824
>
> URL: http://llvm.org/viewvc/llvm-project?rev=250824&view=rev
> Log:
> Apply modernize-use-default to clang-tools-extra.
>
> Summary: Replace empty bodies of default constructors and destructors with
> '= default'.
>
> Reviewers: klimek
>
> Subscribers: alexfh, cfe-commits
>
> Differential Revision: http://reviews.llvm.org/D13889
>
> Modified:
> clang-tools-extra/trunk/clang-modernize/Core/IncludeDirectives.cpp
> clang-tools-extra/trunk/clang-modernize/Core/Transform.cpp
> clang-tools-extra/trunk/clang-query/Query.cpp
> clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h
> clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.h
> clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.cpp
> clang-tools-extra/trunk/modularize/CoverageChecker.cpp
> clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp
> clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.cpp
> clang-tools-extra/trunk/unittests/clang-tidy/IncludeInserterTest.cpp
>
> Modified:
> clang-tools-extra/trunk/clang-modernize/Core/IncludeDirectives.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/Core/IncludeDirectives.cpp?rev=250824&r1=250823&r2=250824&view=diff
>
> ==
> --- clang-tools-extra/trunk/clang-modernize/Core/IncludeDirectives.cpp
> (original)
> +++ clang-tools-extra/trunk/clang-modernize/Core/IncludeDirectives.cpp Tue
> Oct 20 07:56:27 2015
> @@ -60,7 +60,7 @@ class IncludeDirectivesPPCallback : publ
>  public:
>IncludeDirectivesPPCallback(IncludeDirectives *Self)
>: Self(Self), Guard(nullptr) {}
> -  ~IncludeDirectivesPPCallback() override {}
> +  ~IncludeDirectivesPPCallback() override = default;
>
>  private:
>void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
>
> Modified: clang-tools-extra/trunk/clang-modernize/Core/Transform.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/Core/Transform.cpp?rev=250824&r1=250823&r2=250824&view=diff
>
> ==
> --- clang-tools-extra/trunk/clang-modernize/Core/Transform.cpp (original)
> +++ clang-tools-extra/trunk/clang-modernize/Core/Transform.cpp Tue Oct 20
> 07:56:27 2015
> @@ -82,7 +82,7 @@ Transform::Transform(llvm::StringRef Nam
>Reset();
>  }
>
> -Transform::~Transform() {}
> +Transform::~Transform() = default;
>
>  bool Transform::isFileModifiable(const SourceManager &SM,
>   SourceLocation Loc) const {
> @@ -150,7 +150,7 @@ Version Version::getFromString(llvm::Str
>return V;
>  }
>
> -TransformFactory::~TransformFactory() {}
> +TransformFactory::~TransformFactory() = default;
>
>  namespace {
>  bool versionSupported(Version Required, Version AvailableSince) {
>
> Modified: clang-tools-extra/trunk/clang-query/Query.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-query/Query.cpp?rev=250824&r1=250823&r2=250824&view=diff
>
> ==
> --- clang-tools-extra/trunk/clang-query/Query.cpp (original)
> +++ clang-tools-extra/trunk/clang-query/Query.cpp Tue Oct 20 07:56:27 2015
> @@ -20,7 +20,7 @@ using namespace clang::ast_matchers::dyn
>  namespace clang {
>  namespace query {
>
> -Query::~Query() {}
> +Query::~Query() = default;
>
>  bool InvalidQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
>OS << ErrStr << "\n";
>
> Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h?rev=250824&r1=250823&r2=250824&view=diff
>
> ==
> --- clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h (original)
> +++ clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h Tue Oct 20
> 07:56:27 2015
> @@ -82,7 +82,7 @@ private:
>  /// them a prefixed name.
>  class ClangTidyModule {
>  public:
> -  virtual ~ClangTidyModule() {}
> +  virtual ~ClangTidyModule() = default;
>
>/// \brief Implement this function in order to register all \c
> CheckFactories
>/// belonging to this module.
>
> Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.h
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.h?rev=250824&r1=250823&r2=250824&view=diff
>
> ==
> --- clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.h (original)
> +++ clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.h Tue Oct 20
> 07:56:27 2015
> @@ -88,7 +88,7 @@ struct ClangTidyOptions {
>  /// \brief Abstract interfa

r251824 - clang-format: Simplify and improve stop condition for formatting

2015-11-02 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Nov  2 14:02:49 2015
New Revision: 251824

URL: http://llvm.org/viewvc/llvm-project?rev=251824&view=rev
Log:
clang-format: Simplify and improve stop condition for formatting
unaffected lines with incorrect initial indent.

Starting from:
  namespace {
int i; // There shouldn't be indentation here.
int j; // <- call clang-format on this line.
  }

Before:
  namespace {
int i;
int j;
}

After:
  namespace {
int i;
int j;
  }

Modified:
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/unittests/Format/FormatTestSelective.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp?rev=251824&r1=251823&r2=251824&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp Mon Nov  2 14:02:49 2015
@@ -815,8 +815,6 @@ UnwrappedLineFormatter::format(const Sma
 
   // The minimum level of consecutive lines that have been formatted.
   unsigned RangeMinLevel = UINT_MAX;
-  // The level of the previous line.
-  unsigned PreviousLineLevel = Lines.front()->Level;
 
   for (const AnnotatedLine *Line =
Joiner.getNextMergedLine(DryRun, IndentTracker);
@@ -830,8 +828,7 @@ UnwrappedLineFormatter::format(const Sma
 // remaining file if it currently missing a closing brace.
 bool ContinueFormatting =
 TheLine.Level > RangeMinLevel ||
-(TheLine.Level == RangeMinLevel && PreviousLineLevel <= TheLine.Level);
-PreviousLineLevel = TheLine.Level;
+(TheLine.Level == RangeMinLevel && !TheLine.startsWith(tok::r_brace));
 
 bool FixIndentation = (FixBadIndentation || ContinueFormatting) &&
   Indent != TheLine.First->OriginalColumn;

Modified: cfe/trunk/unittests/Format/FormatTestSelective.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestSelective.cpp?rev=251824&r1=251823&r2=251824&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestSelective.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestSelective.cpp Mon Nov  2 14:02:49 2015
@@ -273,6 +273,27 @@ TEST_F(FormatTestSelective, IndividualSt
0, 0));
 }
 
+TEST_F(FormatTestSelective, WrongIndent) {
+  EXPECT_EQ("namespace {\n"
+"int i;\n"
+"int j;\n"
+"}",
+format("namespace {\n"
+   "  int i;\n" // Format here.
+   "  int j;\n"
+   "}",
+   15, 0));
+  EXPECT_EQ("namespace {\n"
+"  int i;\n"
+"  int j;\n"
+"}",
+format("namespace {\n"
+   "  int i;\n"
+   "  int j;\n" // Format here.
+   "}",
+   24, 0));
+}
+
 TEST_F(FormatTestSelective, AlwaysFormatsEntireMacroDefinitions) {
   Style.AlignEscapedNewlinesLeft = true;
   EXPECT_EQ("int  i;\n"


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


Re: [PATCH] D12922: Add support for function attribute "notail"

2015-11-02 Thread Akira Hatanaka via cfe-commits
ahatanak updated this revision to Diff 38967.
ahatanak added a comment.

Fixed test cases:

- Added a test case for the attribute being specified on a variable.
- Added a missing 's' to "virtual function" in the check strings.


http://reviews.llvm.org/D12922

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/CGCall.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/attr-no-tail.c
  test/CodeGenCXX/attr-notail.cpp
  test/Sema/attr-notail.c
  test/SemaCXX/attr-notail.cpp

Index: test/SemaCXX/attr-notail.cpp
===
--- /dev/null
+++ test/SemaCXX/attr-notail.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+class Base {
+public:
+  [[clang::not_tail_called]] virtual int foo1(); // expected-error {{'not_tail_called' attribute cannot be applied to virtual functions}}
+  virtual int foo2();
+  [[clang::not_tail_called]] int foo3();
+  virtual ~Base() {}
+};
+
+class Derived1 : public Base {
+public:
+  int foo1() override;
+  [[clang::not_tail_called]] int foo2() override; // expected-error {{'not_tail_called' attribute cannot be applied to virtual functions}}
+  [[clang::not_tail_called]] int foo4();
+};
Index: test/Sema/attr-notail.c
===
--- /dev/null
+++ test/Sema/attr-notail.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int callee0() __attribute__((not_tail_called,always_inline)); // expected-error{{'not_tail_called' and 'always_inline' attributes are not compatible}}
+int callee1() __attribute__((always_inline,not_tail_called)); // expected-error{{'always_inline' and 'not_tail_called' attributes are not compatible}}
+
+int foo(int a) {
+  return a ? callee0() : callee1();
+}
+
+int g0 __attribute__((not_tail_called)); // expected-warning {{'not_tail_called' attribute only applies to functions}}
Index: test/CodeGenCXX/attr-notail.cpp
===
--- /dev/null
+++ test/CodeGenCXX/attr-notail.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple=x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s | FileCheck %s
+
+class Class1 {
+public:
+  [[clang::not_tail_called]] int m1();
+  int m2();
+};
+
+int foo1(int a, Class1 *c1) {
+  if (a)
+return c1->m1();
+  return c1->m2();
+}
+
+// CHECK-LABEL: define i32 @_Z4foo1iP6Class1(
+// CHECK: %{{[a-z0-9]+}} = notail call i32 @_ZN6Class12m1Ev(%class.Class1*
+// CHECK: %{{[a-z0-9]+}} = call i32 @_ZN6Class12m2Ev(%class.Class1*
Index: test/CodeGen/attr-no-tail.c
===
--- /dev/null
+++ test/CodeGen/attr-no-tail.c
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.7.0 %s -emit-llvm -o - | FileCheck %s
+
+// CHECK: %{{[a-z0-9]+}} = notail call i32 @callee0(i32 %
+// CHECK: %{{[a-z0-9]+}} = notail call i32 @callee1(i32 %
+
+// Check that indirect calls do not have the notail marker.
+// CHECK: store i32 (i32)* @callee1, i32 (i32)** [[ALLOCA1:%[A-Za-z0-9]+]], align 8
+// CHECK: [[INDIRFUNC:%[0-9]+]] = load i32 (i32)*, i32 (i32)** [[ALLOCA1]], align 8
+// CHECK: %{{[a-z0-9]+}} = call i32 [[INDIRFUNC]](i32 %6)
+
+// CHECK: %{{[a-z0-9]+}} = call i32 @callee2(i32 %
+
+int callee0(int a) __attribute__((not_tail_called)) {
+  return a + 1;
+}
+
+int callee1(int) __attribute__((not_tail_called));
+
+int callee2(int);
+
+typedef int (*FuncTy)(int);
+
+int foo0(int a) {
+  if (a > 1)
+return callee0(a);
+  if (a == 1)
+return callee1(a);
+  if (a < 0) {
+FuncTy F = callee1;
+return (*F)(a);
+  }
+  return callee2(a);
+}
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -1701,6 +1701,15 @@
Attr.getAttributeSpellingListIndex()));
 }
 
+static void handleNotTailCalledAttr(Sema &S, Decl *D,
+const AttributeList &Attr) {
+  if (checkAttrMutualExclusion(S, D, Attr))
+return;
+
+  D->addAttr(::new (S.Context) NotTailCalledAttr(
+  Attr.getRange(), S.Context, Attr.getAttributeSpellingListIndex()));
+}
+
 static void handleUsedAttr(Sema &S, Decl *D, const AttributeList &Attr) {
   if (const VarDecl *VD = dyn_cast(D)) {
 if (VD->hasLocalStorage()) {
@@ -3419,6 +3428,9 @@
 
 static void handleAlwaysInlineAttr(Sema &S, Decl *D,
const AttributeList &Attr) {
+  if (checkAttrMutualExclusion(S, D, Attr))
+return;
+
   if (AlwaysInlineAttr *Inline = S.mergeAlwaysInlineAttr(
   D, Attr.getRange(), Attr.getName(),
   Attr.getAttributeSpellingListIndex()))
@@ -4991,6 +5003,9 @@
   case AttributeList::AT_ReturnsTwice:
 handleSimpleAttribute(S, D, Attr);
 break;
+  case AttributeList::AT_NotTailCalled:
+handleNotTailCalledAttr(S, 

Re: [PATCH] D12922: Add support for function attribute "notail"

2015-11-02 Thread Akira Hatanaka via cfe-commits
ahatanak added inline comments.


Comment at: test/Sema/attr-notail.c:9
@@ +8,3 @@
+}
+
+int g0 __attribute__((not_tail_called)); // expected-warning 
{{'not_tail_called' attribute only applies to functions}}

I didn't understand what kind of test case is required for not_tail_called on 
passed arguments. Could you give me an example? 


http://reviews.llvm.org/D12922



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


r251828 - [PTH] Fix data length used for stat cache entries

2015-11-02 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Mon Nov  2 14:47:31 2015
New Revision: 251828

URL: http://llvm.org/viewvc/llvm-project?rev=251828&view=rev
Log:
[PTH] Fix data length used for stat cache entries

This came up in a boost build, which apparently uses PTH. This was
broken in r187619 when we migrated it to uses llvm::fs instead of raw
stat calls.

Constructing a test case with a hash table collision in-tree is tough.
Instead, I have a pending change to OnDiskChainedHashTable that asserts
that the reported length of the data agrees with the data actually
written. All of the existing in-tree tests find the bug with this
assert.

Modified:
cfe/trunk/lib/Frontend/CacheTokens.cpp

Modified: cfe/trunk/lib/Frontend/CacheTokens.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CacheTokens.cpp?rev=251828&r1=251827&r2=251828&view=diff
==
--- cfe/trunk/lib/Frontend/CacheTokens.cpp (original)
+++ cfe/trunk/lib/Frontend/CacheTokens.cpp Mon Nov  2 14:47:31 2015
@@ -106,7 +106,7 @@ public:
   }
 
   unsigned getRepresentationLength() const {
-return Kind == IsNoExist ? 0 : 4 + 4 + 2 + 8 + 8;
+return Kind == IsNoExist ? 0 : 4 * 8;
   }
 };
 


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


Re: [PATCH] D14170: Fix false positive warning about memory leak for QApplication::postEvent

2015-11-02 Thread Anna Zaks via cfe-commits
zaks.anna added a comment.

This needs a test case. You can either extend ./test/Analysis/malloc.cpp or add 
another QT specific test file.

Thanks!
Anna.


http://reviews.llvm.org/D14170



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


r251832 - watchOS & tvOS: add a few more tests.

2015-11-02 Thread Tim Northover via cfe-commits
Author: tnorthover
Date: Mon Nov  2 15:14:48 2015
New Revision: 251832

URL: http://llvm.org/viewvc/llvm-project?rev=251832&view=rev
Log:
watchOS & tvOS: add a few more tests.

Modified:
cfe/trunk/test/Driver/darwin-version.c
cfe/trunk/test/Driver/implicit-function-as-error.c
cfe/trunk/test/Sema/attr-availability-app-extensions.c
cfe/trunk/test/Sema/attr-availability-tvos.c
cfe/trunk/test/Sema/attr-availability-watchos.c

Modified: cfe/trunk/test/Driver/darwin-version.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/darwin-version.c?rev=251832&r1=251831&r2=251832&view=diff
==
--- cfe/trunk/test/Driver/darwin-version.c (original)
+++ cfe/trunk/test/Driver/darwin-version.c Mon Nov  2 15:14:48 2015
@@ -41,6 +41,8 @@
 // RUN: %clang -target i386-apple-darwin -mtvos-simulator-version-min=8.3 -c 
%s -### 2>&1 | \
 // RUN:   FileCheck --check-prefix=CHECK-VERSION-TVSIM83 %s
 // CHECK-VERSION-TVSIM83: "i386-apple-tvos8.3.0"
+// RUN: %clang -target armv7k-apple-darwin -mwatchos-version-min=2.0 -c %s 
-### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-VERSION-WATCHOS20 %s
 // CHECK-VERSION-WATCHOS20: "thumbv7k-apple-watchos2.0.0"
 // RUN: %clang -target i386-apple-darwin -mwatchos-simulator-version-min=2.0 
-c %s -### 2>&1 | \
 // RUN:   FileCheck --check-prefix=CHECK-VERSION-WATCHSIM20 %s

Modified: cfe/trunk/test/Driver/implicit-function-as-error.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/implicit-function-as-error.c?rev=251832&r1=251831&r2=251832&view=diff
==
--- cfe/trunk/test/Driver/implicit-function-as-error.c (original)
+++ cfe/trunk/test/Driver/implicit-function-as-error.c Mon Nov  2 15:14:48 2015
@@ -1,5 +1,6 @@
 // RUN: %clang -target x86_64-apple-darwin -mios-simulator-version-min=7 
-fsyntax-only %s -Xclang -verify
 // RUN: %clang -target x86_64-apple-darwin -arch arm64 -target 
x86_64-apple-darwin -mios-version-min=7 -fsyntax-only %s -Xclang -verify
+// RUN: %clang -target armv7k-apple-watchos -arch armv7k -target 
armv7k-apple-watchos -fsyntax-only %s -Xclang -verify
 
 // For 64-bit iOS, automatically promote -Wimplicit-function-declaration
 // to an error.

Modified: cfe/trunk/test/Sema/attr-availability-app-extensions.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-availability-app-extensions.c?rev=251832&r1=251831&r2=251832&view=diff
==
--- cfe/trunk/test/Sema/attr-availability-app-extensions.c (original)
+++ cfe/trunk/test/Sema/attr-availability-app-extensions.c Mon Nov  2 15:14:48 
2015
@@ -1,14 +1,24 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9.0 -fsyntax-only 
-fapplication-extension %s -verify
 // RUN: %clang_cc1 -triple armv7-apple-ios9.0 -fsyntax-only 
-fapplication-extension %s -verify
+// RUN: %clang_cc1 -triple arm64-apple-tvos3.0 -fsyntax-only 
-fapplication-extension -DTVOS=1 -verify %s
+// RUN: %clang_cc1 -triple arm64-apple-tvos3.0 -fsyntax-only 
-fapplication-extension -verify %s
 
 #if __has_feature(attribute_availability_app_extension)
  __attribute__((availability(macosx_app_extension,unavailable)))
+#ifndef TVOS
  __attribute__((availability(ios_app_extension,unavailable)))
+#else
+ __attribute__((availability(tvos_app_extension,unavailable)))
+#endif
 #endif
 void f0(int); // expected-note {{'f0' has been explicitly marked unavailable 
here}}
 
 __attribute__((availability(macosx,unavailable)))
+#ifndef TVOS
 __attribute__((availability(ios,unavailable)))
+#else
+  __attribute__((availability(tvos,unavailable)))
+#endif
 void f1(int); // expected-note {{'f1' has been explicitly marked unavailable 
here}}
 
 void test() {

Modified: cfe/trunk/test/Sema/attr-availability-tvos.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-availability-tvos.c?rev=251832&r1=251831&r2=251832&view=diff
==
--- cfe/trunk/test/Sema/attr-availability-tvos.c (original)
+++ cfe/trunk/test/Sema/attr-availability-tvos.c Mon Nov  2 15:14:48 2015
@@ -19,3 +19,41 @@ void test() {
   f5(0); // expected-warning{{'f5' is deprecated: first deprecated in tvOS 
3.0}}
   f6(0); // expected-warning{{'f6' is deprecated: first deprecated in tvOS 
3.0}}
 }
+
+// Anything iOS later than 8 does not apply to tvOS.
+void f9(int) __attribute__((availability(ios,introduced=2.0,deprecated=9.0)));
+
+void test_transcribed_availability() {
+  f9(0);
+}
+
+// Test tvOS specific attributes.
+void f0_tvos(int) 
__attribute__((availability(tvos,introduced=2.0,deprecated=2.1))); // 
expected-note {{'f0_tvos' has been explicitly marked deprecated here}}
+void f1_tvos(int) __attribute__((availability(tvos,introduced=2.1)));
+void f2_tvos(int) 
__attribute__((availability(tvos,introduced=2.0,deprecated=3.0))); // 
expected-no

[PATCH] D14259: The maximum alignment of std::aligned_storage applies to all Windows compilers

2015-11-02 Thread Reid Kleckner via cfe-commits
rnk created this revision.
rnk added reviewers: danalbert, mclow.lists.
rnk added a subscriber: cfe-commits.

According to Clang's sources, the maximum supported storage alignment is a
property of the COFF object file format. Fixes building libc++ 
with Clang on Windows.

http://reviews.llvm.org/D14259

Files:
  include/type_traits

Index: include/type_traits
===
--- include/type_traits
+++ include/type_traits
@@ -1147,10 +1147,10 @@
 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800);
 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000);
 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000);
-// MSDN says that MSVC does not support alignment beyond 8192 (=0x2000)
-#if !defined(_LIBCPP_MSVC)
+// PE COFF does not support alignment beyond 8192 (=0x2000)
+#if !defined(_WIN32)
 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000);
-#endif // !_LIBCPP_MSVC
+#endif // !_WIN32
 
 #undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION
 


Index: include/type_traits
===
--- include/type_traits
+++ include/type_traits
@@ -1147,10 +1147,10 @@
 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800);
 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000);
 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000);
-// MSDN says that MSVC does not support alignment beyond 8192 (=0x2000)
-#if !defined(_LIBCPP_MSVC)
+// PE COFF does not support alignment beyond 8192 (=0x2000)
+#if !defined(_WIN32)
 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000);
-#endif // !_LIBCPP_MSVC
+#endif // !_WIN32
 
 #undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


RE: [PATCH] D14239: mips-mti-linux TC + debug log

2015-11-02 Thread Vasileios Kalintiris via cfe-commits
Hi Renato,

Thanks for testing this. The /tmp/mips-mti-linux.log file contains log messages 
from the driver. It wasn't my intention to match anything meaningful from the 
mips-mti-linux.c test. 

I'll try to investigate what's going wrong tomorrow.

Thanks,
Vasileios

From: Renato Golin [renato.go...@linaro.org]
Sent: 02 November 2015 18:56
To: Clang Commits
Cc: Vasileios Kalintiris; JF Bastien; Derek Schuff
Subject: Re: [PATCH] D14239: mips-mti-linux TC + debug log

On 2 November 2015 at 16:35, Vasileios Kalintiris
 wrote:
> Can you apply this
> patch, build LLVM+Clang and run with llvm-lit the mips-mti-linux.c test?

Hi Vasileios,

I just built once and the test already fails with FileCheck reporting
empty output. Logs attached.

You seem to be sending the BE stderr to /tmp/mips-mti-linux.log, which
is not standard practice. You should either use the %t (for temp file)
or parse it together with stdout, as you do on the second line (LE).

If I put both to stdout, I still get FileCheck errors. Logs also attached.

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


Re: [PATCH] D13973: CFG: Delay creating Dtors for CompoundStmts which end in ReturnStmt

2015-11-02 Thread Matthias Gehre via cfe-commits
mgehre added a comment.

Basically, there are the following cases:
A)

  void f() {
S s;
  }

Everything OK, only one (reachable) destructor is generated
B)

  int f() {
S s;
return 1;
  }

In current trunk, this first generates dtor in a block when visiting the 
CompoundStmt,
and then abandons that block when visiting the ReturnStmt. Thus we have one 
unreachable block just containing the dtor.
C)

  int f() {
S s;
return 1;
int i = 1;
  }

Like B), but the unreachable block also contains "int i = 1".
D)

  int f(bool b) {
S s;
if(b)
  return 1;
else
  return 17;
  }

Like B), but not fixed by this patch.
E)
Any combination of B) or D) with "throw" or a noreturn function instead of 
"return". Not fixed by the current patch.

I think that case B) is a common thing, and thus it's handled by this patch. 
Handling case B) with a 'throw' instead of 'return'
should be easy enough, too. 
C) is a bit unusual due to the unreachable statement, thus I think that we 
should not optimize for that corner case.
D) more usual, but not easy to fix.

I currently see the following ways forward:

1. Extend this patch to cover also "throw", fixing case B)
2. Do 1) plus loop over the whole body to also fix case C)
3. Drop this patch and instead remove unreachable blocks after the whole CFG 
has been generated (by mark-and-sweep), fixing B), C) and D)

The following comment at the beginning of VisitReturnStmt() indicates that this 
was planned

  // NOTE: If a "return" appears in the middle of a block, this means that the
  //   code afterwards is DEAD (unreachable).  We still keep a basic block
  //   for that code; a simple "mark-and-sweep" from the entry block will be
  //   able to report such dead blocks.

I'm not sure if that is actually done.


http://reviews.llvm.org/D13973



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


[libcxx] r251836 - Make reverse() call iter_swap like the standard says, instead of calling swap directly. No real change.

2015-11-02 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Mon Nov  2 15:34:25 2015
New Revision: 251836

URL: http://llvm.org/viewvc/llvm-project?rev=251836&view=rev
Log:
Make reverse() call iter_swap like the standard says, instead of calling swap 
directly. No real change.

Modified:
libcxx/trunk/include/algorithm

Modified: libcxx/trunk/include/algorithm
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=251836&r1=251835&r2=251836&view=diff
==
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Mon Nov  2 15:34:25 2015
@@ -2330,7 +2330,7 @@ __reverse(_BidirectionalIterator __first
 {
 if (__first == --__last)
 break;
-swap(*__first, *__last);
+_VSTD::iter_swap(__first, __last);
 ++__first;
 }
 }
@@ -2342,7 +2342,7 @@ __reverse(_RandomAccessIterator __first,
 {
 if (__first != __last)
 for (; __first < --__last; ++__first)
-swap(*__first, *__last);
+_VSTD::iter_swap(__first, __last);
 }
 
 template 


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


Re: [PATCH] D13925: Implement __attribute__((internal_linkage))

2015-11-02 Thread Evgeniy Stepanov via cfe-commits
eugenis updated this revision to Diff 38979.
eugenis added a comment.

Added a [[clang::internal_linkage]] spelling to the attribute.
Added tests for namespace re-declarations with and without the attribute.


Repository:
  rL LLVM

http://reviews.llvm.org/D13925

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Sema/Sema.h
  lib/AST/Decl.cpp
  lib/Sema/Sema.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGenCXX/attribute_internal_linkage.cpp
  test/Sema/internal_linkage.c
  test/SemaCXX/internal_linkage.cpp

Index: test/SemaCXX/internal_linkage.cpp
===
--- /dev/null
+++ test/SemaCXX/internal_linkage.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int f() __attribute__((internal_linkage));
+class __attribute__((internal_linkage)) A {
+public:
+  int x __attribute__((internal_linkage)); // expected-warning{{'internal_linkage' attribute ignored}}
+  static int y __attribute__((internal_linkage));
+  void f1() __attribute__((internal_linkage));
+  void f2() __attribute__((internal_linkage)) {}
+  static void f3() __attribute__((internal_linkage)) {}
+  A() __attribute__((internal_linkage)) {}
+  ~A() __attribute__((internal_linkage)) {}
+  A& operator=(const A&) __attribute__((internal_linkage)) { return *this; }
+  struct {
+int z  __attribute__((internal_linkage)); // expected-warning{{'internal_linkage' attribute ignored}}
+  };
+};
+
+namespace Z __attribute__((internal_linkage)) {
+}
+
+int A::y;
+
+void A::f1() {
+}
Index: test/Sema/internal_linkage.c
===
--- /dev/null
+++ test/Sema/internal_linkage.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int var __attribute__((internal_linkage));
+int var2 __attribute__((internal_linkage,common)); // expected-error{{'internal_linkage' and 'common' attributes are not compatible}} \
+   // expected-note{{conflicting attribute is here}}
+int var3 __attribute__((common,internal_linkage)); // expected-error{{'common' and 'internal_linkage' attributes are not compatible}} \
+   // expected-note{{conflicting attribute is here}}
+
+int var4 __attribute__((common)); // expected-error{{'common' and 'internal_linkage' attributes are not compatible}}
+int var4 __attribute__((internal_linkage)); // expected-note{{conflicting attribute is here}}
+
+int var5 __attribute__((internal_linkage)); // expected-error{{'internal_linkage' and 'common' attributes are not compatible}}
+int var5 __attribute__((common)); // expected-note{{conflicting attribute is here}}
+
+ __attribute__((internal_linkage)) int f() {}
+struct __attribute__((internal_linkage)) S {
+};
Index: test/CodeGenCXX/attribute_internal_linkage.cpp
===
--- /dev/null
+++ test/CodeGenCXX/attribute_internal_linkage.cpp
@@ -0,0 +1,101 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++11 -emit-llvm -o - %s | FileCheck %s
+
+__attribute__((internal_linkage)) static void f() {}
+// CHECK-DAG: define internal void @_ZL1fv
+
+class A {
+public:
+  static int y __attribute__((internal_linkage));
+  static int y2 [[clang::internal_linkage]];
+// CHECK-DAG: @_ZN1A1yE = internal global
+// CHECK-DAG: @_ZN1A2y2E = internal global
+  void f1() __attribute__((internal_linkage));
+// CHECK-DAG: define internal void @_ZN1A2f1Ev
+  void f2() __attribute__((internal_linkage)) {}
+// CHECK-DAG: define internal void @_ZN1A2f2Ev
+  void f3();
+// CHECK-DAG: define internal void @_ZN1A2f3Ev
+  static void f4() __attribute__((internal_linkage)) {}
+// CHECK-DAG: define internal void @_ZN1A2f4Ev
+  A() __attribute__((internal_linkage)) {}
+// CHECK-DAG: define internal void @_ZN1AC1Ev
+// CHECK-DAG: define internal void @_ZN1AC2Ev
+  ~A() __attribute__((internal_linkage)) {}
+// CHECK-DAG: define internal void @_ZN1AD1Ev
+// CHECK-DAG: define internal void @_ZN1AD2Ev
+};
+
+int A::y;
+int A::y2;
+
+void A::f1() {
+}
+
+__attribute__((internal_linkage)) void A::f3() {
+}
+
+// Internal_linkage on a namespace affects everything within.
+namespace ZZZ __attribute__((internal_linkage)) {
+int x;
+// CHECK-DAG: @_ZNL3ZZZL1xE = internal global
+void f() {}
+// CHECK-DAG: define internal void @_ZNL3ZZZL1fEv
+class A {
+public:
+  A() {}
+// CHECK-DAG: define internal void @_ZNL3ZZZL1AC1Ev
+// CHECK-DAG: define internal void @_ZNL3ZZZL1AC2Ev
+  ~A() {}
+// CHECK-DAG: define internal void @_ZNL3ZZZL1AD1Ev
+// CHECK-DAG: define internal void @_ZNL3ZZZL1AD2Ev
+  void g() {};
+// CHECK-DAG: define internal void @_ZNL3ZZZL1A1gEv
+};
+}
+
+namespace ZZZ {
+int x2;
+// CHECK-DAG: @_ZN3ZZZ2x2E = global i32
+}
+
+namespace [[clang::internal_linkage]] ZZZ {
+int x3;
+// CHECK-DAG: @_ZNL3ZZZL2x3E = internal global
+}
+
+// Internal_linkage on a class affects all its m

Re: [PATCH] D14096: [clang-tidy] add new check cppcoreguidelines-pro-type-cstyle-cast

2015-11-02 Thread Matthias Gehre via cfe-commits
mgehre added inline comments.


Comment at: clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp:80
@@ +79,3 @@
+  std::string CastText = ("dynamic_cast<" + DestTypeString + ">").str();
+  if (!isa(SubExpr)) {
+CastText.push_back('(');

aaron.ballman wrote:
> Why do we need this check? Perhaps we want to use IgnoreParenImpCasts() 
> instead?
If the cast looks like
```
Derived* D = (Derived*)B;
```
we need to add parenthesis around B to turn it into
```
Derived* D = dynamic_cast(B);
```
If instead we already had
```
Derived* D = (Derived*)(B);
```
adding the parenthesis can be skipped.


http://reviews.llvm.org/D14096



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


Re: [PATCH] D14096: [clang-tidy] add new check cppcoreguidelines-pro-type-cstyle-cast

2015-11-02 Thread Matthias Gehre via cfe-commits
mgehre updated this revision to Diff 38981.
mgehre added a comment.

Update for review comments


http://reviews.llvm.org/D14096

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp
  clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.h
  docs/clang-tidy/checks/cppcoreguidelines-pro-type-cstyle-cast.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-pro-type-cstyle-cast.cpp

Index: test/clang-tidy/cppcoreguidelines-pro-type-cstyle-cast.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-pro-type-cstyle-cast.cpp
@@ -0,0 +1,141 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-cstyle-cast %t
+
+void reinterpretcast() {
+  int i = 0;
+  void *j;
+  j = (int*)j;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]
+}
+
+void constcast() {
+  int* i;
+  const int* j;
+  i = (int*)j;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not use C-style cast to cast away constness [cppcoreguidelines-pro-type-cstyle-cast]
+  j = (const int*)i; // OK, const added
+  (void)j; // OK, not a const_cast
+}
+
+void const_and_reinterpret() {
+  int* i;
+  const void* j;
+  i = (int*)j;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]
+}
+
+class Base {
+};
+
+class Derived : public Base {
+};
+
+class Base2 {
+};
+
+class MultiDerived : public Base, public Base2 {
+};
+
+class PolymorphicBase {
+public:
+  virtual ~PolymorphicBase();
+};
+
+class PolymorphicDerived : public PolymorphicBase {
+};
+
+class PolymorphicMultiDerived : public Base, public PolymorphicBase {
+};
+
+void pointers() {
+
+  auto P0 = (Derived*)new Base();
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use C-style cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-cstyle-cast]
+
+  const Base* B0;
+  auto PC0 = (const Derived*)(B0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use C-style cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-cstyle-cast]
+
+  auto P1 = (Base*)new Derived(); // OK, upcast to a public base
+  auto P2 = (Base*)new MultiDerived(); // OK, upcast to a public base
+  auto P3 = (Base2*)new MultiDerived(); // OK, upcast to a public base
+}
+
+void pointers_polymorphic() {
+
+  auto PP0 = (PolymorphicDerived*)new PolymorphicBase();
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use C-style cast to downcast from a base to a derived class; use dynamic_cast instead [cppcoreguidelines-pro-type-cstyle-cast]
+  // CHECK-FIXES: auto PP0 = dynamic_cast(new PolymorphicBase());
+
+  const PolymorphicBase* B0;
+  auto PPC0 = (const PolymorphicDerived*)B0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: do not use C-style cast to downcast from a base to a derived class; use dynamic_cast instead [cppcoreguidelines-pro-type-cstyle-cast]
+  // CHECK-FIXES: auto PPC0 = dynamic_cast(B0);
+
+
+  auto B1 = (PolymorphicBase*)new PolymorphicDerived(); // OK, upcast to a public base
+  auto B2 = (PolymorphicBase*)new PolymorphicMultiDerived(); // OK, upcast to a public base
+  auto B3 = (Base*)new PolymorphicMultiDerived(); // OK, upcast to a public base
+}
+
+void arrays() {
+  Base ArrayOfBase[10];
+  auto A0 = (Derived*)ArrayOfBase;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use C-style cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-cstyle-cast]
+}
+
+void arrays_polymorphic() {
+  PolymorphicBase ArrayOfPolymorphicBase[10];
+  auto AP0 = (PolymorphicDerived*)ArrayOfPolymorphicBase;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use C-style cast to downcast from a base to a derived class; use dynamic_cast instead
+  // CHECK-FIXES: auto AP0 = dynamic_cast(ArrayOfPolymorphicBase);
+}
+
+void references() {
+  Base B0;
+  auto R0 = (Derived&)B0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use C-style cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-cstyle-cast]
+  Base& RefToBase = B0;
+  auto R1 = (Derived&)RefToBase;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use C-style cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-cstyle-cast]
+
+  const Base& ConstRefToBase = B0;
+  auto RC1 = (const Derived&)ConstRefToBase;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use C-style cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-cstyle-cast]
+
+
+  Derived RD1;
+  auto R2 = (Base&)RD1; // OK, upcast to a public base
+}
+
+void references_polymorphic() {
+  PolymorphicBase B0;
+  auto RP0 = (PolymorphicDerived&)B0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use C-style cast to downcast from a base to a der

Re: [PATCH] D13925: Implement __attribute__((internal_linkage))

2015-11-02 Thread Reid Kleckner via cfe-commits
rnk accepted this revision.
rnk added a reviewer: rnk.
rnk added a comment.
This revision is now accepted and ready to land.

I'm happy with this. Richard, what do you think?


Repository:
  rL LLVM

http://reviews.llvm.org/D13925



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


Re: [PATCH] D13925: Implement __attribute__((internal_linkage))

2015-11-02 Thread Richard Smith via cfe-commits
rsmith added inline comments.


Comment at: include/clang/Basic/Attr.td:2125
@@ +2124,3 @@
+
+def InternalLinkage : InheritableAttr {
+  let Spellings = [GNU<"internal_linkage">, CXX11<"clang", 
"internal_linkage">];

`InheritableAttr` doesn't seem right for the case when this is applied to a 
namespace.


Comment at: lib/AST/Decl.cpp:1358-1362
@@ -1346,3 +1357,7 @@
 }
-assert(!Old || Old->getCachedLinkage() == D->getCachedLinkage());
+// Linkages may also differ if one of the declarations has
+// InternalLinkageAttr.
+assert(!Old || Old->getCachedLinkage() == D->getCachedLinkage() ||
+   (Old->hasAttr() !=
+D->hasAttr()));
 #endif

We shouldn't allow the linkage to be changed after the first declaration. What 
cases cause problems here?


Comment at: lib/Sema/Sema.cpp:539
@@ -538,3 +538,3 @@
 
-if (!ND->isExternallyVisible()) {
+if (!ND->isExternallyVisible() || ND->hasAttr()) {
   S.Diag(ND->getLocation(), diag::warn_undefined_internal)

Hmm, what should `isExternallyVisible` return for a declaration with this 
attribute? Presumably it should be `false`...


Repository:
  rL LLVM

http://reviews.llvm.org/D13925



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


Re: [PATCH] D14191: Make ArgumentAdjuster aware of the current file being processed.

2015-11-02 Thread Alexander Kornienko via cfe-commits
alexfh added a comment.

Ping.


http://reviews.llvm.org/D14191



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


Re: [PATCH] D14192: Add ExtraArgs and ExtraArgsBefore options to enable clang warnings via configuration files.

2015-11-02 Thread Alexander Kornienko via cfe-commits
alexfh added a comment.

Ping.


http://reviews.llvm.org/D14192



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


Re: [PATCH] D14179: Remove some legacy mingw-w64 gcc struct info

2015-11-02 Thread Reid Kleckner via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

Yeah, lgtm.


http://reviews.llvm.org/D14179



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


r251842 - Make hasLHS and hasRHS matchers available for ArraySubscriptExpr

2015-11-02 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Mon Nov  2 16:23:21 2015
New Revision: 251842

URL: http://llvm.org/viewvc/llvm-project?rev=251842&view=rev
Log:
Make hasLHS and hasRHS matchers available for ArraySubscriptExpr

Summary:
The hasBase and hasIndex don't tell anything about the position of the
base and the index in the code, so we need hasLHS and hasRHS in some cases.

Reviewers: klimek

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D14212

Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=251842&r1=251841&r2=251842&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Mon Nov  2 16:23:21 2015
@@ -3127,9 +3127,11 @@ AST_POLYMORPHIC_MATCHER_P(hasOperatorNam
 /// \code
 ///   a || b
 /// \endcode
-AST_MATCHER_P(BinaryOperator, hasLHS,
-  internal::Matcher, InnerMatcher) {
-  Expr *LeftHandSide = Node.getLHS();
+AST_POLYMORPHIC_MATCHER_P(hasLHS,
+  AST_POLYMORPHIC_SUPPORTED_TYPES(BinaryOperator,
+  ArraySubscriptExpr),
+  internal::Matcher, InnerMatcher) {
+  const Expr *LeftHandSide = Node.getLHS();
   return (LeftHandSide != nullptr &&
   InnerMatcher.matches(*LeftHandSide, Finder, Builder));
 }
@@ -3140,9 +3142,11 @@ AST_MATCHER_P(BinaryOperator, hasLHS,
 /// \code
 ///   a || b
 /// \endcode
-AST_MATCHER_P(BinaryOperator, hasRHS,
-  internal::Matcher, InnerMatcher) {
-  Expr *RightHandSide = Node.getRHS();
+AST_POLYMORPHIC_MATCHER_P(hasRHS,
+  AST_POLYMORPHIC_SUPPORTED_TYPES(BinaryOperator,
+  ArraySubscriptExpr),
+  internal::Matcher, InnerMatcher) {
+  const Expr *RightHandSide = Node.getRHS();
   return (RightHandSide != nullptr &&
   InnerMatcher.matches(*RightHandSide, Finder, Builder));
 }
@@ -3246,7 +3250,7 @@ AST_MATCHER(RecordDecl, isClass) {
 /// \endcode
 AST_MATCHER_P(ConditionalOperator, hasTrueExpression,
   internal::Matcher, InnerMatcher) {
-  Expr *Expression = Node.getTrueExpr();
+  const Expr *Expression = Node.getTrueExpr();
   return (Expression != nullptr &&
   InnerMatcher.matches(*Expression, Finder, Builder));
 }
@@ -3259,7 +3263,7 @@ AST_MATCHER_P(ConditionalOperator, hasTr
 /// \endcode
 AST_MATCHER_P(ConditionalOperator, hasFalseExpression,
   internal::Matcher, InnerMatcher) {
-  Expr *Expression = Node.getFalseExpr();
+  const Expr *Expression = Node.getFalseExpr();
   return (Expression != nullptr &&
   InnerMatcher.matches(*Expression, Finder, Builder));
 }
@@ -4270,7 +4274,7 @@ AST_MATCHER_P(NestedNameSpecifierLoc, sp
 AST_MATCHER_P_OVERLOAD(NestedNameSpecifier, hasPrefix,
internal::Matcher, InnerMatcher,
0) {
-  NestedNameSpecifier *NextNode = Node.getPrefix();
+  const NestedNameSpecifier *NextNode = Node.getPrefix();
   if (!NextNode)
 return false;
   return InnerMatcher.matches(*NextNode, Finder, Builder);

Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=251842&r1=251841&r2=251842&view=diff
==
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Mon Nov  2 16:23:21 2015
@@ -2372,6 +2372,11 @@ TEST(MatchBinaryOperator, HasLHSAndHasRH
   EXPECT_TRUE(matches("void x() { true || false; }", OperatorTrueFalse));
   EXPECT_TRUE(matches("void x() { true && false; }", OperatorTrueFalse));
   EXPECT_TRUE(notMatches("void x() { false || true; }", OperatorTrueFalse));
+
+  StatementMatcher OperatorIntPointer = arraySubscriptExpr(
+  hasLHS(hasType(isInteger())), hasRHS(hasType(pointsTo(qualType();
+  EXPECT_TRUE(matches("void x() { 1[\"abc\"]; }", OperatorIntPointer));
+  EXPECT_TRUE(notMatches("void x() { \"abc\"[1]; }", OperatorIntPointer));
 }
 
 TEST(MatchBinaryOperator, HasEitherOperand) {


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


r251843 - Remove empty directories.

2015-11-02 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Mon Nov  2 16:24:28 2015
New Revision: 251843

URL: http://llvm.org/viewvc/llvm-project?rev=251843&view=rev
Log:
Remove empty directories.


Removed:
cfe/trunk/test/Driver/Inputs/mips_mti_linux/

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


Re: [PATCH] D12031: Const std::move() argument ClangTidy check

2015-11-02 Thread Alexander Kornienko via cfe-commits
alexfh added a comment.

Vadym, what's the state of this patch?


http://reviews.llvm.org/D12031



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


Re: r251041 - Define weak and __weak to mean ARC-style weak references, even in MRC.

2015-11-02 Thread Nico Weber via cfe-commits
On Fri, Oct 30, 2015 at 5:55 PM, John McCall  wrote:

> > On Oct 30, 2015, at 5:39 PM, Nico Weber  wrote:
> > Hi John,
> >
> > this breaks programs that use __weak and target 10.6, like so:
> >
> > $ cat test.m
> > #import 
> > @interface I : NSObject {
> >   __weak NSObject* foo_;
> > }
> > - (NSObject*)foo;
> > @end
> >
> > @implementation I
> > - (NSObject *)foo {
> >   return foo_;
> > }
> > @end
> > $ clang -c test.m -mmacosx-version-min=10.6  # works with Xcode's clang
> > $ ~/src/llvm-build/bin/clang -c test.m -isysroot $(xcrun -show-sdk-path)
> -mmacosx-version-min=10.6
> > test.m:10:10: error: 'foo_' is unavailable: cannot use weak references
> because the current deployment target does not support them
> >   return foo_;
> >  ^
> > test.m:3:20: note: unsupported declaration here
> >   __weak NSObject* foo_;
> >^
> > test.m:3:20: error: cannot create __weak reference because the current
> deployment target does not support weak references
> >   __weak NSObject* foo_;
> >^
> > 2 errors generated.
> >
> >
> > We target 10.6 (and don't use ARC) and some library we use has __weak
> ivars. After this change, we can't build it any longer. This isn't a huge
> issue: we can change the library to use a WEAK macro that expands to
> nothing for us and __weak if ARC is enabled, but it sounded like you're
> interested in hearing about this.
>
> This is intended behavior.  We are changing __weak in non-ARC, non-GC TUs
> (i.e. MRC) to mean ARC-style __weak references.  Since, previously, __weak
> was accepted but silently ignored in MRC, there will be a period of time
> during which __weak will simply be rejected by the compiler in this mode.
> The compiler does try to be conservative about variables that are actually
> defined in other translation units, but in this case you are defining (and
> using) the ivar in the current TU, and you need to be aware that the
> semantics of that are changing.
>
> If the library is quite old, it may be using __weak in the GC sense, in
> which case you can probably just remove it.  If the library is new, and it
> really wants an ARC weak reference, then you may want your macro to expand
> to __unsafe_unretained, just in case there are files in that project that
> do use ARC.
>

Thanks. Is the plan to also add a __has_feature check added when __weak
becomes available in MRC mode (say, __has_feature(mrc_weak) or similar)?
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r251041 - Define weak and __weak to mean ARC-style weak references, even in MRC.

2015-11-02 Thread John McCall via cfe-commits
> On Nov 2, 2015, at 2:53 PM, Nico Weber  wrote:
> On Fri, Oct 30, 2015 at 5:55 PM, John McCall  > wrote:
> > On Oct 30, 2015, at 5:39 PM, Nico Weber  > > wrote:
> > Hi John,
> >
> > this breaks programs that use __weak and target 10.6, like so:
> >
> > $ cat test.m
> > #import 
> > @interface I : NSObject {
> >   __weak NSObject* foo_;
> > }
> > - (NSObject*)foo;
> > @end
> >
> > @implementation I
> > - (NSObject *)foo {
> >   return foo_;
> > }
> > @end
> > $ clang -c test.m -mmacosx-version-min=10.6  # works with Xcode's clang
> > $ ~/src/llvm-build/bin/clang -c test.m -isysroot $(xcrun -show-sdk-path) 
> > -mmacosx-version-min=10.6
> > test.m:10:10: error: 'foo_' is unavailable: cannot use weak references 
> > because the current deployment target does not support them
> >   return foo_;
> >  ^
> > test.m:3:20: note: unsupported declaration here
> >   __weak NSObject* foo_;
> >^
> > test.m:3:20: error: cannot create __weak reference because the current 
> > deployment target does not support weak references
> >   __weak NSObject* foo_;
> >^
> > 2 errors generated.
> >
> >
> > We target 10.6 (and don't use ARC) and some library we use has __weak 
> > ivars. After this change, we can't build it any longer. This isn't a huge 
> > issue: we can change the library to use a WEAK macro that expands to 
> > nothing for us and __weak if ARC is enabled, but it sounded like you're 
> > interested in hearing about this.
> 
> This is intended behavior.  We are changing __weak in non-ARC, non-GC TUs 
> (i.e. MRC) to mean ARC-style __weak references.  Since, previously, __weak 
> was accepted but silently ignored in MRC, there will be a period of time 
> during which __weak will simply be rejected by the compiler in this mode.  
> The compiler does try to be conservative about variables that are actually 
> defined in other translation units, but in this case you are defining (and 
> using) the ivar in the current TU, and you need to be aware that the 
> semantics of that are changing.
> 
> If the library is quite old, it may be using __weak in the GC sense, in which 
> case you can probably just remove it.  If the library is new, and it really 
> wants an ARC weak reference, then you may want your macro to expand to 
> __unsafe_unretained, just in case there are files in that project that do use 
> ARC.
> 
> Thanks. Is the plan to also add a __has_feature check added when __weak 
> becomes available in MRC mode (say, __has_feature(mrc_weak) or similar)?

Our plan was to spell this check:
  __has_feature(objc_arc_weak) && !__has_feature(objc_arc)

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


Re: r251041 - Define weak and __weak to mean ARC-style weak references, even in MRC.

2015-11-02 Thread Nico Weber via cfe-commits
On Mon, Nov 2, 2015 at 3:00 PM, John McCall  wrote:

> On Nov 2, 2015, at 2:53 PM, Nico Weber  wrote:
> On Fri, Oct 30, 2015 at 5:55 PM, John McCall  wrote:
>
>> > On Oct 30, 2015, at 5:39 PM, Nico Weber  wrote:
>> > Hi John,
>> >
>> > this breaks programs that use __weak and target 10.6, like so:
>> >
>> > $ cat test.m
>> > #import 
>> > @interface I : NSObject {
>> >   __weak NSObject* foo_;
>> > }
>> > - (NSObject*)foo;
>> > @end
>> >
>> > @implementation I
>> > - (NSObject *)foo {
>> >   return foo_;
>> > }
>> > @end
>> > $ clang -c test.m -mmacosx-version-min=10.6  # works with Xcode's clang
>> > $ ~/src/llvm-build/bin/clang -c test.m -isysroot $(xcrun
>> -show-sdk-path) -mmacosx-version-min=10.6
>> > test.m:10:10: error: 'foo_' is unavailable: cannot use weak references
>> because the current deployment target does not support them
>> >   return foo_;
>> >  ^
>> > test.m:3:20: note: unsupported declaration here
>> >   __weak NSObject* foo_;
>> >^
>> > test.m:3:20: error: cannot create __weak reference because the current
>> deployment target does not support weak references
>> >   __weak NSObject* foo_;
>> >^
>> > 2 errors generated.
>> >
>> >
>> > We target 10.6 (and don't use ARC) and some library we use has __weak
>> ivars. After this change, we can't build it any longer. This isn't a huge
>> issue: we can change the library to use a WEAK macro that expands to
>> nothing for us and __weak if ARC is enabled, but it sounded like you're
>> interested in hearing about this.
>>
>> This is intended behavior.  We are changing __weak in non-ARC, non-GC TUs
>> (i.e. MRC) to mean ARC-style __weak references.  Since, previously, __weak
>> was accepted but silently ignored in MRC, there will be a period of time
>> during which __weak will simply be rejected by the compiler in this mode.
>> The compiler does try to be conservative about variables that are actually
>> defined in other translation units, but in this case you are defining (and
>> using) the ivar in the current TU, and you need to be aware that the
>> semantics of that are changing.
>>
>> If the library is quite old, it may be using __weak in the GC sense, in
>> which case you can probably just remove it.  If the library is new, and it
>> really wants an ARC weak reference, then you may want your macro to expand
>> to __unsafe_unretained, just in case there are files in that project that
>> do use ARC.
>>
>
> Thanks. Is the plan to also add a __has_feature check added when __weak
> becomes available in MRC mode (say, __has_feature(mrc_weak) or similar)?
>
>
> Our plan was to spell this check:
>   __has_feature(objc_arc_weak) && !__has_feature(objc_arc)
>

Ah, that makes sense. Thanks!
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D11944: Nativize filename in FileManager::getFile().

2015-11-02 Thread Benjamin Kramer via cfe-commits
bkramer added a comment.

Can you try setting up the virtual files with the vfs::InMemoryFileSystem 
stuff? There are some examples how to set up with OverlayFileSystem in tree.

InMemoryFileSystem was written with windows path separators in mind, I just 
never tried to run it on windows :)


http://reviews.llvm.org/D11944



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


Re: [PATCH] D13925: Implement __attribute__((internal_linkage))

2015-11-02 Thread Aaron Ballman via cfe-commits
aaron.ballman added a subscriber: aaron.ballman.
aaron.ballman requested changes to this revision.
aaron.ballman added a reviewer: aaron.ballman.
aaron.ballman added a comment.
This revision now requires changes to proceed.

I would like to hold off on adding the namespace attribute. There were 
persuasive reasons to not have attributes on namespaces that was discussed in 
EWG in Kona, and this is a feature we could add on later if there's sufficient 
design consensus.



Comment at: include/clang/Basic/Attr.td:2125
@@ +2124,3 @@
+
+def InternalLinkage : InheritableAttr {
+  let Spellings = [GNU<"internal_linkage">, CXX11<"clang", 
"internal_linkage">];

rsmith wrote:
> `InheritableAttr` doesn't seem right for the case when this is applied to a 
> namespace.
Long and unusual is not a problem; that's why you can manually specify the 
diagnostic enum. This should be using Subjects unless it's realy onerous 
(or impossible).


Comment at: include/clang/Basic/AttrDocs.td:1619
@@ +1618,3 @@
+  let Content = [{
+The ``internal_linkage`` attribute changes the linkage type of the declaration 
to internal.
+  }];

Some examples would be nice, as well as an explanation as to why someone might 
want to do this.


Comment at: lib/Sema/SemaDeclAttr.cpp:3306
@@ +3305,3 @@
+
+  if (InternalLinkageAttr *Internal = D->getAttr()) {
+Diag(Range.getBegin(), diag::err_attributes_are_not_compatible)

Please use checkAttrMutualExclusion instead (and augment it with the 
note_conflicting_attribute).


Comment at: lib/Sema/SemaDeclAttr.cpp:3320
@@ +3319,3 @@
+
+  if (CommonAttr *Common = D->getAttr()) {
+Diag(Range.getBegin(), diag::err_attributes_are_not_compatible)

Please use checkAttrMutualExclusion instead.


Comment at: test/SemaCXX/internal_linkage.cpp:6
@@ +5,3 @@
+public:
+  int x __attribute__((internal_linkage)); // 
expected-warning{{'internal_linkage' attribute ignored}}
+  static int y __attribute__((internal_linkage));

This does not seem like a useful diagnostic as it doesn't tell the user *why* 
it was ignored.


Comment at: test/SemaCXX/internal_linkage.cpp:25
@@ +24,2 @@
+void A::f1() {
+}

Missing tests for internal_linkage accepting an argument (which should 
diagnose).
Missing tests for what happens with forward declarations and redeclarations 
that do not have matching attribute specifiers.
Missing tests for using the C++ spelling of the attribute.


Repository:
  rL LLVM

http://reviews.llvm.org/D13925



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


Re: [PATCH] D14096: [clang-tidy] add new check cppcoreguidelines-pro-type-cstyle-cast

2015-11-02 Thread Aaron Ballman via cfe-commits
On Mon, Nov 2, 2015 at 4:43 AM, Joerg Sonnenberger via cfe-commits
 wrote:
> On Sun, Nov 01, 2015 at 08:48:53PM -0500, Aaron Ballman via cfe-commits wrote:
>> On Sun, Nov 1, 2015 at 2:31 PM, Joerg Sonnenberger via cfe-commits
>>  wrote:
>> > On Tue, Oct 27, 2015 at 06:10:26PM +, Samuel Benzaquen via cfe-commits 
>> > wrote:
>> >> sbenza added a comment.
>> >>
>> >> In http://reviews.llvm.org/D14096#275902, @xazax.hun wrote:
>> >>
>> >> > There is already a similar check in the Google package. What are the 
>> >> > differences between those two checks? What is the reason we can not 
>> >> > just register that check into the core guidelines module?
>> >>
>> >>
>> >> That other check discourages c-style cast in favor of C++ style casts, 
>> >> even if it is a reinterpret_cast. It simply replaces the cstyle cast with 
>> >> an equivalent C++ one. It is basically a stylistic check.
>> >>
>> >> This check will warn unsafe cstyle casts, while allowing safe ones like 
>> >> int->uint casts.
>> >> This one is a safety related check.
>> >
>> > Looking back to the discussion about the C++ style casts, this argument
>> > makes no sense. For C++ code, reinterpret_cast is clearly preferable
>> > over C-style casts for all but code size reasons. There seems to be no
>> > consideration about "safe" uses with reinterpret_cast, so why should 
>> > C-style casts
>> > be different?
>>
>> "Clearly preferable" is kind of debatable, but I don't disagree with
>> your statement. That being said, this checker isn't concerned with
>> C++-style casts, so I'm not certain I understand what you would like
>> to see changed with this checker. Can you elaborate?
>
> Let me reverse that. Do the core guidelines really define a set of
> "safe" C-style casts and don't have the equivalent for C++ casts? The
> latter is what I took from the follow-up on the introduction of the C++
> cast checkers.

Okay, that makes more sense to me -- thank you for the clarification.

My understanding is that the core guidelines define a set of "safe"
C-style casts and don't have the equivalent for C++ casts. That seems
like a good bug report to file with the core guidelines folks
(https://github.com/isocpp/CppCoreGuidelines/issues). I agree that it
seems strange that a C-style cast resulting in reinterpret_cast is
safe and not diagnosed, while the same effective cast spelled with
reinterpret_cast is diagnosed.

~Aaron

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


Re: [PATCH] D12922: Add support for function attribute "notail"

2015-11-02 Thread Aaron Ballman via cfe-commits
aaron.ballman added inline comments.


Comment at: test/Sema/attr-notail.c:9
@@ +8,3 @@
+}
+
+int g0 __attribute__((not_tail_called)); // expected-warning 
{{'not_tail_called' attribute only applies to functions}}

ahatanak wrote:
> I didn't understand what kind of test case is required for not_tail_called on 
> passed arguments. Could you give me an example? 
Sorry, I may have been unclear. I meant the attribute being passed arguments 
itself. e.g.,
```
int f() __attribute__((not_tail_called("this should diagnose")));
```


http://reviews.llvm.org/D12922



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


[PATCH] D14266: CodeGen: Update for debug info API change.Depends on D14265.

2015-11-02 Thread Peter Collingbourne via cfe-commits
pcc created this revision.
pcc added a reviewer: dexonsmith.
pcc added a subscriber: cfe-commits.

http://reviews.llvm.org/D14266

Files:
  lib/CodeGen/CGDebugInfo.cpp
  test/CodeGen/debug-info-block-decl.c
  test/CodeGenCXX/debug-info-static-fns.cpp
  test/CodeGenCXX/debug-info-windows-dtor.cpp
  test/CodeGenCXX/globalinit-loc.cpp
  test/CodeGenCXX/linetable-virtual-variadic.cpp
  test/CodeGenObjCXX/property-objects.mm

Index: test/CodeGenObjCXX/property-objects.mm
===
--- test/CodeGenObjCXX/property-objects.mm
+++ test/CodeGenObjCXX/property-objects.mm
@@ -37,7 +37,7 @@
 
 // Don't attach debug locations to the prologue instructions. These were
 // leaking over from the previous function emission by accident.
-// CHECK: define internal void @"\01-[I setBounds:]"
+// CHECK: define internal void @"\01-[I setBounds:]"({{.*}} {
 // CHECK-NOT: !dbg
 // CHECK: call void @llvm.dbg.declare
 - (void)setFrame:(CGRect)frameRect {}
Index: test/CodeGenCXX/linetable-virtual-variadic.cpp
===
--- test/CodeGenCXX/linetable-virtual-variadic.cpp
+++ test/CodeGenCXX/linetable-virtual-variadic.cpp
@@ -10,14 +10,14 @@
 
 void Derived::VariadicFunction(...) { }
 
-// CHECK-LABEL: define void @_ZN7Derived16VariadicFunctionEz(
+// CHECK: define void @_ZN7Derived16VariadicFunctionEz({{.*}} !dbg ![[SP:[0-9]+]]
 // CHECK: ret void, !dbg ![[LOC:[0-9]+]]
 // CHECK-LABEL: define void @_ZT{{.+}}N7Derived16VariadicFunctionEz(
 // CHECK: ret void, !dbg ![[LOC:[0-9]+]]
 //
 // CHECK: !llvm.dbg.cu = !{![[CU:[0-9]+]]}
 //
 // CHECK: ![[CU]] = distinct !DICompileUnit({{.*}} subprograms: ![[SPs:[0-9]+]]
-// CHECK: ![[SPs]] = !{![[SP:[0-9]+]]}
-// CHECK: ![[SP]] = distinct !DISubprogram(name: "VariadicFunction",{{.*}} function: {{[^:]+}} @_ZN7Derived16VariadicFunctionEz
+// CHECK: ![[SPs]] = !{![[SP]]}
+// CHECK: ![[SP]] = distinct !DISubprogram(name: "VariadicFunction"
 // CHECK: ![[LOC]] = !DILocation({{.*}}scope: ![[SP]])
Index: test/CodeGenCXX/globalinit-loc.cpp
===
--- test/CodeGenCXX/globalinit-loc.cpp
+++ test/CodeGenCXX/globalinit-loc.cpp
@@ -4,7 +4,7 @@
 // Verify that the global init helper function does not get associated
 // with any source location.
 //
-// CHECK: define internal {{.*}}void @_GLOBAL__sub_I_globalinit_loc.cpp
+// CHECK: define internal {{.*}}void @_GLOBAL__sub_I_globalinit_loc.cpp({{.*}} {
 // CHECK: !dbg ![[DBG:.*]]
 // CHECK: !DISubprogram(linkageName: "_GLOBAL__sub_I_globalinit_loc.cpp"
 // CHECK-NOT:   line:
Index: test/CodeGenCXX/debug-info-windows-dtor.cpp
===
--- test/CodeGenCXX/debug-info-windows-dtor.cpp
+++ test/CodeGenCXX/debug-info-windows-dtor.cpp
@@ -14,9 +14,9 @@
 
 template struct AB;
 
-// CHECK-LABEL: define {{.*}}@"\01??_E?$AB@H@@W3AEPAXI@Z"
+// CHECK: define {{.*}}@"\01??_E?$AB@H@@W3AEPAXI@Z"({{.*}} !dbg [[THUNK_VEC_DEL_DTOR:![0-9]*]]
 // CHECK: call {{.*}}@"\01??_G?$AB@H@@UAEPAXI@Z"({{.*}}) #{{[0-9]*}}, !dbg [[THUNK_LOC:![0-9]*]]
-// CHECK-LABEL: define
+// CHECK: define
 
-// CHECK: [[THUNK_VEC_DEL_DTOR:![0-9]*]] = distinct !DISubprogram({{.*}}function: {{.*}}@"\01??_E?$AB@H@@W3AEPAXI@Z"
+// CHECK: [[THUNK_VEC_DEL_DTOR]] = distinct !DISubprogram
 // CHECK: [[THUNK_LOC]] = !DILocation(line: 15, scope: [[THUNK_VEC_DEL_DTOR]])
Index: test/CodeGenCXX/debug-info-static-fns.cpp
===
--- test/CodeGenCXX/debug-info-static-fns.cpp
+++ test/CodeGenCXX/debug-info-static-fns.cpp
@@ -7,7 +7,7 @@
 }
 
 // Verify that a is present and mangled.
-// CHECK: !DISubprogram(name: "a", linkageName: "_ZN1AL1aEi",
+// CHECK: define internal i32 @_ZN1AL1aEi({{.*}} !dbg [[DBG:![0-9]+]]
+// CHECK: [[DBG]] = distinct !DISubprogram(name: "a", linkageName: "_ZN1AL1aEi",
 // CHECK-SAME:  line: 4
 // CHECK-SAME:  isDefinition: true
-// CHECK-SAME:  function: i32 (i32)* @_ZN1AL1aEi
Index: test/CodeGen/debug-info-block-decl.c
===
--- test/CodeGen/debug-info-block-decl.c
+++ test/CodeGen/debug-info-block-decl.c
@@ -5,7 +5,7 @@
 // CHECK: define{{.*}}@main()
 // CHECK: store{{.*}}bitcast{{.*}}, !dbg ![[ASSIGNMENT:[0-9]+]]
 // CHECK: define {{.*}} @__main_block_invoke
-// CHECK: dbg ![[BLOCK_ENTRY:[0-9]+]]
+// CHECK: , !dbg ![[BLOCK_ENTRY:[0-9]+]]
 
 int main()
 {
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -1176,7 +1176,7 @@
   RecordTy, MethodName, MethodLinkageName, MethodDefUnit, MethodLine,
   MethodTy, /*isLocalToUnit=*/false,
   /* isDefinition=*/false, Virtuality, VIndex, ContainingType, Flags,
-  CGM.getLangOpts().Optimize, nullptr, TParamsArray.get());
+  CGM.getLangOpt

Re: [PATCH] D14180: enable -fms-extensions by default on the mingw-w64 target

2015-11-02 Thread Reid Kleckner via cfe-commits
rnk added a comment.

Will Clang be able to compile the last few stable mingw-w64 releases with this 
change? I'd like that to keep working.


http://reviews.llvm.org/D14180



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


Re: [PATCH] D12922: Add support for function attribute "notail"

2015-11-02 Thread Akira Hatanaka via cfe-commits
ahatanak updated this revision to Diff 39003.
ahatanak added a comment.

Added test case that produces an error diagnostic if an argument is passed for 
not_tail_called.


http://reviews.llvm.org/D12922

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/CGCall.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/attr-no-tail.c
  test/CodeGenCXX/attr-notail.cpp
  test/Sema/attr-notail.c
  test/SemaCXX/attr-notail.cpp

Index: test/SemaCXX/attr-notail.cpp
===
--- /dev/null
+++ test/SemaCXX/attr-notail.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+class Base {
+public:
+  [[clang::not_tail_called]] virtual int foo1(); // expected-error {{'not_tail_called' attribute cannot be applied to virtual functions}}
+  virtual int foo2();
+  [[clang::not_tail_called]] int foo3();
+  virtual ~Base() {}
+};
+
+class Derived1 : public Base {
+public:
+  int foo1() override;
+  [[clang::not_tail_called]] int foo2() override; // expected-error {{'not_tail_called' attribute cannot be applied to virtual functions}}
+  [[clang::not_tail_called]] int foo4();
+};
Index: test/Sema/attr-notail.c
===
--- /dev/null
+++ test/Sema/attr-notail.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int callee0() __attribute__((not_tail_called,always_inline)); // expected-error{{'not_tail_called' and 'always_inline' attributes are not compatible}}
+int callee1() __attribute__((always_inline,not_tail_called)); // expected-error{{'always_inline' and 'not_tail_called' attributes are not compatible}}
+
+int foo(int a) {
+  return a ? callee0() : callee1();
+}
+
+int g0 __attribute__((not_tail_called)); // expected-warning {{'not_tail_called' attribute only applies to functions}}
+
+int foo2(int a) __attribute__((not_tail_called("abc"))); // expected-error {{'not_tail_called' attribute takes no arguments}}
Index: test/CodeGenCXX/attr-notail.cpp
===
--- /dev/null
+++ test/CodeGenCXX/attr-notail.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple=x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s | FileCheck %s
+
+class Class1 {
+public:
+  [[clang::not_tail_called]] int m1();
+  int m2();
+};
+
+int foo1(int a, Class1 *c1) {
+  if (a)
+return c1->m1();
+  return c1->m2();
+}
+
+// CHECK-LABEL: define i32 @_Z4foo1iP6Class1(
+// CHECK: %{{[a-z0-9]+}} = notail call i32 @_ZN6Class12m1Ev(%class.Class1*
+// CHECK: %{{[a-z0-9]+}} = call i32 @_ZN6Class12m2Ev(%class.Class1*
Index: test/CodeGen/attr-no-tail.c
===
--- /dev/null
+++ test/CodeGen/attr-no-tail.c
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.7.0 %s -emit-llvm -o - | FileCheck %s
+
+// CHECK: %{{[a-z0-9]+}} = notail call i32 @callee0(i32 %
+// CHECK: %{{[a-z0-9]+}} = notail call i32 @callee1(i32 %
+
+// Check that indirect calls do not have the notail marker.
+// CHECK: store i32 (i32)* @callee1, i32 (i32)** [[ALLOCA1:%[A-Za-z0-9]+]], align 8
+// CHECK: [[INDIRFUNC:%[0-9]+]] = load i32 (i32)*, i32 (i32)** [[ALLOCA1]], align 8
+// CHECK: %{{[a-z0-9]+}} = call i32 [[INDIRFUNC]](i32 %6)
+
+// CHECK: %{{[a-z0-9]+}} = call i32 @callee2(i32 %
+
+int callee0(int a) __attribute__((not_tail_called)) {
+  return a + 1;
+}
+
+int callee1(int) __attribute__((not_tail_called));
+
+int callee2(int);
+
+typedef int (*FuncTy)(int);
+
+int foo0(int a) {
+  if (a > 1)
+return callee0(a);
+  if (a == 1)
+return callee1(a);
+  if (a < 0) {
+FuncTy F = callee1;
+return (*F)(a);
+  }
+  return callee2(a);
+}
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -1701,6 +1701,15 @@
Attr.getAttributeSpellingListIndex()));
 }
 
+static void handleNotTailCalledAttr(Sema &S, Decl *D,
+const AttributeList &Attr) {
+  if (checkAttrMutualExclusion(S, D, Attr))
+return;
+
+  D->addAttr(::new (S.Context) NotTailCalledAttr(
+  Attr.getRange(), S.Context, Attr.getAttributeSpellingListIndex()));
+}
+
 static void handleUsedAttr(Sema &S, Decl *D, const AttributeList &Attr) {
   if (const VarDecl *VD = dyn_cast(D)) {
 if (VD->hasLocalStorage()) {
@@ -3419,6 +3428,9 @@
 
 static void handleAlwaysInlineAttr(Sema &S, Decl *D,
const AttributeList &Attr) {
+  if (checkAttrMutualExclusion(S, D, Attr))
+return;
+
   if (AlwaysInlineAttr *Inline = S.mergeAlwaysInlineAttr(
   D, Attr.getRange(), Attr.getName(),
   Attr.getAttributeSpellingListIndex()))
@@ -4991,6 +5003,9 @@
   case AttributeList::AT_ReturnsTwice:
 handleSimpleAttribute(S, D, Attr);
 break;
+

Re: [PATCH] D12922: Add support for function attribute "notail"

2015-11-02 Thread Aaron Ballman via cfe-commits
aaron.ballman added inline comments.


Comment at: lib/Sema/SemaDecl.cpp:5374
@@ +5373,3 @@
+
+  // Virtual functions cannot be marked as 'notail'.
+  if (auto *Attr = ND.getAttr())

I am not home yet, and so I don't have the source code to try this out, but I 
have a sneaking suspicion there's a way to tell whether a function is an 
override. IIRC, it's something like overridden_methods() on a CXXMethodDecl.

I will do some poking when I am back in front of the source. Otherwise, I would 
guess you can look at some of the diagnostics in DiagnosticSemaKinds.td for the 
override keyword itself, because I bet we warn when you specify override on 
something that isn't a virtual function override, and that should have a code 
example.


http://reviews.llvm.org/D12922



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


r251874 - Stop back-patching 'readonly' Objective-C properties with 'readwrite' ones.

2015-11-02 Thread Douglas Gregor via cfe-commits
Author: dgregor
Date: Mon Nov  2 19:15:46 2015
New Revision: 251874

URL: http://llvm.org/viewvc/llvm-project?rev=251874&view=rev
Log:
Stop back-patching 'readonly' Objective-C properties with 'readwrite' ones.

A 'readonly' Objective-C property declared in the primary class can
effectively be shadowed by a 'readwrite' property declared within an
extension of that class, so long as the types and attributes of the
two property declarations are compatible.

Previously, this functionality was implemented by back-patching the
original 'readonly' property to make it 'readwrite', destroying source
information and causing some hideously redundant, incorrect
code. Simplify the implementation to express how this should actually
be modeled: as a separate property declaration in the extension that
shadows (via the name lookup rules) the declaration in the primary
class. While here, correct some broken Fix-Its, eliminate a pile of
redundant code, clean up the ARC migrator's handling of properties
declared in extensions, and fix debug info's naming of methods that
come from categories.

A wonderous side effect of doing this write is that it eliminates the
"AddedObjCPropertyInClassExtension" method from the AST mutation
listener, which in turn eliminates the last place where we rewrite
entire declarations in a chained PCH file or a module file. This
change (which fixes rdar://problem/18475765) will allow us to
eliminate the rewritten-decls logic from the serialization library,
and fixes a crash (rdar://problem/23247794) illustrated by the
test/PCH/chain-categories.m example.


Modified:
cfe/trunk/include/clang/AST/ASTMutationListener.h
cfe/trunk/include/clang/AST/DeclObjC.h
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Serialization/ASTWriter.h
cfe/trunk/lib/ARCMigrate/TransProperties.cpp
cfe/trunk/lib/AST/DeclObjC.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/Frontend/MultiplexConsumer.cpp
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/lib/Sema/SemaObjCProperty.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/test/FixIt/atomic-property.m
cfe/trunk/test/Index/complete-kvc.m
cfe/trunk/test/Modules/ModuleDebugInfo.m
cfe/trunk/test/PCH/chain-categories.m
cfe/trunk/test/SemaObjC/atomoic-property-synnthesis-rules.m
cfe/trunk/test/SemaObjC/property-3.m
cfe/trunk/test/SemaObjC/property-in-class-extension-1.m
cfe/trunk/test/SemaObjCXX/property-invalid-type.mm

Modified: cfe/trunk/include/clang/AST/ASTMutationListener.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTMutationListener.h?rev=251874&r1=251873&r2=251874&view=diff
==
--- cfe/trunk/include/clang/AST/ASTMutationListener.h (original)
+++ cfe/trunk/include/clang/AST/ASTMutationListener.h Mon Nov  2 19:15:46 2015
@@ -92,18 +92,6 @@ public:
   virtual void AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD,
 const ObjCInterfaceDecl *IFD) {}
 
-  /// \brief A objc class extension redeclared or introduced a property.
-  ///
-  /// \param Prop the property in the class extension
-  ///
-  /// \param OrigProp the property from the original interface that was 
declared
-  /// or null if the property was introduced.
-  ///
-  /// \param ClassExt the class extension.
-  virtual void AddedObjCPropertyInClassExtension(const ObjCPropertyDecl *Prop,
-const ObjCPropertyDecl *OrigProp,
-const ObjCCategoryDecl *ClassExt) 
{}
-
   /// \brief A declaration is marked used which was not previously marked used.
   ///
   /// \param D the declaration marked used

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=251874&r1=251873&r2=251874&view=diff
==
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Mon Nov  2 19:15:46 2015
@@ -2524,11 +2524,6 @@ public:
 PropertyAttributesAsWritten = PRVal;
   }
 
- void makeitReadWriteAttribute() {
-PropertyAttributes &= ~OBJC_PR_readonly;
-PropertyAttributes |= OBJC_PR_readwrite;
- }
-
   // Helper methods for accessing attributes.
 
   /// isReadOnly - Return true iff the property has a setter.

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=251874&r1=251873&r2=251874&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Nov  2 19:

Re: r251874 - Stop back-patching 'readonly' Objective-C properties with 'readwrite' ones.

2015-11-02 Thread Douglas Gregor via cfe-commits
… and I forgot the most important part, which is that this is based on the good 
work of Mr. Kyrtzidis that I failed to acknowledge in the commit message.

- Doug


> On Nov 2, 2015, at 5:15 PM, Douglas Gregor via cfe-commits 
>  wrote:
> 
> Author: dgregor
> Date: Mon Nov  2 19:15:46 2015
> New Revision: 251874
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=251874&view=rev
> Log:
> Stop back-patching 'readonly' Objective-C properties with 'readwrite' ones.
> 
> A 'readonly' Objective-C property declared in the primary class can
> effectively be shadowed by a 'readwrite' property declared within an
> extension of that class, so long as the types and attributes of the
> two property declarations are compatible.
> 
> Previously, this functionality was implemented by back-patching the
> original 'readonly' property to make it 'readwrite', destroying source
> information and causing some hideously redundant, incorrect
> code. Simplify the implementation to express how this should actually
> be modeled: as a separate property declaration in the extension that
> shadows (via the name lookup rules) the declaration in the primary
> class. While here, correct some broken Fix-Its, eliminate a pile of
> redundant code, clean up the ARC migrator's handling of properties
> declared in extensions, and fix debug info's naming of methods that
> come from categories.
> 
> A wonderous side effect of doing this write is that it eliminates the
> "AddedObjCPropertyInClassExtension" method from the AST mutation
> listener, which in turn eliminates the last place where we rewrite
> entire declarations in a chained PCH file or a module file. This
> change (which fixes rdar://problem/18475765) will allow us to
> eliminate the rewritten-decls logic from the serialization library,
> and fixes a crash (rdar://problem/23247794) illustrated by the
> test/PCH/chain-categories.m example.
> 
> 
> Modified:
>cfe/trunk/include/clang/AST/ASTMutationListener.h
>cfe/trunk/include/clang/AST/DeclObjC.h
>cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>cfe/trunk/include/clang/Sema/Sema.h
>cfe/trunk/include/clang/Serialization/ASTWriter.h
>cfe/trunk/lib/ARCMigrate/TransProperties.cpp
>cfe/trunk/lib/AST/DeclObjC.cpp
>cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>cfe/trunk/lib/Frontend/MultiplexConsumer.cpp
>cfe/trunk/lib/Sema/SemaDeclObjC.cpp
>cfe/trunk/lib/Sema/SemaExprObjC.cpp
>cfe/trunk/lib/Sema/SemaObjCProperty.cpp
>cfe/trunk/lib/Serialization/ASTWriter.cpp
>cfe/trunk/test/FixIt/atomic-property.m
>cfe/trunk/test/Index/complete-kvc.m
>cfe/trunk/test/Modules/ModuleDebugInfo.m
>cfe/trunk/test/PCH/chain-categories.m
>cfe/trunk/test/SemaObjC/atomoic-property-synnthesis-rules.m
>cfe/trunk/test/SemaObjC/property-3.m
>cfe/trunk/test/SemaObjC/property-in-class-extension-1.m
>cfe/trunk/test/SemaObjCXX/property-invalid-type.mm
> 
> Modified: cfe/trunk/include/clang/AST/ASTMutationListener.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTMutationListener.h?rev=251874&r1=251873&r2=251874&view=diff
> ==
> --- cfe/trunk/include/clang/AST/ASTMutationListener.h (original)
> +++ cfe/trunk/include/clang/AST/ASTMutationListener.h Mon Nov  2 19:15:46 2015
> @@ -92,18 +92,6 @@ public:
>   virtual void AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD,
> const ObjCInterfaceDecl *IFD) {}
> 
> -  /// \brief A objc class extension redeclared or introduced a property.
> -  ///
> -  /// \param Prop the property in the class extension
> -  ///
> -  /// \param OrigProp the property from the original interface that was 
> declared
> -  /// or null if the property was introduced.
> -  ///
> -  /// \param ClassExt the class extension.
> -  virtual void AddedObjCPropertyInClassExtension(const ObjCPropertyDecl 
> *Prop,
> -const ObjCPropertyDecl *OrigProp,
> -const ObjCCategoryDecl 
> *ClassExt) {}
> -
>   /// \brief A declaration is marked used which was not previously marked 
> used.
>   ///
>   /// \param D the declaration marked used
> 
> Modified: cfe/trunk/include/clang/AST/DeclObjC.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=251874&r1=251873&r2=251874&view=diff
> ==
> --- cfe/trunk/include/clang/AST/DeclObjC.h (original)
> +++ cfe/trunk/include/clang/AST/DeclObjC.h Mon Nov  2 19:15:46 2015
> @@ -2524,11 +2524,6 @@ public:
> PropertyAttributesAsWritten = PRVal;
>   }
> 
> - void makeitReadWriteAttribute() {
> -PropertyAttributes &= ~OBJC_PR_readonly;
> -PropertyAttributes |= OBJC_PR_readwrite;
> - }
> -
>   // Helper methods for accessing attributes.
> 
>   /// isReadOnly - Return true iff the property has a

r251875 - Switch to using an explicit scope object to ensure we don't forget to pop ObjC

2015-11-02 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon Nov  2 19:19:56 2015
New Revision: 251875

URL: http://llvm.org/viewvc/llvm-project?rev=251875&view=rev
Log:
Switch to using an explicit scope object to ensure we don't forget to pop ObjC
type parameters off the scope, and fix the cases where we failed to do so.

Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/test/SemaObjC/parameterized_classes.m

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=251875&r1=251874&r2=251875&view=diff
==
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Mon Nov  2 19:19:56 2015
@@ -1253,12 +1253,12 @@ private:
   DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
   Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
 ParsedAttributes &prefixAttrs);
+  class ObjCTypeParamListScope;
   ObjCTypeParamList *parseObjCTypeParamList();
   ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
-   SourceLocation &lAngleLoc,
-   SmallVectorImpl &protocolIdents,
-   SourceLocation &rAngleLoc,
-   bool mayBeProtocolList = true);
+  ObjCTypeParamListScope &Scope, SourceLocation &lAngleLoc,
+  SmallVectorImpl &protocolIdents,
+  SourceLocation &rAngleLoc, bool mayBeProtocolList = true);
 
   void HelperActionsForIvarDeclarations(Decl *interfaceDecl, SourceLocation 
atLoc,
 BalancedDelimiterTracker &T,

Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=251875&r1=251874&r2=251875&view=diff
==
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Mon Nov  2 19:19:56 2015
@@ -94,6 +94,28 @@ Parser::DeclGroupPtrTy Parser::ParseObjC
   return Actions.ConvertDeclToDeclGroup(SingleDecl);
 }
 
+/// Class to handle popping type parameters when leaving the scope.
+class Parser::ObjCTypeParamListScope {
+  Sema &Actions;
+  Scope *S;
+  ObjCTypeParamList *Params;
+public:
+  ObjCTypeParamListScope(Sema &Actions, Scope *S)
+  : Actions(Actions), S(S), Params(nullptr) {}
+  ~ObjCTypeParamListScope() {
+leave();
+  }
+  void enter(ObjCTypeParamList *P) {
+assert(!Params);
+Params = P;
+  }
+  void leave() {
+if (Params)
+  Actions.popObjCTypeParamList(S, Params);
+Params = nullptr;
+  }
+};
+
 ///
 /// objc-class-declaration:
 ///'@' 'class' objc-class-forward-decl (',' objc-class-forward-decl)* ';'
@@ -121,11 +143,8 @@ Parser::ParseObjCAtClassDeclaration(Sour
 
 // Parse the optional objc-type-parameter-list.
 ObjCTypeParamList *TypeParams = nullptr;
-if (Tok.is(tok::less)) {
+if (Tok.is(tok::less))
   TypeParams = parseObjCTypeParamList();
-  if (TypeParams)
-Actions.popObjCTypeParamList(getCurScope(), TypeParams);
-}
 ClassTypeParams.push_back(TypeParams);
 if (!TryConsumeToken(tok::comma))
   break;
@@ -221,11 +240,10 @@ Decl *Parser::ParseObjCAtInterfaceDeclar
   SourceLocation LAngleLoc, EndProtoLoc;
   SmallVector ProtocolIdents;
   ObjCTypeParamList *typeParameterList = nullptr;
-  if (Tok.is(tok::less)) {
-typeParameterList = parseObjCTypeParamListOrProtocolRefs(LAngleLoc, 
- ProtocolIdents,
- EndProtoLoc);
-  }
+  ObjCTypeParamListScope typeParamScope(Actions, getCurScope());
+  if (Tok.is(tok::less))
+typeParameterList = parseObjCTypeParamListOrProtocolRefs(
+typeParamScope, LAngleLoc, ProtocolIdents, EndProtoLoc);
 
   if (Tok.is(tok::l_paren) &&
   !isKnownToBeTypeSpecifier(GetLookAheadToken(1))) { // we have a category.
@@ -286,9 +304,6 @@ Decl *Parser::ParseObjCAtInterfaceDeclar
   
 ParseObjCInterfaceDeclList(tok::objc_not_keyword, CategoryType);
 
-if (typeParameterList)
-  Actions.popObjCTypeParamList(getCurScope(), typeParameterList);
-
 return CategoryType;
   }
   // Parse a class interface.
@@ -370,9 +385,6 @@ Decl *Parser::ParseObjCAtInterfaceDeclar
 
   ParseObjCInterfaceDeclList(tok::objc_interface, ClsType);
 
-  if (typeParameterList)
-Actions.popObjCTypeParamList(getCurScope(), typeParameterList);
-
   return ClsType;
 }
 
@@ -432,10 +444,9 @@ static void addContextSensitiveTypeNulla
 ///
 /// \param rAngleLoc The location of the ending '>'.
 ObjCTypeParamList *Parser::parseObjCTypeParamListOrProtocolRefs(
- SourceLocation &lAngleLoc,
- SmallVectorImpl &protocolIdents,
- SourceLocation &rAngl

r251877 - Eliminate "rewritten decls" from the AST writer. NFC

2015-11-02 Thread Douglas Gregor via cfe-commits
Author: dgregor
Date: Mon Nov  2 19:20:54 2015
New Revision: 251877

URL: http://llvm.org/viewvc/llvm-project?rev=251877&view=rev
Log:
Eliminate "rewritten decls" from the AST writer. NFC


Modified:
cfe/trunk/include/clang/Serialization/ASTWriter.h
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp

Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=251877&r1=251876&r2=251877&view=diff
==
--- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTWriter.h Mon Nov  2 19:20:54 2015
@@ -376,10 +376,6 @@ private:
   /// coming from another AST file.
   SmallVector UpdatingVisibleDecls;
 
-  typedef llvm::SmallSetVector DeclsToRewriteTy;
-  /// \brief Decls that will be replaced in the current dependent AST file.
-  DeclsToRewriteTy DeclsToRewrite;
-
   /// \brief The set of Objective-C class that have categories we
   /// should serialize.
   llvm::SetVector ObjCClassesWithCategories;
@@ -764,14 +760,6 @@ public:
   /// \brief Add a version tuple to the given record
   void AddVersionTuple(const VersionTuple &Version, RecordDataImpl &Record);
 
-  void RewriteDecl(const Decl *D) {
-DeclsToRewrite.insert(D);
-  }
-
-  bool isRewritten(const Decl *D) const {
-return DeclsToRewrite.count(D);
-  }
-
   /// \brief Infer the submodule ID that contains an entity at the given
   /// source location.
   serialization::SubmoduleID inferSubmoduleIDFromLocation(SourceLocation Loc);

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=251877&r1=251876&r2=251877&view=diff
==
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Mon Nov  2 19:20:54 2015
@@ -3513,11 +3513,11 @@ ASTWriter::GenerateNameLookupTable(const
 auto &Name = Lookup.first;
 auto &Result = Lookup.second;
 
-// If there are no local declarations in our lookup result, we don't
-// need to write an entry for the name at all unless we're rewriting
-// the decl context. If we can't write out a lookup set without
-// performing more deserialization, just skip this entry.
-if (isLookupResultExternal(Result, DC) && !isRewritten(cast(DC)) &&
+// If there are no local declarations in our lookup result, we
+// don't need to write an entry for the name at all. If we can't
+// write out a lookup set without performing more deserialization,
+// just skip this entry.
+if (isLookupResultExternal(Result, DC) &&
 isLookupResultEntirelyExternal(Result, DC))
   continue;
 
@@ -3758,9 +3758,6 @@ uint64_t ASTWriter::WriteDeclContextVisi
 /// (in C++), for namespaces, and for classes with forward-declared unscoped
 /// enumeration members (in C++11).
 void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) {
-  if (isRewritten(cast(DC)))
-return;
-
   StoredDeclsMap *Map = DC->getLookupPtr();
   if (!Map || Map->empty())
 return;
@@ -4376,10 +4373,6 @@ uint64_t ASTWriter::WriteASTCore(Sema &S
   Stream.EnterSubblock(DECLTYPES_BLOCK_ID, /*bits for abbreviations*/5);
   WriteTypeAbbrevs();
   WriteDeclAbbrevs();
-  for (DeclsToRewriteTy::iterator I = DeclsToRewrite.begin(),
-  E = DeclsToRewrite.end();
-   I != E; ++I)
-DeclTypesToEmit.push(const_cast(*I));
   do {
 WriteDeclUpdatesBlocks(DeclUpdatesOffsetsRecord);
 while (!DeclTypesToEmit.empty()) {
@@ -4545,8 +4538,6 @@ void ASTWriter::WriteDeclUpdatesBlocks(R
 
   for (auto &DeclUpdate : LocalUpdates) {
 const Decl *D = DeclUpdate.first;
-if (isRewritten(D))
-  continue; // The decl will be written completely,no need to store 
updates.
 
 bool HasUpdatedBody = false;
 RecordData Record;

Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=251877&r1=251876&r2=251877&view=diff
==
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Mon Nov  2 19:20:54 2015
@@ -2093,16 +2093,12 @@ void ASTWriter::WriteDecl(ASTContext &Co
 
   // Determine the ID for this declaration.
   serialization::DeclID ID;
-  if (D->isFromASTFile()) {
-assert(isRewritten(D) && "should not be emitting imported decl");
-ID = getDeclID(D);
-  } else {
-serialization::DeclID &IDR = DeclIDs[D];
-if (IDR == 0)
-  IDR = NextDeclID++;
+  assert(!D->isFromASTFile() && "should not be emitting imported decl");
+  serialization::DeclID &IDR = DeclIDs[D];
+  if (IDR == 0)
+IDR = N

Re: r251874 - Stop back-patching 'readonly' Objective-C properties with 'readwrite' ones.

2015-11-02 Thread Richard Smith via cfe-commits
This is awesome, thank you both!

On Mon, Nov 2, 2015 at 5:22 PM, Douglas Gregor via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> … and I forgot the most important part, which is that this is based on the
> good work of Mr. Kyrtzidis that I failed to acknowledge in the commit
> message.
>
> - Doug
>
>
> > On Nov 2, 2015, at 5:15 PM, Douglas Gregor via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> >
> > Author: dgregor
> > Date: Mon Nov  2 19:15:46 2015
> > New Revision: 251874
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=251874&view=rev
> > Log:
> > Stop back-patching 'readonly' Objective-C properties with 'readwrite'
> ones.
> >
> > A 'readonly' Objective-C property declared in the primary class can
> > effectively be shadowed by a 'readwrite' property declared within an
> > extension of that class, so long as the types and attributes of the
> > two property declarations are compatible.
> >
> > Previously, this functionality was implemented by back-patching the
> > original 'readonly' property to make it 'readwrite', destroying source
> > information and causing some hideously redundant, incorrect
> > code. Simplify the implementation to express how this should actually
> > be modeled: as a separate property declaration in the extension that
> > shadows (via the name lookup rules) the declaration in the primary
> > class. While here, correct some broken Fix-Its, eliminate a pile of
> > redundant code, clean up the ARC migrator's handling of properties
> > declared in extensions, and fix debug info's naming of methods that
> > come from categories.
> >
> > A wonderous side effect of doing this write is that it eliminates the
> > "AddedObjCPropertyInClassExtension" method from the AST mutation
> > listener, which in turn eliminates the last place where we rewrite
> > entire declarations in a chained PCH file or a module file. This
> > change (which fixes rdar://problem/18475765) will allow us to
> > eliminate the rewritten-decls logic from the serialization library,
> > and fixes a crash (rdar://problem/23247794) illustrated by the
> > test/PCH/chain-categories.m example.
> >
> >
> > Modified:
> >cfe/trunk/include/clang/AST/ASTMutationListener.h
> >cfe/trunk/include/clang/AST/DeclObjC.h
> >cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> >cfe/trunk/include/clang/Sema/Sema.h
> >cfe/trunk/include/clang/Serialization/ASTWriter.h
> >cfe/trunk/lib/ARCMigrate/TransProperties.cpp
> >cfe/trunk/lib/AST/DeclObjC.cpp
> >cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> >cfe/trunk/lib/Frontend/MultiplexConsumer.cpp
> >cfe/trunk/lib/Sema/SemaDeclObjC.cpp
> >cfe/trunk/lib/Sema/SemaExprObjC.cpp
> >cfe/trunk/lib/Sema/SemaObjCProperty.cpp
> >cfe/trunk/lib/Serialization/ASTWriter.cpp
> >cfe/trunk/test/FixIt/atomic-property.m
> >cfe/trunk/test/Index/complete-kvc.m
> >cfe/trunk/test/Modules/ModuleDebugInfo.m
> >cfe/trunk/test/PCH/chain-categories.m
> >cfe/trunk/test/SemaObjC/atomoic-property-synnthesis-rules.m
> >cfe/trunk/test/SemaObjC/property-3.m
> >cfe/trunk/test/SemaObjC/property-in-class-extension-1.m
> >cfe/trunk/test/SemaObjCXX/property-invalid-type.mm
> >
> > Modified: cfe/trunk/include/clang/AST/ASTMutationListener.h
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTMutationListener.h?rev=251874&r1=251873&r2=251874&view=diff
> >
> ==
> > --- cfe/trunk/include/clang/AST/ASTMutationListener.h (original)
> > +++ cfe/trunk/include/clang/AST/ASTMutationListener.h Mon Nov  2
> 19:15:46 2015
> > @@ -92,18 +92,6 @@ public:
> >   virtual void AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD,
> > const ObjCInterfaceDecl
> *IFD) {}
> >
> > -  /// \brief A objc class extension redeclared or introduced a property.
> > -  ///
> > -  /// \param Prop the property in the class extension
> > -  ///
> > -  /// \param OrigProp the property from the original interface that was
> declared
> > -  /// or null if the property was introduced.
> > -  ///
> > -  /// \param ClassExt the class extension.
> > -  virtual void AddedObjCPropertyInClassExtension(const ObjCPropertyDecl
> *Prop,
> > -const ObjCPropertyDecl
> *OrigProp,
> > -const ObjCCategoryDecl
> *ClassExt) {}
> > -
> >   /// \brief A declaration is marked used which was not previously
> marked used.
> >   ///
> >   /// \param D the declaration marked used
> >
> > Modified: cfe/trunk/include/clang/AST/DeclObjC.h
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=251874&r1=251873&r2=251874&view=diff
> >
> ==
> > --- cfe/trunk/include/clang/AST/DeclObjC.h (original)
> > +++ cfe/trunk/include/clang/AST/DeclObjC.h Mon Nov  2 19

Re: [PATCH] D13144: [CUDA] propagate to CUDA sub-compilations target triple of opposite side.

2015-11-02 Thread Artem Belevich via cfe-commits
tra updated this revision to Diff 39017.
tra added a comment.

Moved CUDA toolchain selection to Compilation.
Removed DeviceTriple info from CudaHostActions and CudaDeviceActions.
Removed few now-unnecessary parameters and code that used them.


http://reviews.llvm.org/D13144

Files:
  include/clang/Driver/Action.h
  include/clang/Driver/Compilation.h
  include/clang/Driver/Driver.h
  lib/Driver/Action.cpp
  lib/Driver/Compilation.cpp
  lib/Driver/Driver.cpp
  lib/Driver/Tools.cpp
  test/Driver/cuda-options.cu
  test/SemaCUDA/function-target-hd.cu

Index: test/SemaCUDA/function-target-hd.cu
===
--- test/SemaCUDA/function-target-hd.cu
+++ test/SemaCUDA/function-target-hd.cu
@@ -8,9 +8,9 @@
 // host device functions are not allowed to call device functions.
 
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-// RUN: %clang_cc1 -fsyntax-only -fcuda-is-device -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fcuda-is-device -triple nvptx-unknown-cuda -verify %s
 // RUN: %clang_cc1 -fsyntax-only -fcuda-allow-host-calls-from-host-device -verify %s -DTEST_WARN_HD
-// RUN: %clang_cc1 -fsyntax-only -fcuda-is-device -fcuda-allow-host-calls-from-host-device -verify %s -DTEST_WARN_HD
+// RUN: %clang_cc1 -fsyntax-only -fcuda-is-device -triple nvptx-unknown-cuda -fcuda-allow-host-calls-from-host-device -verify %s -DTEST_WARN_HD
 
 #include "Inputs/cuda.h"
 
Index: test/Driver/cuda-options.cu
===
--- test/Driver/cuda-options.cu
+++ test/Driver/cuda-options.cu
@@ -111,14 +111,6 @@
 // Make sure we don't link anything.
 // RUN:   -check-prefix CUDA-NL %s
 
-// Match device-side preprocessor, and compiler phases with -save-temps
-// CUDA-D1S: "-cc1" "-triple" "nvptx{{(64)?}}-nvidia-cuda"
-// CUDA-D1S-SAME: "-fcuda-is-device"
-// CUDA-D1S-SAME: "-x" "cuda"
-// CUDA-D1S: "-cc1" "-triple" "nvptx{{(64)?}}-nvidia-cuda"
-// CUDA-D1S-SAME: "-fcuda-is-device"
-// CUDA-D1S-SAME: "-x" "cuda-cpp-output"
-
 // --cuda-host-only should never trigger unused arg warning.
 // RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only -c %s 2>&1 | \
 // RUN:FileCheck -check-prefix CUDA-NO-UNUSED-CHO %s
@@ -133,34 +125,47 @@
 // RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only -x c -c %s 2>&1 | \
 // RUN:FileCheck -check-prefix CUDA-UNUSED-CDO %s
 
+// Match device-side preprocessor, and compiler phases with -save-temps
+// CUDA-D1S: "-cc1" "-triple" "nvptx64-nvidia-cuda"
+// CUDA-D1S-SAME: "-aux-triple" "x86_64--linux-gnu"
+// CUDA-D1S-SAME: "-fcuda-is-device"
+// CUDA-D1S-SAME: "-x" "cuda"
+
+// CUDA-D1S: "-cc1" "-triple" "nvptx64-nvidia-cuda"
+// CUDA-D1S-SAME: "-aux-triple" "x86_64--linux-gnu"
+// CUDA-D1S-SAME: "-fcuda-is-device"
+// CUDA-D1S-SAME: "-x" "cuda-cpp-output"
+
 // Match the job that produces PTX assembly
-// CUDA-D1: "-cc1" "-triple" "nvptx{{(64)?}}-nvidia-cuda"
+// CUDA-D1: "-cc1" "-triple" "nvptx64-nvidia-cuda"
+// CUDA-D1NS-SAME: "-aux-triple" "x86_64--linux-gnu"
 // CUDA-D1-SAME: "-fcuda-is-device"
 // CUDA-D1-SM35-SAME: "-target-cpu" "sm_35"
 // CUDA-D1-SAME: "-o" "[[GPUBINARY1:[^"]*]]"
 // CUDA-D1NS-SAME: "-x" "cuda"
 // CUDA-D1S-SAME: "-x" "ir"
 
-// Match anothe device-side compilation
-// CUDA-D2: "-cc1" "-triple" "nvptx{{(64)?}}-nvidia-cuda"
+// Match another device-side compilation
+// CUDA-D2: "-cc1" "-triple" "nvptx64-nvidia-cuda"
+// CUDA-D2-SAME: "-aux-triple" "x86_64--linux-gnu"
 // CUDA-D2-SAME: "-fcuda-is-device"
 // CUDA-D2-SM30-SAME: "-target-cpu" "sm_30"
 // CUDA-D2-SAME: "-o" "[[GPUBINARY2:[^"]*]]"
 // CUDA-D2-SAME: "-x" "cuda"
 
 // Match no device-side compilation
-// CUDA-ND-NOT: "-cc1" "-triple" "nvptx{{(64)?}}-nvidia-cuda"
+// CUDA-ND-NOT: "-cc1" "-triple" "nvptx64-nvidia-cuda"
 // CUDA-ND-SAME-NOT: "-fcuda-is-device"
 
 // Match host-side preprocessor job with -save-temps
-// CUDA-HS: "-cc1" "-triple"
-// CUDA-HS-SAME-NOT: "nvptx{{(64)?}}-nvidia-cuda"
+// CUDA-HS: "-cc1" "-triple" "x86_64--linux-gnu"
+// CUDA-HS-SAME: "-aux-triple" "nvptx64-nvidia-cuda"
 // CUDA-HS-SAME-NOT: "-fcuda-is-device"
 // CUDA-HS-SAME: "-x" "cuda"
 
 // Match host-side compilation
-// CUDA-H: "-cc1" "-triple"
-// CUDA-H-SAME-NOT: "nvptx{{(64)?}}-nvidia-cuda"
+// CUDA-H: "-cc1" "-triple" "x86_64--linux-gnu"
+// CUDA-H-SAME: "-aux-triple" "nvptx64-nvidia-cuda"
 // CUDA-H-SAME-NOT: "-fcuda-is-device"
 // CUDA-H-SAME: "-o" "[[HOSTOUTPUT:[^"]*]]"
 // CUDA-HNS-SAME: "-x" "cuda"
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -3224,6 +3224,20 @@
   CmdArgs.push_back("-triple");
   CmdArgs.push_back(Args.MakeArgString(TripleStr));
 
+  if (IsCuda) {
+const ToolChain *AuxToolChain;
+if (&getToolChain() == C.getCudaDeviceToolChain())
+  AuxToolChain = C.getCudaHostToolChain();
+else if (&getToolChain() == C.getCudaHostToolChain())
+  AuxToolChain = C.getCudaDeviceToolChain();

Re: [PATCH] D13144: [CUDA] propagate to CUDA sub-compilations target triple of opposite side.

2015-11-02 Thread Artem Belevich via cfe-commits
tra updated this revision to Diff 39019.
tra added a comment.

Moved CUDA toolchain selection to Driver::BuildCompilation() where Compilation 
is set up.


http://reviews.llvm.org/D13144

Files:
  include/clang/Driver/Action.h
  include/clang/Driver/Compilation.h
  include/clang/Driver/Driver.h
  lib/Driver/Action.cpp
  lib/Driver/Compilation.cpp
  lib/Driver/Driver.cpp
  lib/Driver/Tools.cpp
  test/Driver/cuda-options.cu
  test/SemaCUDA/function-target-hd.cu

Index: test/SemaCUDA/function-target-hd.cu
===
--- test/SemaCUDA/function-target-hd.cu
+++ test/SemaCUDA/function-target-hd.cu
@@ -8,9 +8,9 @@
 // host device functions are not allowed to call device functions.
 
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-// RUN: %clang_cc1 -fsyntax-only -fcuda-is-device -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fcuda-is-device -triple nvptx-unknown-cuda -verify %s
 // RUN: %clang_cc1 -fsyntax-only -fcuda-allow-host-calls-from-host-device -verify %s -DTEST_WARN_HD
-// RUN: %clang_cc1 -fsyntax-only -fcuda-is-device -fcuda-allow-host-calls-from-host-device -verify %s -DTEST_WARN_HD
+// RUN: %clang_cc1 -fsyntax-only -fcuda-is-device -triple nvptx-unknown-cuda -fcuda-allow-host-calls-from-host-device -verify %s -DTEST_WARN_HD
 
 #include "Inputs/cuda.h"
 
Index: test/Driver/cuda-options.cu
===
--- test/Driver/cuda-options.cu
+++ test/Driver/cuda-options.cu
@@ -111,14 +111,6 @@
 // Make sure we don't link anything.
 // RUN:   -check-prefix CUDA-NL %s
 
-// Match device-side preprocessor, and compiler phases with -save-temps
-// CUDA-D1S: "-cc1" "-triple" "nvptx{{(64)?}}-nvidia-cuda"
-// CUDA-D1S-SAME: "-fcuda-is-device"
-// CUDA-D1S-SAME: "-x" "cuda"
-// CUDA-D1S: "-cc1" "-triple" "nvptx{{(64)?}}-nvidia-cuda"
-// CUDA-D1S-SAME: "-fcuda-is-device"
-// CUDA-D1S-SAME: "-x" "cuda-cpp-output"
-
 // --cuda-host-only should never trigger unused arg warning.
 // RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only -c %s 2>&1 | \
 // RUN:FileCheck -check-prefix CUDA-NO-UNUSED-CHO %s
@@ -133,34 +125,47 @@
 // RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only -x c -c %s 2>&1 | \
 // RUN:FileCheck -check-prefix CUDA-UNUSED-CDO %s
 
+// Match device-side preprocessor, and compiler phases with -save-temps
+// CUDA-D1S: "-cc1" "-triple" "nvptx64-nvidia-cuda"
+// CUDA-D1S-SAME: "-aux-triple" "x86_64--linux-gnu"
+// CUDA-D1S-SAME: "-fcuda-is-device"
+// CUDA-D1S-SAME: "-x" "cuda"
+
+// CUDA-D1S: "-cc1" "-triple" "nvptx64-nvidia-cuda"
+// CUDA-D1S-SAME: "-aux-triple" "x86_64--linux-gnu"
+// CUDA-D1S-SAME: "-fcuda-is-device"
+// CUDA-D1S-SAME: "-x" "cuda-cpp-output"
+
 // Match the job that produces PTX assembly
-// CUDA-D1: "-cc1" "-triple" "nvptx{{(64)?}}-nvidia-cuda"
+// CUDA-D1: "-cc1" "-triple" "nvptx64-nvidia-cuda"
+// CUDA-D1NS-SAME: "-aux-triple" "x86_64--linux-gnu"
 // CUDA-D1-SAME: "-fcuda-is-device"
 // CUDA-D1-SM35-SAME: "-target-cpu" "sm_35"
 // CUDA-D1-SAME: "-o" "[[GPUBINARY1:[^"]*]]"
 // CUDA-D1NS-SAME: "-x" "cuda"
 // CUDA-D1S-SAME: "-x" "ir"
 
-// Match anothe device-side compilation
-// CUDA-D2: "-cc1" "-triple" "nvptx{{(64)?}}-nvidia-cuda"
+// Match another device-side compilation
+// CUDA-D2: "-cc1" "-triple" "nvptx64-nvidia-cuda"
+// CUDA-D2-SAME: "-aux-triple" "x86_64--linux-gnu"
 // CUDA-D2-SAME: "-fcuda-is-device"
 // CUDA-D2-SM30-SAME: "-target-cpu" "sm_30"
 // CUDA-D2-SAME: "-o" "[[GPUBINARY2:[^"]*]]"
 // CUDA-D2-SAME: "-x" "cuda"
 
 // Match no device-side compilation
-// CUDA-ND-NOT: "-cc1" "-triple" "nvptx{{(64)?}}-nvidia-cuda"
+// CUDA-ND-NOT: "-cc1" "-triple" "nvptx64-nvidia-cuda"
 // CUDA-ND-SAME-NOT: "-fcuda-is-device"
 
 // Match host-side preprocessor job with -save-temps
-// CUDA-HS: "-cc1" "-triple"
-// CUDA-HS-SAME-NOT: "nvptx{{(64)?}}-nvidia-cuda"
+// CUDA-HS: "-cc1" "-triple" "x86_64--linux-gnu"
+// CUDA-HS-SAME: "-aux-triple" "nvptx64-nvidia-cuda"
 // CUDA-HS-SAME-NOT: "-fcuda-is-device"
 // CUDA-HS-SAME: "-x" "cuda"
 
 // Match host-side compilation
-// CUDA-H: "-cc1" "-triple"
-// CUDA-H-SAME-NOT: "nvptx{{(64)?}}-nvidia-cuda"
+// CUDA-H: "-cc1" "-triple" "x86_64--linux-gnu"
+// CUDA-H-SAME: "-aux-triple" "nvptx64-nvidia-cuda"
 // CUDA-H-SAME-NOT: "-fcuda-is-device"
 // CUDA-H-SAME: "-o" "[[HOSTOUTPUT:[^"]*]]"
 // CUDA-HNS-SAME: "-x" "cuda"
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -3224,6 +3224,20 @@
   CmdArgs.push_back("-triple");
   CmdArgs.push_back(Args.MakeArgString(TripleStr));
 
+  if (IsCuda) {
+const ToolChain *AuxToolChain;
+if (&getToolChain() == C.getCudaDeviceToolChain())
+  AuxToolChain = C.getCudaHostToolChain();
+else if (&getToolChain() == C.getCudaHostToolChain())
+  AuxToolChain = C.getCudaDeviceToolChain();
+else
+  llvm_unreachable("Can't figure out CUDA compilation mode.");
+if (Au

Re: [PATCH] D13144: [CUDA] propagate to CUDA sub-compilations target triple of opposite side.

2015-11-02 Thread Artem Belevich via cfe-commits
tra marked an inline comment as done.
tra added a comment.

http://reviews.llvm.org/D13144



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


[PATCH] D14274: Add alloc_size attribute to clang

2015-11-02 Thread George Burgess IV via cfe-commits
george.burgess.iv created this revision.
george.burgess.iv added a reviewer: rsmith.
george.burgess.iv added a subscriber: cfe-commits.

This is the first in a two patch series aimed at adding the alloc_size 
attribute to clang. This patch adds the alloc_size attribute, docs, and all of 
the logic needed to handle it in ExprConstant. The only thing that's _really_ 
missing is our ability to handle non-const locals, because that's proving to be 
a moderately interesting challenge. (Spoiler alert: that's basically the only 
thing in patch #2)

There's also a restructuring of TryEvaluateBuiltinObjectSize thrown in, because 
I felt like it was getting overly subtle. Hopefully the new version is 
considerably easier to reason about. :)

— Implementation notes —
- With the restructuring of TryEvaluateBuiltinObjectSize, I was able to make 
EM_DesignatorFold (now EM_OffsetFold) the only EvalMode we use in evaluating 
__builtin_object_size.

- The InvalidBase functionality of LValues was further (ab)used to get 
information to TryEvaluateBuiltinObjectSize. We know an LValue has been 
initialized by an alloc_size function if the base is invalid and the base 
itself is a CallExpr. This won’t conflict with current behavior, because (prior 
to this patch) all invalid bases were MemberExprs.

- As said in the ExprConstant code, I’d love a less hand-wavy approach to 
writing tryEvaluateLValueAsAllocSize.

http://reviews.llvm.org/D14274

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/ExprConstant.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/alloc-size.c
  test/Sema/alloc-size.c

Index: test/Sema/alloc-size.c
===
--- /dev/null
+++ test/Sema/alloc-size.c
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 %s -verify
+
+void *fail1(int a) __attribute__((alloc_size)); //expected-error{{'alloc_size' attribute takes at least 1 argument}}
+void *fail2(int a) __attribute__((alloc_size())); //expected-error{{'alloc_size' attribute takes at least 1 argument}}
+
+void *fail3(int a) __attribute__((alloc_size(0))); //expected-error{{'alloc_size' attribute parameter 1 is out of bounds: can only be 1, since there is one parameter}}
+void *fail4(int a) __attribute__((alloc_size(2))); //expected-error{{'alloc_size' attribute parameter 1 is out of bounds: can only be 1, since there is one parameter}}
+
+void *fail5(int a, int b) __attribute__((alloc_size(0, 1))); //expected-error{{'alloc_size' attribute parameter 1 is out of bounds: must be between 1 and 2}}
+void *fail6(int a, int b) __attribute__((alloc_size(3, 1))); //expected-error{{'alloc_size' attribute parameter 1 is out of bounds: must be between 1 and 2}}
+
+void *fail7(int a, int b) __attribute__((alloc_size(1, 0))); //expected-error{{'alloc_size' attribute parameter 2 is out of bounds: must be between 1 and 2}}
+void *fail8(int a, int b) __attribute__((alloc_size(1, 3))); //expected-error{{'alloc_size' attribute parameter 2 is out of bounds: must be between 1 and 2}}
+
+int fail9(int a) __attribute__((alloc_size(1))); //expected-warning{{'alloc_size' attribute only applies to return values that are pointers}}
+
+int fail10 __attribute__((alloc_size(1))); //expected-warning{{'alloc_size' attribute only applies to functions}}
+
+void *fail11(void *a) __attribute__((alloc_size(1))); //expected-error{{'alloc_size' attribute only applies to integer arguments}}
+
+void *fail12(int a) __attribute__((alloc_size("abc"))); //expected-error{{'alloc_size' attribute requires parameter 1 to be an integer constant}}
+void *fail12(int a) __attribute__((alloc_size(1, "abc"))); //expected-error{{'alloc_size' attribute requires parameter 2 to be an integer constant}}
+void *fail13(int a) __attribute__((alloc_size(1U<<31))); //expected-error{{integer constant expression evaluates to value 2147483648 that cannot be represented in a 32-bit signed integer type}}
Index: test/CodeGen/alloc-size.c
===
--- /dev/null
+++ test/CodeGen/alloc-size.c
@@ -0,0 +1,263 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm %s -o - 2>&1 | FileCheck %s
+
+#define NULL ((void *)0)
+
+int gi;
+
+void *my_malloc(int size) __attribute__((alloc_size(1)));
+void *my_calloc(int elem_size, int num_elems) __attribute__((alloc_size(1, 2)));
+
+// CHECK-LABEL: @test1
+void test1() {
+  void *const vp = my_malloc(100);
+  // CHECK: store i32 100
+  gi = __builtin_object_size(vp, 0);
+  // CHECK: store i32 100
+  gi = __builtin_object_size(vp, 1);
+  // CHECK: store i32 100
+  gi = __builtin_object_size(vp, 2);
+  // CHECK: store i32 100
+  gi = __builtin_object_size(vp, 3);
+
+  void *const arr = my_calloc(100, 5);
+  // CHECK: store i32 500
+  gi = __builtin_object_size(arr, 0);
+  // CHECK: store i32 500
+  gi = __builtin_object_size(arr, 1);
+  // CHECK: store i32 500
+  gi = __builtin_object_size(arr, 2);
+  // CHECK: store i3

r251898 - [modules] Rationalize the behavior of Decl::declarationReplaces, and in

2015-11-02 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon Nov  2 21:13:11 2015
New Revision: 251898

URL: http://llvm.org/viewvc/llvm-project?rev=251898&view=rev
Log:
[modules] Rationalize the behavior of Decl::declarationReplaces, and in
particular don't assume that two declarations of the same kind in the same
context are declaring the same entity. That's not true when the same name is
declared multiple times as internal-linkage symbols within a module.
(getCanonicalDecl is cheap now, so we can just use it here.)

Added:
cfe/trunk/test/Modules/Inputs/internal-constants/
cfe/trunk/test/Modules/Inputs/internal-constants/a.h
cfe/trunk/test/Modules/Inputs/internal-constants/b.h
cfe/trunk/test/Modules/Inputs/internal-constants/c.h
cfe/trunk/test/Modules/Inputs/internal-constants/const.h
cfe/trunk/test/Modules/Inputs/internal-constants/module.modulemap
cfe/trunk/test/Modules/internal-constants.cpp
Modified:
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
cfe/trunk/test/SemaCXX/enable_if.cpp

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=251898&r1=251897&r2=251898&view=diff
==
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Mon Nov  2 21:13:11 2015
@@ -1451,32 +1451,6 @@ void NamedDecl::getNameForDiagnostic(raw
 printName(OS);
 }
 
-static bool isKindReplaceableBy(Decl::Kind OldK, Decl::Kind NewK) {
-  // For method declarations, we never replace.
-  if (ObjCMethodDecl::classofKind(NewK))
-return false;
-
-  if (OldK == NewK)
-return true;
-
-  // A compatibility alias for a class can be replaced by an interface.
-  if (ObjCCompatibleAliasDecl::classofKind(OldK) &&
-  ObjCInterfaceDecl::classofKind(NewK))
-return true;
-
-  // A typedef-declaration, alias-declaration, or Objective-C class declaration
-  // can replace another declaration of the same type. Semantic analysis checks
-  // that we have matching types.
-  if ((TypedefNameDecl::classofKind(OldK) ||
-   ObjCInterfaceDecl::classofKind(OldK)) &&
-  (TypedefNameDecl::classofKind(NewK) ||
-   ObjCInterfaceDecl::classofKind(NewK)))
-return true;
-
-  // Otherwise, a kind mismatch implies that the declaration is not replaced.
-  return false;
-}
-
 template static bool isRedeclarableImpl(Redeclarable *) {
   return true;
 }
@@ -1500,9 +1474,19 @@ bool NamedDecl::declarationReplaces(Name
   if (OldD->isFromASTFile() && isFromASTFile())
 return false;
 
-  if (!isKindReplaceableBy(OldD->getKind(), getKind()))
+  // A kind mismatch implies that the declaration is not replaced.
+  if (OldD->getKind() != getKind())
+return false;
+
+  // For method declarations, we never replace. (Why?)
+  if (isa(this))
 return false;
 
+  // For parameters, pick the newer one. This is either an error or (in
+  // Objective-C) permitted as an extension.
+  if (isa(this))
+return true;
+
   // Inline namespaces can give us two declarations with the same
   // name and kind in the same scope but different contexts; we should
   // keep both declarations in this case.
@@ -1510,28 +1494,8 @@ bool NamedDecl::declarationReplaces(Name
   OldD->getDeclContext()->getRedeclContext()))
 return false;
 
-  if (const FunctionDecl *FD = dyn_cast(this))
-// For function declarations, we keep track of redeclarations.
-// FIXME: This returns false for functions that should in fact be replaced.
-// Instead, perform some kind of type check?
-if (FD->getPreviousDecl() != OldD)
-  return false;
-
-  // For function templates, the underlying function declarations are linked.
-  if (const FunctionTemplateDecl *FunctionTemplate =
-  dyn_cast(this))
-return FunctionTemplate->getTemplatedDecl()->declarationReplaces(
-cast(OldD)->getTemplatedDecl());
-
-  // Using shadow declarations can be overloaded on their target declarations
-  // if they introduce functions.
-  // FIXME: If our target replaces the old target, can we replace the old
-  //shadow declaration?
-  if (auto *USD = dyn_cast(this))
-if (USD->getTargetDecl() != cast(OldD)->getTargetDecl())
-  return false;
-
-  // Using declarations can be overloaded if they introduce functions.
+  // Using declarations can be replaced if they import the same name from the
+  // same context.
   if (auto *UD = dyn_cast(this)) {
 ASTContext &Context = getASTContext();
 return Context.getCanonicalNestedNameSpecifier(UD->getQualifier()) ==
@@ -1546,13 +1510,20 @@ bool NamedDecl::declarationReplaces(Name
   }
 
   // UsingDirectiveDecl's are not really NamedDecl's, and all have same name.
-  // We want to keep it, unless it nominates same namespace.
+  // They can be replaced if they nominate the same namespace.
+  // FIXME: Is this true even if they hav

Re: [PATCH] D13357: [Concepts] Diagnose when 'concept' is specified on a specialization

2015-11-02 Thread Nathan Wilson via cfe-commits
nwilson updated this revision to Diff 39030.
nwilson added a comment.

Updating to r251898


http://reviews.llvm.org/D13357

Files:
  include/clang/AST/Decl.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaTemplate.cpp
  test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p1.cpp

Index: test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p1.cpp
===
--- test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p1.cpp
+++ test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p1.cpp
@@ -39,3 +39,20 @@
 template  concept union TCU1 {}; // expected-error {{'concept' can only appear on the definition of a function template or variable template}}
 
 concept bool; // expected-error {{'concept' can only appear on the definition of a function template or variable template}}
+
+template concept bool VCEI { true };
+template concept bool VCEI; // expected-error {{'concept' cannot be applied on an explicit instantiation}}
+extern template concept bool VCEI; // expected-error {{'concept' cannot be applied on an explicit instantiation}}
+
+template concept bool VCPS { true };
+template concept bool VCPS { true }; // expected-error {{'concept' cannot be applied on an partial specialization}}
+
+template concept bool VCES { true };
+template<> concept bool VCES { true }; // expected-error {{'concept' cannot be applied on an explicit specialization}}
+
+template concept bool FCEI() { return true; }
+template concept bool FCEI(); // expected-error {{'concept' cannot be applied on an explicit instantiation}}
+extern template concept bool FCEI(); // expected-error {{'concept' cannot be applied on an explicit instantiation}}
+
+template concept bool FCES() { return true; }
+template<> concept bool FCES() { return true; } // expected-error {{'concept' cannot be applied on an explicit specialization}}
Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -7597,6 +7597,17 @@
 Diag(D.getDeclSpec().getConstexprSpecLoc(),
  diag::err_explicit_instantiation_constexpr);
 
+  // C++ Concepts TS [dcl.spec.concept]p1: The concept specifier shall be
+  // applied only to the definition of a function template or variable template,
+  // declared in namespace scope. A concept definition refers to either a
+  // function concept and its definition or a variable concept and its
+  // initializer.
+  if (D.getDeclSpec().isConceptSpecified()) {
+Diag(D.getDeclSpec().getConceptSpecLoc(),
+ diag:: err_concept_specified_specialization) << 0;
+return true;
+  }
+
   // C++0x [temp.explicit]p2:
   //   There are two forms of explicit instantiation: an explicit instantiation
   //   definition and an explicit instantiation declaration. An explicit
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -5898,6 +5898,17 @@
 << 0 << 3;
 NewVD->setInvalidDecl(true);
   }
+
+  // C++ Concepts TS [dcl.spec.concept]p1: The concept specifier shall be
+  // applied only to the definition of a [...] variable template, declared
+  // in namespace scope. [...] A concept definition refers to [...] a
+  // variable concept and its initializer.
+  if (IsVariableTemplateSpecialization) {
+Diag(D.getDeclSpec().getConceptSpecLoc(),
+ diag::err_concept_specified_specialization)
+  << (IsPartialSpecialization ? 2 : 1);
+NewVD->setInvalidDecl(true);
+  }
 }
   }
 
@@ -7544,6 +7555,9 @@
 }
 
 if (isConcept) {
+  // This is a function concept.
+  NewFD->setConcept(true);
+
   // C++ Concepts TS [dcl.spec.concept]p1: The concept specifier shall be
   // applied only to the definition of a function template [...]
   if (!D.isFunctionDefinition()) {
@@ -7595,6 +7609,15 @@
 << 1 << 3;
 NewFD->setInvalidDecl(true);
   }
+
+  // C++ Concepts TS [dcl.spec.concept]p1: The concept specifier shall be
+  // applied only to the definition of a function template [...], declared
+  // in namespace scope. [...] A concept definition refers to either a
+  // function concept and its definition [...].
+  if (isFunctionTemplateSpecialization) {
+Diag(D.getDeclSpec().getConceptSpecLoc(),
+ diag::err_concept_specified_specialization) << 1;
+  }
 }
 
 // If __module_private__ was specified, mark the function accordingly.
@@ -7858,7 +7881,7 @@
  TemplateArgs);
 
   HasExplicitTemplateArgs = true;
-
+
   if (NewFD->isInvalidDecl()) {
 HasExplicitTemplateArgs = false;
   } else if (FunctionTemplate) {
Index: include/clang/Basic/DiagnosticSemaKinds.td
===

Re: [PATCH] D13357: [Concepts] Diagnose when 'concept' is specified on a specialization

2015-11-02 Thread Nathan Wilson via cfe-commits
nwilson added inline comments.


Comment at: lib/Sema/SemaDecl.cpp:5909
@@ +5908,3 @@
+ diag::err_concept_specified_specialization)
+  << (IsPartialSpecialization ? 2 : 1);
+NewVD->setInvalidDecl(true);

Hmm, I'd lean toward leaving it as is until the wording is sorted out. I don't 
feel too strongly either way though.


http://reviews.llvm.org/D13357



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


Re: [PATCH] D14259: The maximum alignment of std::aligned_storage applies to all Windows compilers

2015-11-02 Thread Saleem Abdulrasool via cfe-commits
compnerd added a subscriber: compnerd.
compnerd accepted this revision.
compnerd added a reviewer: compnerd.
compnerd added a comment.
This revision is now accepted and ready to land.

Yeah, this is a COFF limitation.  Its unfortunate we don't have a better way to 
detect COFF targets.


http://reviews.llvm.org/D14259



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


Re: [PATCH] D12922: Add support for function attribute "notail"

2015-11-02 Thread Akira Hatanaka via cfe-commits
ahatanak added inline comments.


Comment at: lib/Sema/SemaDecl.cpp:5374
@@ +5373,3 @@
+
+  // Virtual functions cannot be marked as 'notail'.
+  if (auto *Attr = ND.getAttr())

aaron.ballman wrote:
> I am not home yet, and so I don't have the source code to try this out, but I 
> have a sneaking suspicion there's a way to tell whether a function is an 
> override. IIRC, it's something like overridden_methods() on a CXXMethodDecl.
> 
> I will do some poking when I am back in front of the source. Otherwise, I 
> would guess you can look at some of the diagnostics in DiagnosticSemaKinds.td 
> for the override keyword itself, because I bet we warn when you specify 
> override on something that isn't a virtual function override, and that should 
> have a code example.
It's possible to tell a method is a virtual function if either an overridden 
method is added to its declaration (which will cause isVirtual() to return 
true) or an OverrideAttr attribute is added. Currently, processDeclAttributes 
is called before these methods or attributes are added, and that is why I think 
it isn't possible to tell if the method is virtual when the attributes are 
being checked.


http://reviews.llvm.org/D12922



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


r251900 - Fix a couple intrinsic header comments. NFC

2015-11-02 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Tue Nov  3 00:16:31 2015
New Revision: 251900

URL: http://llvm.org/viewvc/llvm-project?rev=251900&view=rev
Log:
Fix a couple intrinsic header comments. NFC

Modified:
cfe/trunk/lib/Headers/avx512erintrin.h
cfe/trunk/lib/Headers/avx512fintrin.h

Modified: cfe/trunk/lib/Headers/avx512erintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512erintrin.h?rev=251900&r1=251899&r2=251900&view=diff
==
--- cfe/trunk/lib/Headers/avx512erintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512erintrin.h Tue Nov  3 00:16:31 2015
@@ -1,4 +1,4 @@
-/*=== avx512fintrin.h - AVX2 intrinsics 
---===
+/*=== avx512erintrin.h - AVX512ER intrinsics ---===
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to 
deal

Modified: cfe/trunk/lib/Headers/avx512fintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512fintrin.h?rev=251900&r1=251899&r2=251900&view=diff
==
--- cfe/trunk/lib/Headers/avx512fintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512fintrin.h Tue Nov  3 00:16:31 2015
@@ -1,4 +1,4 @@
-/*=== avx512fintrin.h - AVX2 intrinsics ===
+/*=== avx512fintrin.h - AVX512F intrinsics -===
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to 
deal


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


  1   2   >