[PATCH] D35781: [Sema] Make sure that -Wunguarded-availability emits notes at the right redeclaration

2017-07-23 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington planned changes to this revision.
erik.pilkington added a comment.

On second thought, I think it makes more sense to do this right before we emit 
a diagnostic so we have the most recent redecl with all the inherited 
availability attributes until then. I'll put a diff up for that tomorrow!


https://reviews.llvm.org/D35781



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


[PATCH] D35782: [C++2a][Preprocessor] Implement p0306 __VA_OPT__ (Comma omission and comma deletion)

2017-07-23 Thread Faisal Vali via Phabricator via cfe-commits
faisalv created this revision.
faisalv added a project: clang.

This patch implements an extension to the preprocessor: __VA_OPT__ which 
expands into its contents if variadic arguments are supplied, or behaves as an 
empty token if none.

- currently it is only enabled for C++2a (we could always enable this for 
various other dialects with the appropriate extension or compatibility warnings)

Given:

  #define F(a,...) a #__VA_OPT__(a ## a)  a ## __VA_OPT__(__VA_ARGS__)

A few technicalities (most which were clarified through private correspondence 
between rsmith, hubert and thomas) are worth mentioning:

- the call F(,)  Does not supply any tokens for the variadic arguments and 
hence __VA_OPT__ behaves as a placeholder
- when expanding VA_OPT (for e.g. F(,1) token pasting occurs eagerly within its 
contents
- a hash or a hashhash prior to __VA_OPT__ does not inhibit expansion of 
arguments if they are the first token within VA_OPT.
- essentially, when a variadic argument is supplied, argument substitution 
occurs within the contents as does stringification and concatenation - and this 
is substituted, potentially strinigified and concatenated content (but not 
rescanned) is inserted into the macro expansions token stream just prior to the 
entire stream being rescanned and concatenated.

See wg21.link/P0306 for further details.
See the example files for more involved examples.

Would greatly appreciate timely feedback =)


Repository:
  rL LLVM

https://reviews.llvm.org/D35782

Files:
  include/clang/Basic/DiagnosticLexKinds.td
  include/clang/Lex/Preprocessor.h
  include/clang/Lex/TokenLexer.h
  include/clang/Lex/VariadicMacroSupport.h
  lib/Lex/PPDirectives.cpp
  lib/Lex/Preprocessor.cpp
  lib/Lex/TokenLexer.cpp
  test/Preprocessor/macro_vaopt_check.cpp
  test/Preprocessor/macro_vaopt_expand.cpp

Index: test/Preprocessor/macro_vaopt_expand.cpp
===
--- test/Preprocessor/macro_vaopt_expand.cpp
+++ test/Preprocessor/macro_vaopt_expand.cpp
@@ -0,0 +1,127 @@
+// RUN: %clang_cc1 -E %s -pedantic -std=c++2a | FileCheck -strict-whitespace %s
+
+#define LPAREN ( 
+#define RPAREN ) 
+
+#define A0 expandedA0
+#define A1  expandedA1 A0
+#define A2  expandedA2 A1
+#define A3  expandedA3 A2
+
+#define A() B LPAREN )
+#define B() C LPAREN )
+#define C() D LPAREN )
+
+
+#define F(x, y) x + y 
+#define ELLIP_FUNC(...) __VA_OPT__(__VA_ARGS__)
+
+1: ELLIP_FUNC(F, LPAREN, 'a', 'b', RPAREN); 
+2: ELLIP_FUNC(F LPAREN 'a', 'b' RPAREN); 
+#undef F
+#undef ELLIP_FUNC
+
+// CHECK: 1: F, (, 'a', 'b', );
+// CHECK: 2: 'a' + 'b';
+
+#define F(...) f(0 __VA_OPT__(,) __VA_ARGS__)
+3: F(a, b, c) // replaced by f(0, a, b, c) 
+4: F() // replaced by f(0)
+
+// CHECK: 3: f(0 , a, b, c) 
+// CHECK: 4: f(0 )
+#undef F
+
+#define G(X, ...) f(0, X __VA_OPT__(,) __VA_ARGS__)
+
+5: G(a, b, c) // replaced by f(0, a , b, c) 
+6: G(a) // replaced by f(0, a) 
+7: G(a,) // replaced by f(0, a) 
+7.1: G(a,,)
+
+
+// CHECK: 5: f(0, a , b, c) 
+// CHECK: 6: f(0, a ) 
+// CHECK: 7: f(0, a ) 
+// CHECK: 7.1: f(0, a , ,)
+#undef G 
+
+#define HT_B() TONG
+
+#define F(x, ...) HT_ ## __VA_OPT__(x x A()  #x)
+
+8: F(1)
+9: F(A(),1)
+
+// CHECK: 8: HT_
+// CHECK: 9: TONG C ( ) B ( ) "A()"
+#undef HT_B
+#undef F
+
+#define F(a,...) #__VA_OPT__(A1 a)
+
+10: F(A())
+11: F(A1 A(), 1)
+// CHECK: 10: ""
+// CHECK: 11: "A1 expandedA1 expandedA0 B ( )"
+#undef F
+
+
+#define F(a,...) a ## __VA_OPT__(A1 a) ## __VA_ARGS__ ## a
+12.0: F()
+12: F(,)
+13: F(B,)
+// CHECK: 12.0: 
+// CHECK: 12: 
+// CHECK: 13: BB 
+#undef F
+
+#define F(...) #__VA_OPT__()  X ## __VA_OPT__()  #__VA_OPT__()
+
+14: F()
+15: F(1)
+
+// CHECK: 14: "" X ""
+// CHECK: 15: "" X ""
+
+#undef F
+
+#define SDEF(sname, ...) S sname __VA_OPT__(= { __VA_ARGS__ })
+
+16: SDEF(foo); // replaced by S foo; 
+17: SDEF(bar, 1, 2); // replaced by S bar = { 1, 2 }; 
+
+// CHECK: 16: S foo ;
+// CHECK: 17: S bar = { 1, 2 }; 
+#undef SDEF
+
+#define F(a,...) A() #__VA_OPT__(A3 __VA_ARGS__ a ## __VA_ARGS__ ## a ## C A3) A()
+
+18: F()
+19: F(,)
+20: F(,A3)
+21: F(A3, A(),A0)
+
+
+// CHECK: 18: B ( ) "" B ( ) 
+// CHECK: 19: B ( ) "" B ( ) 
+// CHECK: 20: B ( ) "A3 expandedA3 expandedA2 expandedA1 expandedA0 A3C A3" B ( )
+// CHECK: 21: B ( ) "A3 B ( ),expandedA0 A3A(),A0A3C A3" B ( )
+
+#undef F
+
+#define F(a,...) A() #__VA_OPT__(A3 __VA_ARGS__ a ## __VA_ARGS__ ## a ## C A3) a __VA_OPT__(A0 __VA_ARGS__ a ## __VA_ARGS__ ## a ## C A0) A()
+
+22: F()
+23: F(,)
+24: F(,A0)
+25: F(A0, A(),A0)
+
+
+// CHECK: 22: B ( ) "" B ( ) 
+// CHECK: 23: B ( ) "" B ( ) 
+// CHECK: 24: B ( ) "A3 expandedA0 A0C A3" expandedA0 expandedA0 A0C expandedA0 B ( )
+// CHECK: 25: B ( ) "A3 B ( ),expandedA0 A0A(),A0A0C A3" expandedA0 expandedA0 C ( ),expandedA0 A0A(),A0A0C expandedA0 B ( )
+
+#undef F
+
Index: test/Preprocessor/macro_vaopt_check.cpp
===
--- test/Preprocessor/macro_vaopt_check.cpp
+++ 

Re: [PATCH v3] [PPC64]: Add support for Swift calling convention

2017-07-23 Thread Andrew Jeffery via cfe-commits
Hi Hal,

On Sat, 2017-07-22 at 23:26 -0500, Hal Finkel wrote:
> On 07/19/2017 10:26 AM, Adrian Prantl wrote:
> > > > > > On Jun 21, 2017, at 11:32 PM, Andrew Jeffery  
> > > > > > wrote:
> > > 
> > > For the tests I've extracted the int5 and int8 cases to cater for
> > > different alignments for different platform ABIs. For Linux on POWER the
> > > 5 and 8 element vectors must be naturally aligned with respect to the
> > > total "soft" vector size, despite being represented as an aggregate.
> > > Specifically, the patch caters for the following differences in
> > > supporting powerpc64le-unknown-linux:
> > > 
> > >    $ diff -u test/CodeGen/64bit-swiftcall.c test/CodeGen/ppc64-swiftcall.c
> > > > > >    --- test/CodeGen/64bit-swiftcall.c   2017-04-20 
> > > > > > 17:14:59.797963820 +0930
> > > > > >    +++ test/CodeGen/ppc64-swiftcall.c   2017-04-20 
> > > > > > 17:15:11.621965118 +0930
> > >    @@ -1,7 +1,6 @@
> > >    -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 
> > > -emit-llvm -o - %s | FileCheck %s
> > >    -// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone 
> > > -emit-llvm -o - %s | FileCheck %s
> > >    +// RUN: %clang_cc1 -triple powerpc64le-unknown-linux -emit-llvm -o - 
> > > %s | FileCheck %s
> > > 
> > >    -// REQUIRES: aarch64-registered-target,x86-registered-target
> > >    +// REQUIRES: powerpc-registered-target
> > > 
> > > #define SWIFTCALL __attribute__((swiftcall))
> > > #define OUT __attribute__((swift_indirect_result))
> > >    @@ -370,8 +369,8 @@
> > > 
> > > TEST(int8)
> > > // CHECK-LABEL: define {{.*}} @return_int8()
> > >    -// CHECK:   [[RET:%.*]] = alloca [[REC:<8 x i32>]], align 16
> > >    +// CHECK:   [[RET:%.*]] = alloca [[REC:<8 x i32>]], align 32
> > > // CHECK:   [[VAR:%.*]] = alloca [[REC]], align
> > > // CHECK:   store
> > > // CHECK:   load
> > > // CHECK:   store
> > >    @@ -414,8 +413,8 @@
> > > 
> > > TEST(int5)
> > > // CHECK-LABEL: define {{.*}} @return_int5()
> > >    -// CHECK:   [[RET:%.*]] = alloca [[REC:<5 x i32>]], align 16
> > >    +// CHECK:   [[RET:%.*]] = alloca [[REC:<5 x i32>]], align 32
> > > // CHECK:   [[VAR:%.*]] = alloca [[REC]], align
> > > // CHECK:   store
> > > // CHECK:   load
> > > // CHECK:   store
> > > 
> > > Despite some duplication, the advantage of this approach over using
> > > pattern matching for alignment in 64bit-swiftcall.c is that we ensure
> > > each platform is using the expected alignment but without duplicating
> > > the entirety of 64bit-swiftcall.c.
> > 
> > You could also write all in one file and use invoke FileCheck with 
> > --check-prefix=CHECK-PPC64 to have a second set of CHECK-lines in the same 
> > input file.
> > 
> > -- adrian
> > > > > > Signed-off-by: Andrew Jeffery 
> > > ---
> > > 
> > > Hello,
> > > 
> > > The only change in v3 is rebasing it on top upstream HEAD, fixing a 
> > > conflict in
> > > one of the lit REQUIRES lines.
> > > 
> > > Ulrich, Hal, Bill: I've Cc'ed you as you were fingered by the blame 
> > > output. As
> > > some background I sent the patch several months ago but it hasn't got much
> > > traction aside from a LGTM from Adrian (thanks!). I'm hoping it gets a 
> > > bit more
> > > attention as without it we get build failures for Swift on POWER, which is
> > > in-turn blocking some CI efforts.
> > > 
> > > Cheers,
> > > 
> > > Andrew
> > > 
> > > lib/Basic/Targets.cpp |  11 ++
> > > lib/CodeGen/TargetInfo.cpp|  14 ++-
> > > test/CodeGen/64bit-swiftcall-extvec-agg-align16.c | 117 
> > > ++
> > > test/CodeGen/64bit-swiftcall-extvec-agg-align32.c | 116 
> > > +
> > > test/CodeGen/64bit-swiftcall.c|  93 +
> > > 5 files changed, 258 insertions(+), 93 deletions(-)
> > > create mode 100644 test/CodeGen/64bit-swiftcall-extvec-agg-align16.c
> > > create mode 100644 test/CodeGen/64bit-swiftcall-extvec-agg-align32.c
> > > 
> > > diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp
> > > index e23a93e..54b5911 100644
> > > --- a/lib/Basic/Targets.cpp
> > > +++ b/lib/Basic/Targets.cpp
> > > @@ -1753,6 +1753,17 @@ public:
> > >  }
> > >  return false;
> > >    }
> > > +
> > > +  CallingConvCheckResult checkCallingConvention(CallingConv CC) const 
> > > override {
> > > +switch (CC) {
> > > +case CC_C:
> > > +case CC_Swift:
> > > +return CCCR_OK;
> > > +default:
> > > +break;
> > > +}
> > > +return CCCR_Warning;
> > > +  }
> > > };
> > > 
> > > class DarwinPPC32TargetInfo : public DarwinTargetInfo {
> > > diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp
> > > index 8d00e05..a82cd24 100644
> > > --- a/lib/CodeGen/TargetInfo.cpp
> > > +++ b/lib/CodeGen/TargetInfo.cpp
> > > @@ -4179,7 +4179,7 @@ 
> > > 

Re: [PATCH v3] [PPC64]: Add support for Swift calling convention

2017-07-23 Thread Andrew Jeffery via cfe-commits
On Wed, 2017-07-19 at 08:26 -0700, Adrian Prantl wrote:
> > > > On Jun 21, 2017, at 11:32 PM, Andrew Jeffery  wrote:
> > 
> > For the tests I've extracted the int5 and int8 cases to cater for
> > different alignments for different platform ABIs. For Linux on POWER the
> > 5 and 8 element vectors must be naturally aligned with respect to the
> > total "soft" vector size, despite being represented as an aggregate.
> > Specifically, the patch caters for the following differences in
> > supporting powerpc64le-unknown-linux:
> > 
> >   $ diff -u test/CodeGen/64bit-swiftcall.c test/CodeGen/ppc64-swiftcall.c
> > > >   --- test/CodeGen/64bit-swiftcall.c2017-04-20 17:14:59.797963820 
> > > > +0930
> > > >   +++ test/CodeGen/ppc64-swiftcall.c2017-04-20 17:15:11.621965118 
> > > > +0930
> >   @@ -1,7 +1,6 @@
> >   -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 
> > -emit-llvm -o - %s | FileCheck %s
> >   -// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone 
> > -emit-llvm -o - %s | FileCheck %s
> >   +// RUN: %clang_cc1 -triple powerpc64le-unknown-linux -emit-llvm -o - %s 
> > | FileCheck %s
> > 
> >   -// REQUIRES: aarch64-registered-target,x86-registered-target
> >   +// REQUIRES: powerpc-registered-target
> > 
> >    #define SWIFTCALL __attribute__((swiftcall))
> >    #define OUT __attribute__((swift_indirect_result))
> >   @@ -370,8 +369,8 @@
> > 
> >    TEST(int8)
> >    // CHECK-LABEL: define {{.*}} @return_int8()
> >   -// CHECK:   [[RET:%.*]] = alloca [[REC:<8 x i32>]], align 16
> >   +// CHECK:   [[RET:%.*]] = alloca [[REC:<8 x i32>]], align 32
> >    // CHECK:   [[VAR:%.*]] = alloca [[REC]], align
> >    // CHECK:   store
> >    // CHECK:   load
> >    // CHECK:   store
> >   @@ -414,8 +413,8 @@
> > 
> >    TEST(int5)
> >    // CHECK-LABEL: define {{.*}} @return_int5()
> >   -// CHECK:   [[RET:%.*]] = alloca [[REC:<5 x i32>]], align 16
> >   +// CHECK:   [[RET:%.*]] = alloca [[REC:<5 x i32>]], align 32
> >    // CHECK:   [[VAR:%.*]] = alloca [[REC]], align
> >    // CHECK:   store
> >    // CHECK:   load
> >    // CHECK:   store
> > 
> > Despite some duplication, the advantage of this approach over using
> > pattern matching for alignment in 64bit-swiftcall.c is that we ensure
> > each platform is using the expected alignment but without duplicating
> > the entirety of 64bit-swiftcall.c.
> 
> You could also write all in one file and use invoke FileCheck with 
> --check-prefix=CHECK-PPC64 to have a second set of CHECK-lines in the same 
> input file.
> 

Ah, interesting. That's probably worth a respin.

Thanks for the feedback.

Andrew

> -- adrian
> > 
> > > > Signed-off-by: Andrew Jeffery 
> > ---
> > 
> > Hello,
> > 
> > The only change in v3 is rebasing it on top upstream HEAD, fixing a 
> > conflict in
> > one of the lit REQUIRES lines.
> > 
> > Ulrich, Hal, Bill: I've Cc'ed you as you were fingered by the blame output. 
> > As
> > some background I sent the patch several months ago but it hasn't got much
> > traction aside from a LGTM from Adrian (thanks!). I'm hoping it gets a bit 
> > more
> > attention as without it we get build failures for Swift on POWER, which is
> > in-turn blocking some CI efforts. 
> > 
> > Cheers,
> > 
> > Andrew
> > 
> > lib/Basic/Targets.cpp |  11 ++
> > lib/CodeGen/TargetInfo.cpp|  14 ++-
> > test/CodeGen/64bit-swiftcall-extvec-agg-align16.c | 117 
> > ++
> > test/CodeGen/64bit-swiftcall-extvec-agg-align32.c | 116 
> > +
> > test/CodeGen/64bit-swiftcall.c|  93 +
> > 5 files changed, 258 insertions(+), 93 deletions(-)
> > create mode 100644 test/CodeGen/64bit-swiftcall-extvec-agg-align16.c
> > create mode 100644 test/CodeGen/64bit-swiftcall-extvec-agg-align32.c
> > 
> > diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp
> > index e23a93e..54b5911 100644
> > --- a/lib/Basic/Targets.cpp
> > +++ b/lib/Basic/Targets.cpp
> > @@ -1753,6 +1753,17 @@ public:
> > }
> > return false;
> >   }
> > +
> > +  CallingConvCheckResult checkCallingConvention(CallingConv CC) const 
> > override {
> > +switch (CC) {
> > +case CC_C:
> > +case CC_Swift:
> > +return CCCR_OK;
> > +default:
> > +break;
> > +}
> > +return CCCR_Warning;
> > +  }
> > };
> > 
> > class DarwinPPC32TargetInfo : public DarwinTargetInfo {
> > diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp
> > index 8d00e05..a82cd24 100644
> > --- a/lib/CodeGen/TargetInfo.cpp
> > +++ b/lib/CodeGen/TargetInfo.cpp
> > @@ -4179,7 +4179,7 @@ 
> > PPC32TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction 
> > ,
> > 
> > namespace {
> > /// PPC64_SVR4_ABIInfo - The 64-bit PowerPC ELF (SVR4) ABI information.
> > -class PPC64_SVR4_ABIInfo : public ABIInfo {
> > +class PPC64_SVR4_ABIInfo : public SwiftABIInfo {
> > public:
> >   enum ABIKind {
> > ELFv1 = 

[PATCH] D34170: [libcxx] Moving compiler specific test infrastructure to compiler.py

2017-07-23 Thread Ben Craig via Phabricator via cfe-commits
bcraig added a comment.

ping


https://reviews.llvm.org/D34170



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


[PATCH] D32411: [libcxx] Provide #include_next alternative for MSVC

2017-07-23 Thread Ben Craig via Phabricator via cfe-commits
bcraig added a comment.

ping


https://reviews.llvm.org/D32411



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


Re: [PATCH] D35780: Introduce -nostdlib++ flag to disable linking the C++ standard library.

2017-07-23 Thread Nico Weber via cfe-commits
On Jul 23, 2017 4:51 PM, "Joerg Sonnenberger"  wrote:

On Sun, Jul 23, 2017 at 03:17:32PM -0400, Nico Weber via cfe-commits wrote:
> On Sun, Jul 23, 2017 at 3:08 PM, Joerg Sonnenberger via Phabricator via
> cfe-commits  wrote:
>
> > joerg added a comment.
> >
> > I don't really like this.
>
> That's cool, you don't need to use the flag.

I'm not talking about the flag, but the implementation.

> > The reason why -lm is added explicitly on many targets is because the
C++
> > STL typically depends on it and that means for static linking and broken
> > ELF linkers, it will be necessary to link against it explicitly.
> >
>
> The driver adds -lm at the end, so it'll work if you add your static
libc++
> flag in user flags, and then -lm gets added at the end. But from what I
> understand, -lm is also there as a usability thing to make c++ a bit more
> accessible than c in this regard, not just for the c++ standard library.
> (Also, if you're trying to statically link your c++ lib, it's possible you
> have some influence on your linker as well.)

I don't think so, it strongly seems to be an implementation detail of
the STL interaction.

> > There is also the question on whether any platform we have currently
uses
> > separate STL and ABI libraries and it is not clear whether the flag
should
> > handle both.
> >
>
> Yes, it should handle both.

If you update the comments and documentation accordingly and stop the
current passing of -lm


If you need this behavior for something, that sounds like something a
-nodefaultlibs++ could do. -nostdlib++ is really meant to disable the c++
stdlib and nothing else.

, it is fine with me. I don't think the libmath
handling should be forced on other STL implementations.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35747: [Driver] Fuchsia defaults to -fno-math-errno

2017-07-23 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308855: [Driver] Fuchsia defaults to -fno-math-errno 
(authored by phosek).

Changed prior to commit:
  https://reviews.llvm.org/D35747?vs=107752=107845#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35747

Files:
  cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
  cfe/trunk/test/Driver/fast-math.c


Index: cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
===
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
@@ -42,6 +42,7 @@
 
   bool HasNativeLLVMSupport() const override { return true; }
   bool IsIntegratedAssemblerDefault() const override { return true; }
+  bool IsMathErrnoDefault() const override { return false; }
   RuntimeLibType GetDefaultRuntimeLibType() const override {
 return ToolChain::RLT_CompilerRT;
   }
Index: cfe/trunk/test/Driver/fast-math.c
===
--- cfe/trunk/test/Driver/fast-math.c
+++ cfe/trunk/test/Driver/fast-math.c
@@ -93,6 +93,8 @@
 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
 // RUN: %clang -### -target x86_64-unknown-dragonfly -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
+// RUN: %clang -### -target x86_64-fuchsia -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
 //
 // Check that -ffast-math disables -fmath-errno, and -fno-fast-math merely
 // preserves the target default. Also check various flag set operations between


Index: cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
===
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
@@ -42,6 +42,7 @@
 
   bool HasNativeLLVMSupport() const override { return true; }
   bool IsIntegratedAssemblerDefault() const override { return true; }
+  bool IsMathErrnoDefault() const override { return false; }
   RuntimeLibType GetDefaultRuntimeLibType() const override {
 return ToolChain::RLT_CompilerRT;
   }
Index: cfe/trunk/test/Driver/fast-math.c
===
--- cfe/trunk/test/Driver/fast-math.c
+++ cfe/trunk/test/Driver/fast-math.c
@@ -93,6 +93,8 @@
 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
 // RUN: %clang -### -target x86_64-unknown-dragonfly -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
+// RUN: %clang -### -target x86_64-fuchsia -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
 //
 // Check that -ffast-math disables -fmath-errno, and -fno-fast-math merely
 // preserves the target default. Also check various flag set operations between
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r308855 - [Driver] Fuchsia defaults to -fno-math-errno

2017-07-23 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Sun Jul 23 15:30:13 2017
New Revision: 308855

URL: http://llvm.org/viewvc/llvm-project?rev=308855=rev
Log:
[Driver] Fuchsia defaults to -fno-math-errno

Patch by Roland McGrath

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

Modified:
cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
cfe/trunk/test/Driver/fast-math.c

Modified: cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Fuchsia.h?rev=308855=308854=308855=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.h Sun Jul 23 15:30:13 2017
@@ -42,6 +42,7 @@ public:
 
   bool HasNativeLLVMSupport() const override { return true; }
   bool IsIntegratedAssemblerDefault() const override { return true; }
+  bool IsMathErrnoDefault() const override { return false; }
   RuntimeLibType GetDefaultRuntimeLibType() const override {
 return ToolChain::RLT_CompilerRT;
   }

Modified: cfe/trunk/test/Driver/fast-math.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fast-math.c?rev=308855=308854=308855=diff
==
--- cfe/trunk/test/Driver/fast-math.c (original)
+++ cfe/trunk/test/Driver/fast-math.c Sun Jul 23 15:30:13 2017
@@ -93,6 +93,8 @@
 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
 // RUN: %clang -### -target x86_64-unknown-dragonfly -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
+// RUN: %clang -### -target x86_64-fuchsia -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
 //
 // Check that -ffast-math disables -fmath-errno, and -fno-fast-math merely
 // preserves the target default. Also check various flag set operations between


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


[PATCH] D35483: clang-format: fix block OpeningLineIndex around preprocessor

2017-07-23 Thread Francois Ferrand via Phabricator via cfe-commits
Typz updated this revision to Diff 107843.
Typz marked 3 inline comments as done.
Typz added a comment.

Address review commentsx


https://reviews.llvm.org/D35483

Files:
  lib/Format/UnwrappedLineParser.cpp
  lib/Format/UnwrappedLineParser.h
  unittests/Format/NamespaceEndCommentsFixerTest.cpp

Index: unittests/Format/NamespaceEndCommentsFixerTest.cpp
===
--- unittests/Format/NamespaceEndCommentsFixerTest.cpp
+++ unittests/Format/NamespaceEndCommentsFixerTest.cpp
@@ -509,6 +509,134 @@
 "}\n"));
 }
 
+TEST_F(NamespaceEndCommentsFixerTest, AddEndCommentForNamespacesAroundMacros) {
+  // Conditional blocks around are fine
+  EXPECT_EQ("namespace A {\n"
+"#if 1\n"
+"int i;\n"
+"#endif\n"
+"}// namespace A",
+fixNamespaceEndComments("namespace A {\n"
+"#if 1\n"
+"int i;\n"
+"#endif\n"
+"}"));
+  EXPECT_EQ("#if 1\n"
+"#endif\n"
+"namespace A {\n"
+"int i;\n"
+"int j;\n"
+"}// namespace A",
+fixNamespaceEndComments("#if 1\n"
+"#endif\n"
+"namespace A {\n"
+"int i;\n"
+"int j;\n"
+"}"));
+  EXPECT_EQ("namespace A {\n"
+"int i;\n"
+"int j;\n"
+"}// namespace A\n"
+"#if 1\n"
+"#endif",
+fixNamespaceEndComments("namespace A {\n"
+"int i;\n"
+"int j;\n"
+"}\n"
+"#if 1\n"
+"#endif"));
+  EXPECT_EQ("#if 1\n"
+"namespace A {\n"
+"int i;\n"
+"int j;\n"
+"}// namespace A\n"
+"#endif",
+fixNamespaceEndComments("#if 1\n"
+"namespace A {\n"
+"int i;\n"
+"int j;\n"
+"}\n"
+"#endif"));
+
+  // Macro definition has no impact
+  EXPECT_EQ("namespace A {\n"
+"#define FOO\n"
+"int i;\n"
+"}// namespace A",
+fixNamespaceEndComments("namespace A {\n"
+"#define FOO\n"
+"int i;\n"
+"}"));
+  EXPECT_EQ("#define FOO\n"
+"namespace A {\n"
+"int i;\n"
+"int j;\n"
+"}// namespace A",
+fixNamespaceEndComments("#define FOO\n"
+"namespace A {\n"
+"int i;\n"
+"int j;\n"
+"}"));
+  EXPECT_EQ("namespace A {\n"
+"int i;\n"
+"int j;\n"
+"}// namespace A\n"
+"#define FOO\n",
+fixNamespaceEndComments("namespace A {\n"
+"int i;\n"
+"int j;\n"
+"}\n"
+"#define FOO\n"));
+
+  // No replacement if open & close in different conditional blocks
+  EXPECT_EQ("#if 1\n"
+"namespace A {\n"
+"#endif\n"
+"int i;\n"
+"int j;\n"
+"#if 1\n"
+"}\n"
+"#endif",
+fixNamespaceEndComments("#if 1\n"
+"namespace A {\n"
+"#endif\n"
+"int i;\n"
+"int j;\n"
+"#if 1\n"
+"}\n"
+"#endif"));
+  EXPECT_EQ("#ifdef A\n"
+"namespace A {\n"
+"#endif\n"
+"int i;\n"
+"int j;\n"
+"#ifdef B\n"
+"}\n"
+"#endif",
+fixNamespaceEndComments("#ifdef A\n"
+"namespace A {\n"
+"#endif\n"
+"int i;\n"
+"int j;\n"
+"#ifdef B\n"
+"}\n"
+"#endif"));
+
+  // No replacement inside unreachable conditional block
+  EXPECT_EQ("#if 0\n"
+"namespace A {\n"
+"int i;\n"
+"int j;\n"
+

[PATCH] D35557: clang-format: merge short case labels with trailing comments

2017-07-23 Thread Francois Ferrand via Phabricator via cfe-commits
Typz updated this revision to Diff 107841.
Typz marked 4 inline comments as done.
Typz added a comment.

Address review comments


https://reviews.llvm.org/D35557

Files:
  lib/Format/UnwrappedLineFormatter.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -897,6 +897,77 @@
"}",
Style);
   verifyFormat("switch (a) {\n"
+   "case 0: return; // comment\n"
+   "case 1: break;  // comment\n"
+   "case 2: return;\n"
+   "// comment\n"
+   "case 3: return;\n"
+   "// comment 1\n"
+   "// comment 2\n"
+   "// comment 3\n"
+   "case 4: break; /* comment */\n"
+   "case 5:\n"
+   "  // comment\n"
+   "  break;\n"
+   "case 6: /* comment */ x = 1; break;\n"
+   "case 7: x = /* comment */ 1; break;\n"
+   "case 8:\n"
+   "  x = 1; /* comment */\n"
+   "  break;\n"
+   "case 9:\n"
+   "  break; // comment line 1\n"
+   " // comment line 2\n"
+   "}",
+   Style);
+  EXPECT_EQ("switch (a) {\n"
+"case 1:\n"
+"  x = 8;\n"
+"  // fall through\n"
+"case 2: x = 8;\n"
+"// comment\n"
+"case 3:\n"
+"  return; /* comment line 1\n"
+"   * comment line 2 */\n"
+"case 4: i = 8;\n"
+"// something else\n"
+"#if FOO\n"
+"case 5: break;\n"
+"#endif\n"
+"}",
+format("switch (a) {\n"
+   "case 1: x = 8;\n"
+   "  // fall through\n"
+   "case 2:\n"
+   "  x = 8;\n"
+   "// comment\n"
+   "case 3:\n"
+   "  return; /* comment line 1\n"
+   "   * comment line 2 */\n"
+   "case 4:\n"
+   "  i = 8;\n"
+   "// something else\n"
+   "#if FOO\n"
+   "case 5: break;\n"
+   "#endif\n"
+   "}",
+   Style));
+  EXPECT_EQ("switch (a) {\n" "case 0:\n"
+"  return; // long long long long long long long long long long long long comment\n"
+"  // line\n" "}",
+format("switch (a) {\n"
+   "case 0: return; // long long long long long long long long long long long long comment line\n"
+   "}",
+   Style));
+  EXPECT_EQ("switch (a) {\n"
+"case 0:\n"
+"  return; /* long long long long long long long long long long long long comment\n"
+" line */\n"
+"}",
+format("switch (a) {\n"
+   "case 0: return; /* long long long long long long long long long long long long comment line */\n"
+   "}",
+   Style));
+  verifyFormat("switch (a) {\n"
"#if FOO\n"
"case 0: return 0;\n"
"#endif\n"
Index: lib/Format/UnwrappedLineFormatter.cpp
===
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -382,7 +382,9 @@
   return 0;
 unsigned NumStmts = 0;
 unsigned Length = 0;
+bool EndsWithComment = false;
 bool InPPDirective = I[0]->InPPDirective;
+const unsigned Level = I[0]->Level;
 for (; NumStmts < 3; ++NumStmts) {
   if (I + 1 + NumStmts == E)
 break;
@@ -392,9 +394,26 @@
   if (Line->First->isOneOf(tok::kw_case, tok::kw_default, tok::r_brace))
 break;
   if (Line->First->isOneOf(tok::kw_if, tok::kw_for, tok::kw_switch,
-   tok::kw_while, tok::comment) ||
-  Line->Last->is(tok::comment))
+   tok::kw_while) ||
+  EndsWithComment)
 return 0;
+  if (Line->First->is(tok::comment)) {
+if (Level != Line->Level)
+  return 0;
+SmallVectorImpl::const_iterator J = I + 2 + NumStmts;
+for (; J != E; ++J) {
+  Line = *J;
+  if (Line->InPPDirective != InPPDirective)
+break;
+  if (Line->First->isOneOf(tok::kw_case, tok::kw_default, tok::r_brace))
+break;
+  if (Line->First->isNot(tok::comment) || Level != Line->Level)
+return 0;
+}
+break;
+  }
+  if (Line->Last->is(tok::comment))
+EndsWithComment = true;
   Length += I[1 + NumStmts]->Last->TotalLength + 1; // 1 for the space.
 }
 if (NumStmts == 0 || NumStmts == 3 || Length > Limit)

[PATCH] D35557: clang-format: merge short case labels with trailing comments

2017-07-23 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added inline comments.



Comment at: unittests/Format/FormatTest.cpp:912
+   "  break;\n"
+   "}",
+   Style);

krasimir wrote:
> I'd suggest adding more cases here, like:
> ```
>"case 6: /* comment */ x = 1; break;\n"
>"case 7: x = /* comment */ 1; break;\n"
>"case 8:\n"
>"  x = 1; /* comment */\n"
>"  break;\n"
>"case 9:\n"
>"  break; // comment line 1\n"
>" // comment line 2\n"
>"case 10:\n"
>"  return; /* comment line 1\n"
>"   * comment line 2 */\n"
>"}",
> ```
> I'm interested also why `case 10` here fails.
`case 10` fails because of test::messUp(), which removes the line break inside 
the comment.


https://reviews.llvm.org/D35557



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


[PATCH] D35781: [Sema] Make sure that -Wunguarded-availability emits notes at the right redeclaration

2017-07-23 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington created this revision.

This is done by modifying ShouldDiagnoseAvailabilityOfDecl() so that the 
OffendingDecl is the one with the original availability attribute. Also, keep 
track of this availability attribute so we don't have to constantly recompute 
it via getAttrForPlatform().

Thanks for taking a look!
Erik


https://reviews.llvm.org/D35781

Files:
  include/clang/AST/DeclBase.h
  include/clang/Sema/DelayedDiagnostic.h
  lib/AST/DeclBase.cpp
  lib/Sema/DelayedDiagnostic.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/Sema/attr-availability-ios.c
  test/Sema/attr-availability-tvos.c
  test/Sema/attr-availability-watchos.c
  test/Sema/attr-availability.c
  test/SemaObjC/protocol-attribute.m

Index: test/SemaObjC/protocol-attribute.m
===
--- test/SemaObjC/protocol-attribute.m
+++ test/SemaObjC/protocol-attribute.m
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
 __attribute ((unavailable))
-@protocol FwProto; // expected-note{{marked unavailable}}
+@protocol FwProto; // expected-note 2 {{marked unavailable}}
 
 Class  cFw = 0;  // expected-error {{'FwProto' is unavailable}}
 
@@ -33,7 +33,7 @@
 
 Class  clsP1 = 0;  // expected-warning {{'MyProto1' is deprecated}}
 
-@protocol FwProto @end // expected-note{{marked unavailable}}
+@protocol FwProto @end
 
 @interface MyClass2  // expected-error {{'FwProto' is unavailable}}
 @end
Index: test/Sema/attr-availability.c
===
--- test/Sema/attr-availability.c
+++ test/Sema/attr-availability.c
@@ -16,7 +16,7 @@
 ATSFontGetPostScriptName(int flags) __attribute__((availability(macosx,introduced=8.0,obsoleted=9.0, message="use ATSFontGetFullPostScriptName"))); // expected-note {{'ATSFontGetPostScriptName' has been explicitly marked unavailable here}}
 
 #if defined(WARN_PARTIAL)
-// expected-note@+3 {{has been explicitly marked partial here}}
+// expected-note@+3 2 {{has been explicitly marked partial here}}
 #endif
 extern void
 PartiallyAvailable() __attribute__((availability(macosx,introduced=10.8)));
@@ -38,11 +38,6 @@
   PartiallyAvailable();
 }
 
-#ifdef WARN_PARTIAL
-// FIXME: This note should point to the declaration with the availability
-// attribute.
-// expected-note@+2 {{marked partial here}}
-#endif
 extern void PartiallyAvailable() ;
 void with_redeclaration() {
 #ifdef WARN_PARTIAL
Index: test/Sema/attr-availability-watchos.c
===
--- test/Sema/attr-availability-watchos.c
+++ test/Sema/attr-availability-watchos.c
@@ -32,8 +32,8 @@
 void f5_attr_reversed_watchos(int) __attribute__((availability(ios, deprecated=3.0))) __attribute__((availability(watchos,introduced=2.0)));
 void f5b_watchos(int) __attribute__((availability(watchos,introduced=2.0))) __attribute__((availability(watchos,deprecated=3.0))); // expected-note {{'f5b_watchos' has been explicitly marked deprecated here}}
 void f5c_watchos(int) __attribute__((availability(ios,introduced=2.0))) __attribute__((availability(ios,deprecated=3.0))); // expected-note {{'f5c_watchos' has been explicitly marked deprecated here}}
-void f6_watchos(int) __attribute__((availability(watchos,deprecated=3.0)));
-void f6_watchos(int) __attribute__((availability(watchos,introduced=2.0))); // expected-note {{'f6_watchos' has been explicitly marked deprecated here}}
+void f6_watchos(int) __attribute__((availability(watchos,deprecated=3.0))); // expected-note {{'f6_watchos' has been explicitly marked deprecated here}}
+void f6_watchos(int) __attribute__((availability(watchos,introduced=2.0)));
 
 void test_watchos() {
   f0_watchos(0); // expected-warning{{'f0_watchos' is deprecated: first deprecated in watchOS 2.1}}
Index: test/Sema/attr-availability-tvos.c
===
--- test/Sema/attr-availability-tvos.c
+++ test/Sema/attr-availability-tvos.c
@@ -7,8 +7,8 @@
 void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(tvos,introduced=2.0,deprecated=2.1,obsoleted=3.0))); // expected-note{{explicitly marked unavailable}}
 
 void f5(int) __attribute__((availability(tvos,introduced=2.0))) __attribute__((availability(tvos,deprecated=3.0))); // expected-note {{'f5' has been explicitly marked deprecated here}}
-void f6(int) __attribute__((availability(tvos,deprecated=3.0)));
-void f6(int) __attribute__((availability(tvos,introduced=2.0))); // expected-note {{'f6' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(tvos,deprecated=3.0))); // expected-note {{'f6' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(tvos,introduced=2.0)));
 
 void test() {
   f0(0); // expected-warning{{'f0' is deprecated: first deprecated in tvOS 2.1}}
@@ -43,8 +43,8 @@
 void f5_attr_reversed_tvos(int) __attribute__((availability(ios, deprecated=3.0))) 

Re: [PATCH] D35780: Introduce -nostdlib++ flag to disable linking the C++ standard library.

2017-07-23 Thread Joerg Sonnenberger via cfe-commits
On Sun, Jul 23, 2017 at 03:17:32PM -0400, Nico Weber via cfe-commits wrote:
> On Sun, Jul 23, 2017 at 3:08 PM, Joerg Sonnenberger via Phabricator via
> cfe-commits  wrote:
> 
> > joerg added a comment.
> >
> > I don't really like this.
> 
> That's cool, you don't need to use the flag.

I'm not talking about the flag, but the implementation.

> > The reason why -lm is added explicitly on many targets is because the C++
> > STL typically depends on it and that means for static linking and broken
> > ELF linkers, it will be necessary to link against it explicitly.
> >
> 
> The driver adds -lm at the end, so it'll work if you add your static libc++
> flag in user flags, and then -lm gets added at the end. But from what I
> understand, -lm is also there as a usability thing to make c++ a bit more
> accessible than c in this regard, not just for the c++ standard library.
> (Also, if you're trying to statically link your c++ lib, it's possible you
> have some influence on your linker as well.)

I don't think so, it strongly seems to be an implementation detail of
the STL interaction.

> > There is also the question on whether any platform we have currently uses
> > separate STL and ABI libraries and it is not clear whether the flag should
> > handle both.
> >
> 
> Yes, it should handle both.

If you update the comments and documentation accordingly and stop the
current passing of -lm, it is fine with me. I don't think the libmath
handling should be forced on other STL implementations.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D35780: Introduce -nostdlib++ flag to disable linking the C++ standard library.

2017-07-23 Thread Nico Weber via cfe-commits
But if you have alternative ideas on how to address this use case
(statically linking a custom libc++ without having to duplicate all the
default libs, in particular built-in ones like libbuiltin-rt), I'm happy to
hear them, or course :-)

On Jul 23, 2017 3:17 PM, "Nico Weber"  wrote:

On Sun, Jul 23, 2017 at 3:08 PM, Joerg Sonnenberger via Phabricator via
cfe-commits  wrote:

> joerg added a comment.
>
> I don't really like this.


That's cool, you don't need to use the flag.


> The reason why -lm is added explicitly on many targets is because the C++
> STL typically depends on it and that means for static linking and broken
> ELF linkers, it will be necessary to link against it explicitly.
>

The driver adds -lm at the end, so it'll work if you add your static libc++
flag in user flags, and then -lm gets added at the end. But from what I
understand, -lm is also there as a usability thing to make c++ a bit more
accessible than c in this regard, not just for the c++ standard library.
(Also, if you're trying to statically link your c++ lib, it's possible you
have some influence on your linker as well.)


> There is also the question on whether any platform we have currently uses
> separate STL and ABI libraries and it is not clear whether the flag should
> handle both.
>

Yes, it should handle both.


>
>
> https://reviews.llvm.org/D35780
>
>
>
> ___
> 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] D35780: Introduce -nostdlib++ flag to disable linking the C++ standard library.

2017-07-23 Thread Nico Weber via cfe-commits
On Sun, Jul 23, 2017 at 3:08 PM, Joerg Sonnenberger via Phabricator via
cfe-commits  wrote:

> joerg added a comment.
>
> I don't really like this.


That's cool, you don't need to use the flag.


> The reason why -lm is added explicitly on many targets is because the C++
> STL typically depends on it and that means for static linking and broken
> ELF linkers, it will be necessary to link against it explicitly.
>

The driver adds -lm at the end, so it'll work if you add your static libc++
flag in user flags, and then -lm gets added at the end. But from what I
understand, -lm is also there as a usability thing to make c++ a bit more
accessible than c in this regard, not just for the c++ standard library.
(Also, if you're trying to statically link your c++ lib, it's possible you
have some influence on your linker as well.)


> There is also the question on whether any platform we have currently uses
> separate STL and ABI libraries and it is not clear whether the flag should
> handle both.
>

Yes, it should handle both.


>
>
> https://reviews.llvm.org/D35780
>
>
>
> ___
> 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


[PATCH] D35780: Introduce -nostdlib++ flag to disable linking the C++ standard library.

2017-07-23 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

I don't really like this. The reason why -lm is added explicitly on many 
targets is because the C++ STL typically depends on it and that means for 
static linking and broken ELF linkers, it will be necessary to link against it 
explicitly.
There is also the question on whether any platform we have currently uses 
separate STL and ABI libraries and it is not clear whether the flag should 
handle both.


https://reviews.llvm.org/D35780



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


[PATCH] D35780: Introduce -nostdlib++ flag to disable linking the C++ standard library.

2017-07-23 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Most of the patch is unifying all the toolchains to call the newly-introduced 
ToolChain::ShouldLinkCXXStdlib() instead of all manually checking for 
`D.CCIsCXX() && !getFlag(nostdlib, nodefaultlibs)`. The actual behavior change 
is to make that function check the new nostdlib++ flag too.

One use-case for this new flag is 
https://cs.chromium.org/chromium/src/build/config/c%2B%2B/BUILD.gn?type=cs=nodefaultlibs=package:chromium=32


https://reviews.llvm.org/D35780



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


[PATCH] D35780: Introduce -nostdlib++ flag to disable linking the C++ standard library.

2017-07-23 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
Herald added subscribers: aheejin, jgravelle-google, sbc100, dschuff, jfb, 
emaste.

Projects that want to statically link their own C++ standard library currently 
need to pass -nostdlib or -nodefaultlibs, which also disables linking of the 
builtins library, -lm, and so on. Alternatively, they could use `clang` instead 
of `clang++`, but that already disables implicit addition of -lm on some 
toolchains.

Add a dedicated flag -nostdlib++ that disables just linking of libc++ / 
libstdc++. This is analogous to -nostdinc++.


https://reviews.llvm.org/D35780

Files:
  include/clang/Driver/Options.td
  include/clang/Driver/ToolChain.h
  lib/Driver/ToolChain.cpp
  lib/Driver/ToolChains/Ananas.cpp
  lib/Driver/ToolChains/BareMetal.cpp
  lib/Driver/ToolChains/CloudABI.cpp
  lib/Driver/ToolChains/CommonArgs.cpp
  lib/Driver/ToolChains/CrossWindows.cpp
  lib/Driver/ToolChains/Darwin.cpp
  lib/Driver/ToolChains/DragonFly.cpp
  lib/Driver/ToolChains/FreeBSD.cpp
  lib/Driver/ToolChains/Fuchsia.cpp
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/ToolChains/Hexagon.cpp
  lib/Driver/ToolChains/MinGW.cpp
  lib/Driver/ToolChains/Minix.cpp
  lib/Driver/ToolChains/NaCl.cpp
  lib/Driver/ToolChains/NetBSD.cpp
  lib/Driver/ToolChains/OpenBSD.cpp
  lib/Driver/ToolChains/PS4CPU.cpp
  lib/Driver/ToolChains/Solaris.cpp
  lib/Driver/ToolChains/WebAssembly.cpp
  test/Driver/nostdlibxx.cpp

Index: test/Driver/nostdlibxx.cpp
===
--- test/Driver/nostdlibxx.cpp
+++ test/Driver/nostdlibxx.cpp
@@ -0,0 +1,8 @@
+// RUN: %clangxx -target i686-pc-linux-gnu -### -nostdlib++ %s 2> %t
+// RUN: FileCheck < %t %s
+
+// We should still have -lm and the C standard libraries, but not -lstdc++.
+
+// CHECK-NOT: -lstdc++
+// CHECK-NOT: -lc++
+// CHECK: -lm
Index: include/clang/Driver/ToolChain.h
===
--- include/clang/Driver/ToolChain.h
+++ include/clang/Driver/ToolChain.h
@@ -432,6 +432,10 @@
   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const;
 
+  /// Returns if the C++ standard library should be linked in.
+  /// Note that e.g. -lm should still be linked even if this returns false.
+  bool ShouldLinkCXXStdlib(const llvm::opt::ArgList ) const;
+
   /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use
   /// for the given C++ standard library type.
   virtual void AddCXXStdlibLibArgs(const llvm::opt::ArgList ,
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -2138,6 +2138,7 @@
 def nostdincxx : Flag<["-"], "nostdinc++">, Flags<[CC1Option]>,
   HelpText<"Disable standard #include directories for the C++ standard library">;
 def nostdlib : Flag<["-"], "nostdlib">;
+def nostdlibxx : Flag<["-"], "nostdlib++">;
 def object : Flag<["-"], "object">;
 def o : JoinedOrSeparate<["-"], "o">, Flags<[DriverOption, RenderAsInput, CC1Option, CC1AsOption]>,
   HelpText<"Write output to ">, MetaVarName<"">;
Index: lib/Driver/ToolChains/WebAssembly.cpp
===
--- lib/Driver/ToolChains/WebAssembly.cpp
+++ lib/Driver/ToolChains/WebAssembly.cpp
@@ -38,7 +38,6 @@
 const char *LinkingOutput) const {
 
   const ToolChain  = getToolChain();
-  const Driver  = ToolChain.getDriver();
   const char *Linker = Args.MakeArgString(ToolChain.GetLinkerPath());
   ArgStringList CmdArgs;
   CmdArgs.push_back("-flavor");
@@ -77,7 +76,7 @@
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
-if (D.CCCIsCXX())
+if (ToolChain.ShouldLinkCXXStdlib(Args))
   ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
 
 if (Args.hasArg(options::OPT_pthread))
Index: lib/Driver/ToolChains/Solaris.cpp
===
--- lib/Driver/ToolChains/Solaris.cpp
+++ lib/Driver/ToolChains/Solaris.cpp
@@ -100,7 +100,7 @@
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
-if (getToolChain().getDriver().CCCIsCXX())
+if (getToolChain().ShouldLinkCXXStdlib(Args))
   getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
 CmdArgs.push_back("-lgcc_s");
 CmdArgs.push_back("-lc");
Index: lib/Driver/ToolChains/PS4CPU.cpp
===
--- lib/Driver/ToolChains/PS4CPU.cpp
+++ lib/Driver/ToolChains/PS4CPU.cpp
@@ -227,7 +227,8 @@
 // libraries for both C and C++ compilations.
 CmdArgs.push_back("-lkernel");
 if (D.CCCIsCXX()) {
-  ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
+  if (ToolChain.ShouldLinkCXXStdlib(Args))
+

r308848 - Remove Driver::UseStdLib.

2017-07-23 Thread Nico Weber via cfe-commits
Author: nico
Date: Sun Jul 23 09:31:47 2017
New Revision: 308848

URL: http://llvm.org/viewvc/llvm-project?rev=308848=rev
Log:
Remove Driver::UseStdLib.

All but one place are checking options::OPT_nostdlib instead of looking at
this field, so convert that one other place to doing that as well.

No behavior change.

Modified:
cfe/trunk/include/clang/Driver/Driver.h
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp

Modified: cfe/trunk/include/clang/Driver/Driver.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Driver.h?rev=308848=308847=308848=diff
==
--- cfe/trunk/include/clang/Driver/Driver.h (original)
+++ cfe/trunk/include/clang/Driver/Driver.h Sun Jul 23 09:31:47 2017
@@ -148,9 +148,6 @@ public:
   /// Dynamic loader prefix, if present
   std::string DyldPrefix;
 
-  /// If the standard library is used
-  bool UseStdLib;
-
   /// Driver title to use with help.
   std::string DriverTitle;
 

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=308848=308847=308848=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Sun Jul 23 09:31:47 2017
@@ -87,7 +87,7 @@ Driver::Driver(StringRef ClangExecutable
 : Opts(createDriverOptTable()), Diags(Diags), VFS(std::move(VFS)),
   Mode(GCCMode), SaveTemps(SaveTempsNone), BitcodeEmbed(EmbedNone),
   LTOMode(LTOK_None), ClangExecutable(ClangExecutable),
-  SysRoot(DEFAULT_SYSROOT), UseStdLib(true),
+  SysRoot(DEFAULT_SYSROOT), 
   DriverTitle("clang LLVM compiler"), CCPrintOptionsFilename(nullptr),
   CCPrintHeadersFilename(nullptr), CCLogDiagnosticsFilename(nullptr),
   CCCPrintBindings(false), CCPrintHeaders(false), CCLogDiagnostics(false),
@@ -678,8 +678,6 @@ Compilation *Driver::BuildCompilation(Ar
 SysRoot = A->getValue();
   if (const Arg *A = Args.getLastArg(options::OPT__dyld_prefix_EQ))
 DyldPrefix = A->getValue();
-  if (Args.hasArg(options::OPT_nostdlib))
-UseStdLib = false;
 
   if (const Arg *A = Args.getLastArg(options::OPT_resource_dir))
 ResourceDir = A->getValue();

Modified: cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp?rev=308848=308847=308848=diff
==
--- cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp Sun Jul 23 09:31:47 2017
@@ -324,7 +324,7 @@ void netbsd::Linker::ConstructJob(Compil
 
 NetBSD::NetBSD(const Driver , const llvm::Triple , const ArgList 
)
 : Generic_ELF(D, Triple, Args) {
-  if (getDriver().UseStdLib) {
+  if (!Args.hasArg(options::OPT_nostdlib)) {
 // When targeting a 32-bit platform, try the special directory used on
 // 64-bit hosts, and only fall back to the main library directory if that
 // doesn't work.


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


[PATCH] D35776: clang/Basic/TargetInfo.h: Sink llvm/IR/DataLayout.h into implementations.

2017-07-23 Thread NAKAMURA Takumi via Phabricator via cfe-commits
chapuni created this revision.
Herald added a subscriber: nhaehnle.

It loosens dependencies of Clang_Basic from LLVM_intrinsic.


Repository:
  rL LLVM

https://reviews.llvm.org/D35776

Files:
  cfe/trunk/include/clang/Basic/TargetInfo.h
  cfe/trunk/lib/AST/Mangle.cpp
  cfe/trunk/lib/Basic/TargetInfo.cpp
  cfe/trunk/lib/Basic/Targets/AMDGPU.cpp
  cfe/trunk/lib/Frontend/InitPreprocessor.cpp


Index: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
===
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp
@@ -25,6 +25,7 @@
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Serialization/ASTReader.h"
 #include "llvm/ADT/APFloat.h"
+#include "llvm/IR/DataLayout.h"
 using namespace clang;
 
 static bool MacroBodyEndsInBackslash(StringRef MacroBody) {
Index: cfe/trunk/lib/Basic/Targets/AMDGPU.cpp
===
--- cfe/trunk/lib/Basic/Targets/AMDGPU.cpp
+++ cfe/trunk/lib/Basic/Targets/AMDGPU.cpp
@@ -18,6 +18,7 @@
 #include "clang/Basic/TargetBuiltins.h"
 #include "clang/Frontend/CodeGenOptions.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/IR/DataLayout.h"
 
 using namespace clang;
 using namespace clang::targets;
Index: cfe/trunk/lib/Basic/TargetInfo.cpp
===
--- cfe/trunk/lib/Basic/TargetInfo.cpp
+++ cfe/trunk/lib/Basic/TargetInfo.cpp
@@ -17,6 +17,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/IR/DataLayout.h"
 #include "llvm/Support/ErrorHandling.h"
 #include 
 using namespace clang;
@@ -112,6 +113,10 @@
 // Out of line virtual dtor for TargetInfo.
 TargetInfo::~TargetInfo() {}
 
+void TargetInfo::resetDataLayout(StringRef DL) {
+  DataLayout.reset(new llvm::DataLayout(DL));
+}
+
 /// getTypeName - Return the user string for the specified integer type enum.
 /// For example, SignedShort -> "short".
 const char *TargetInfo::getTypeName(IntType T) {
Index: cfe/trunk/lib/AST/Mangle.cpp
===
--- cfe/trunk/lib/AST/Mangle.cpp
+++ cfe/trunk/lib/AST/Mangle.cpp
@@ -22,6 +22,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/IR/DataLayout.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
 
Index: cfe/trunk/include/clang/Basic/TargetInfo.h
===
--- cfe/trunk/include/clang/Basic/TargetInfo.h
+++ cfe/trunk/include/clang/Basic/TargetInfo.h
@@ -21,21 +21,22 @@
 #include "clang/Basic/TargetCXXABI.h"
 #include "clang/Basic/TargetOptions.h"
 #include "clang/Basic/VersionTuple.h"
+#include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APInt.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Triple.h"
-#include "llvm/IR/DataLayout.h"
 #include "llvm/Support/DataTypes.h"
 #include 
 #include 
 #include 
 
 namespace llvm {
-struct fltSemantics;
+class DataLayout;
 }
 
 namespace clang {
@@ -101,9 +102,7 @@
   // TargetInfo Constructor.  Default initializes all fields.
   TargetInfo(const llvm::Triple );
 
-  void resetDataLayout(StringRef DL) {
-DataLayout.reset(new llvm::DataLayout(DL));
-  }
+  void resetDataLayout(StringRef DL);
 
 public:
   /// \brief Construct a target for the given options.


Index: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
===
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp
@@ -25,6 +25,7 @@
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Serialization/ASTReader.h"
 #include "llvm/ADT/APFloat.h"
+#include "llvm/IR/DataLayout.h"
 using namespace clang;
 
 static bool MacroBodyEndsInBackslash(StringRef MacroBody) {
Index: cfe/trunk/lib/Basic/Targets/AMDGPU.cpp
===
--- cfe/trunk/lib/Basic/Targets/AMDGPU.cpp
+++ cfe/trunk/lib/Basic/Targets/AMDGPU.cpp
@@ -18,6 +18,7 @@
 #include "clang/Basic/TargetBuiltins.h"
 #include "clang/Frontend/CodeGenOptions.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/IR/DataLayout.h"
 
 using namespace clang;
 using namespace clang::targets;
Index: cfe/trunk/lib/Basic/TargetInfo.cpp
===
--- cfe/trunk/lib/Basic/TargetInfo.cpp
+++ cfe/trunk/lib/Basic/TargetInfo.cpp
@@ -17,6 +17,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/IR/DataLayout.h"
 #include "llvm/Support/ErrorHandling.h"
 #include 
 using namespace clang;
@@ -112,6 +113,10 @@

[PATCH] D26587: [AVX512][inline-asm] Fix AVX512 inline assembly instruction resolution when the size qualifier of a memory operand is not specified explicitly.

2017-07-23 Thread coby via Phabricator via cfe-commits
coby abandoned this revision.
coby added a comment.

superseded by https://reviews.llvm.org/rL302179


Repository:
  rL LLVM

https://reviews.llvm.org/D26587



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


[PATCH] D35718: [clang-tidy] Do not issue fixit for explicit template specializations

2017-07-23 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG. Thanks!


https://reviews.llvm.org/D35718



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


[PATCH] D35775: [x86][inline-asm]Extend support for memory reference expression

2017-07-23 Thread coby via Phabricator via cfe-commits
coby created this revision.
Herald added a subscriber: eraman.

Extend support for expressions which represent a variable access in ms-style 
inline-asm, to allow the incorporation of both registers and variables.
Currently, expression such as '//__asm mov eax, [var + eax]//' would have been 
reduced to the (equivalent of) '//__asm mov eax, [eax]//'
This patch amends it
llvm counterpart: https://reviews.llvm.org/D35774


Repository:
  rL LLVM

https://reviews.llvm.org/D35775

Files:
  lib/Sema/SemaStmtAsm.cpp
  test/CodeGen/ms-inline-asm-indirect-memory-ref.c
  test/CodeGen/ms-inline-asm.c
  test/Sema/ms-inline-asm.c


Index: lib/Sema/SemaStmtAsm.cpp
===
--- lib/Sema/SemaStmtAsm.cpp
+++ lib/Sema/SemaStmtAsm.cpp
@@ -665,8 +665,12 @@
   fillInlineAsmTypeInfo(Context, T, Info);
 
   // We can work with the expression as long as it's not an r-value.
-  if (!Result.get()->isRValue())
+  if (!Result.get()->isRValue()) {
 Info.IsVarDecl = true;
+Expr::EvalResult Eval;
+if (Result.get()->EvaluateAsLValue(Eval, Context))
+  Info.IsGlobalLV = Eval.isGlobalLValue();
+  }
 
   return Result;
 }
Index: test/CodeGen/ms-inline-asm.c
===
--- test/CodeGen/ms-inline-asm.c
+++ test/CodeGen/ms-inline-asm.c
@@ -515,7 +515,7 @@
   __asm { mov eax, 4*(4-2)[64 + arr - 2*32] }
 // CHECK: call void asm sideeffect inteldialect "mov eax, $$8$0", 
"*m,~{eax},~{dirflag},~{fpsr},~{flags}"([4 x i32]* %{{.*}})
   __asm { mov eax, 32*(4-2)[arr - 2*32] }
-// CHECK: call void asm sideeffect inteldialect "mov eax, $$0$0", 
"*m,~{eax},~{dirflag},~{fpsr},~{flags}"([4 x i32]* %{{.*}})
+// CHECK: call void asm sideeffect inteldialect "mov eax, $0", 
"*m,~{eax},~{dirflag},~{fpsr},~{flags}"([4 x i32]* %{{.*}})
 }
 
 void cpuid() {
Index: test/CodeGen/ms-inline-asm-indirect-memory-ref.c
===
--- test/CodeGen/ms-inline-asm-indirect-memory-ref.c
+++ test/CodeGen/ms-inline-asm-indirect-memory-ref.c
@@ -0,0 +1,36 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 %s -fasm-blocks -triple x86_64-unknown-linux-gnu -emit-llvm 
-o - | FileCheck %s
+
+int gVar;
+
+void t1() {
+  // CHECK: add eax, dword ptr gVar[eax]
+  __asm add eax, dword ptr gVar[eax]
+  // CHECK: add dword ptr gVar[eax], eax
+  __asm add dword ptr [eax+gVar], eax
+  // CHECK: add ebx, dword ptr gVar[ebx + $$270]
+  __asm add ebx, dword ptr gVar[271 - 82 + 81 + ebx]
+  // CHECK: add dword ptr gVar[ebx + $$828], ebx
+  __asm add dword ptr [ebx + gVar + 828], ebx
+  // CHECK: add ecx, dword ptr gVar[ecx + ecx * $$4 + $$4590]
+  __asm add ecx, dword ptr gVar[4590 + ecx + ecx*4]
+  // CHECK: add dword ptr gVar[ecx + ecx * $$8 + $$73], ecx
+  __asm add dword ptr [gVar + ecx + 45 + 23 - 53 + 60 - 2 + ecx*8], ecx
+  // CHECK: add gVar[ecx + ebx + $$7], eax
+  __asm add 1 + 1 + 2 + 3[gVar + ecx + ebx], eax
+}
+
+void t2() {
+  int lVar;
+  // CHECK: mov eax, dword ptr ${{[0-9]}}[eax]
+  __asm mov eax, dword ptr lVar[eax]
+  // CHECK: mov dword ptr ${{[0-9]}}[eax], eax
+  __asm mov dword ptr [eax+lVar], eax
+  // CHECK: mov ebx, dword ptr ${{[0-9]}}[ebx + $$270]
+  __asm mov ebx, dword ptr lVar[271 - 82 + 81 + ebx]
+  // CHECK: mov dword ptr ${{[0-9]}}[ebx + $$828], ebx
+  __asm mov dword ptr [ebx + lVar + 828], ebx
+  // CHECK: mov ${{[0-9]}}[ebx + $$47], eax
+  __asm mov 5 + 8 + 13 + 21[lVar + ebx], eax
+}
+
Index: test/Sema/ms-inline-asm.c
===
--- test/Sema/ms-inline-asm.c
+++ test/Sema/ms-inline-asm.c
@@ -59,10 +59,8 @@
 mov eax, arr[1 + (2 * 5) - 3 + 1<<1];
   }
 
-  // expected-error@+1 {{cannot use base register with variable reference}}
-  __asm { mov eax, arr[ebp + 1 + (2 * 5) - 3 + 1<<1] }
-  // expected-error@+1 {{cannot use index register with variable reference}}
-  __asm { mov eax, arr[esi * 4] }
+  // expected-error@+1 {{Can't use a local variable with both base and index 
registers}}
+  __asm { mov eax, [i + eax + ebx] }
   // expected-error@+1 {{cannot use more than one symbol in memory operand}}
   __asm { mov eax, arr[i] }
   // expected-error@+1 {{cannot use more than one symbol in memory operand}}


Index: lib/Sema/SemaStmtAsm.cpp
===
--- lib/Sema/SemaStmtAsm.cpp
+++ lib/Sema/SemaStmtAsm.cpp
@@ -665,8 +665,12 @@
   fillInlineAsmTypeInfo(Context, T, Info);
 
   // We can work with the expression as long as it's not an r-value.
-  if (!Result.get()->isRValue())
+  if (!Result.get()->isRValue()) {
 Info.IsVarDecl = true;
+Expr::EvalResult Eval;
+if (Result.get()->EvaluateAsLValue(Eval, Context))
+  Info.IsGlobalLV = Eval.isGlobalLValue();
+  }
 
   return Result;
 }
Index: test/CodeGen/ms-inline-asm.c
===
--- test/CodeGen/ms-inline-asm.c
+++ 

[PATCH] D21767: Fix instantiation of friend function templates

2017-07-23 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 107817.
sepavloff added a comment.

Reworked patch

Used more general way to cope with calculation of instantiation
stack, which is suitable for cases represented in PR26512.

Added new tests.


https://reviews.llvm.org/D21767

Files:
  include/clang/AST/ASTLambda.h
  include/clang/AST/Decl.h
  include/clang/Sema/Sema.h
  lib/AST/Decl.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/SemaTemplate/instantiate-friend-function.cpp

Index: test/SemaTemplate/instantiate-friend-function.cpp
===
--- /dev/null
+++ test/SemaTemplate/instantiate-friend-function.cpp
@@ -0,0 +1,560 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -S -triple %itanium_abi_triple -std=c++11 -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+
+// Instantiate friend function, pattern is at file level.
+
+
+template struct C01 {
+  template friend void func_01(C01 &, T1);
+  template friend void func_01a(C01 &, T2);
+};
+
+C01 c01;
+
+void f_01() {
+  func_01(c01, 0.0);
+  func_01a(c01, 0.0);
+}
+
+template void func_01(C01 &, T1) {}
+template void func_01a(C01 &, T2) {}
+
+// void func_01(C01&, double)
+// CHECK: define linkonce_odr void @_Z7func_01IdEvR3C01IiET_
+//
+// void func_01a(C01&, double)
+// CHECK: define linkonce_odr void @_Z8func_01aIidEvR3C01IT_ET0_
+
+
+template struct C02 {
+  template friend void func_02(const C02 &, T1) { T var; }
+  template friend void func_02a(const C02 &, T2) { T var; }
+  template friend constexpr unsigned func_02b(const C02 &, const T1 x) { return sizeof(T1); }
+};
+
+const C02 c02;
+
+void f_02() {
+  func_02(c02, 0.0);
+  func_02a(c02, 0.0);
+  static_assert(func_02b(c02, short(122)) == sizeof(short), "Invalid calculation");
+  static_assert(func_02b(c02, 122L) == sizeof(long), "Invalid calculation");
+}
+
+// void func_02(C02 const&, double)
+// CHECK: define linkonce_odr void @_Z7func_02IdEvRK3C02IiET_
+//
+// void func_02a(C02 const&, double)
+// CHECK: define linkonce_odr void @_Z8func_02aIidEvRK3C02IT_ET0_
+
+
+template struct C03 {
+  template friend void func_03(C03 &, T1);
+  template friend void func_03a(C03 &, T2);
+};
+
+C03 c03;
+
+void f_03() {
+  func_03(c03, 0.0);
+  func_03a(c03, 0.0);
+}
+
+template struct C03A {
+  template friend void func_03(C03 &, T1) { }
+};
+template struct C03B {
+  template friend void func_03a(C03 &, T2) { T var; }
+};
+
+C03A c03a;
+C03B c03b;
+
+// void func_03(C03&, double)
+// CHECK: define linkonce_odr void @_Z7func_03IdEvR3C03IiET_  
+//
+// void func_03a(C03&, double)
+// CHECK: define linkonce_odr void @_Z8func_03aIidEvR3C03IT_ET0_
+
+
+// File level declaration, friend pattern.
+
+
+template void func_10(T1 *x);
+template void func_10a(T1 *x, T2 *y);
+template constexpr unsigned func_10b(const T1 x);
+template constexpr unsigned func_10c(const T1 x);
+
+template
+struct C10 {
+  template friend void func_10(T1 *x) { T var; }
+  template friend void func_10a(T1 *x, T2 *y) { T var; }
+  template friend constexpr unsigned func_10b(const T1 x) { return sizeof(T1); }
+  template friend constexpr unsigned func_10c(const T1 x) { return sizeof(T); }
+};
+
+C10 v10;
+
+void use_10(int *x) {
+  func_10(x);
+  func_10a(x, );
+  static_assert(func_10b(short(122)) == sizeof(short), "Invalid calculation");
+  static_assert(func_10b(122L) == sizeof(long), "Invalid calculation");
+  static_assert(func_10c(short(122)) == sizeof(int), "Invalid calculation");
+  static_assert(func_10c(122L) == sizeof(int), "Invalid calculation");
+}
+
+// void func_10(int*)
+// CHECK: define linkonce_odr void @_Z7func_10IiEvPT_
+//
+// void func_10a(int*, int**)
+// CHECK: define linkonce_odr void @_Z8func_10aIiPiEvPT_PT0_
+
+
+template
+struct C11 {
+  template friend void func_11(T1 *x) { T var; }
+  template friend void func_11a(T1 *x, T2 *y) { T var; }
+  template friend constexpr unsigned func_11b(const T1 x) { return sizeof(T1); }
+  template friend constexpr unsigned func_11c(const T1 x) { return sizeof(T); }
+};
+
+C11 v11;
+
+template void func_11(T *x);
+template void func_11a(T1 *x, T2 *y);
+template constexpr unsigned func_11b(const T1 x);
+template constexpr unsigned func_11c(const T1 x);
+
+void use_11(int *x) {
+  func_11(x);
+  func_11a(x, );
+  static_assert(func_11b(short(123)) == sizeof(short), "Invalid calculation");
+  static_assert(func_11b(123L) == sizeof(long), "Invalid calculation");
+  static_assert(func_11c(short(123)) == sizeof(int), "Invalid calculation");
+  static_assert(func_11c(123L) == sizeof(int), "Invalid calculation");
+}
+
+// void func_11(int*)
+// CHECK: define linkonce_odr void @_Z7func_11IiEvPT_
+//
+// void func_11a(int*, int**)
+// CHECK: define linkonce_odr void @_Z8func_11aIiPiEvPT_PT0_
+
+
+template
+struct C12 {
+  template friend void func_12(T1 *x) { T var; }
+  template friend void