[PATCH] D30810: Preserve vec3 type.

2017-03-15 Thread JinGu Kang via Phabricator via cfe-commits
jaykang10 added a comment.



> I believe the assumption is more practical: most part of upstream llvm 
> targets only support vectors with even sized number of lanes. And in those 
> cases you would have to expand to a 4x vector and leave the 4th element as 
> undef anyway, so it was done in the front-end to get rid of it right away. 
> Probably GPU targets do some special tricks here during legalization.

I have compiled below code, which current clang generates for vec3,  using llc 
with amdgcn target.

LLVM IR (vec3 --> vec4)

  define void @foo(<3 x float>* nocapture %a, <3 x float>* nocapture readonly 
%b) {
  entry:
%castToVec4 = bitcast <3 x float>* %b to <4 x float>*
%loadVec4 = load <4 x float>, <4 x float>* %castToVec4, align 16
%storetmp = bitcast <3 x float>* %a to <4 x float>*
store <4 x float> %loadVec4, <4 x float>* %storetmp, align 16
ret void
  }

SelectionDAG after legalization.

  Legalized selection DAG: BB#0 'foo:entry'
  SelectionDAG has 43 nodes:
t0: ch = EntryToken
t2: i64,ch = CopyFromReg t0, Register:i64 %vreg0
  t9: i64 = add t2, Constant:i64<40>
t10: i32,ch = 
load t0, t9, 
undef:i64
  t4: i64 = add t2, Constant:i64<36>
t6: i32,ch = 
load t0, t4, 
undef:i64
t12: ch = TokenFactor t6:1, t10:1
t32: v4i32 = BUILD_VECTOR t22, t25, t27, t29
  t21: v4f32 = bitcast t32
t18: v4i32 = bitcast t21
t22: i32,ch = load t12, t10, undef:i32
t24: i32 = add t10, Constant:i32<4>
t25: i32,ch = load t12, t24, undef:i32
t26: i32 = add t24, Constant:i32<4>
t27: i32,ch = load t12, t26, undef:i32
  t28: i32 = add t26, Constant:i32<4>
t29: i32,ch = load t12, t28, undef:i32
t31: ch = TokenFactor t22:1, t25:1, t27:1, t29:1
  t35: i32 = extract_vector_elt t18, Constant:i32<0>
t36: ch = store t31, t35, t6, undef:i32
  t38: i32 = extract_vector_elt t18, Constant:i32<1>
  t39: i32 = add t6, Constant:i32<4>
t40: ch = store t31, t38, t39, undef:i32
  t42: i32 = extract_vector_elt t18, Constant:i32<2>
  t44: i32 = add t6, Constant:i32<8>
t45: ch = store t31, t42, t44, undef:i32
  t47: i32 = extract_vector_elt t18, Constant:i32<3>
  t49: i32 = add t6, Constant:i32<12>
t50: ch = store t31, t47, t49, undef:i32
  t51: ch = TokenFactor t36, t40, t45, t50
t17: ch = ENDPGM t51

As you can see, the SelectionDAG still has 4 load/store.

Assembly output

.section.AMDGPU.config
.long   47176
.long   11272257
.long   47180
.long   132
.long   47200
.long   0
.long   4
.long   0
.long   8
.long   0
.text
.globl  foo
.p2align8
.type   foo,@function
  foo:; @foo
  ; BB#0: ; %entry
s_load_dword s2, s[0:1], 0x9
s_load_dword s0, s[0:1], 0xa
s_mov_b32 s4, SCRATCH_RSRC_DWORD0
s_mov_b32 s5, SCRATCH_RSRC_DWORD1
s_mov_b32 s6, -1
s_mov_b32 s8, s3
s_mov_b32 s7, 0xe8f000
s_waitcnt lgkmcnt(0)
v_mov_b32_e32 v0, s0
buffer_load_dword v2, v0, s[4:7], s8 offen
buffer_load_dword v3, v0, s[4:7], s8 offen offset:4
buffer_load_dword v4, v0, s[4:7], s8 offen offset:8
buffer_load_dword v0, v0, s[4:7], s8 offen offset:12
v_mov_b32_e32 v1, s2
s_waitcnt vmcnt(0)
buffer_store_dword v0, v1, s[4:7], s8 offen offset:12
buffer_store_dword v4, v1, s[4:7], s8 offen offset:8
buffer_store_dword v3, v1, s[4:7], s8 offen offset:4
buffer_store_dword v2, v1, s[4:7], s8 offen
s_endpgm
  .Lfunc_end0:
.size   foo, .Lfunc_end0-foo
  
.section.AMDGPU.csdata

As you can see, assembly also has 4 load/store. I think gpu target does not 
handle it specially.

> My guess here is that targets that do care are looking through the vector 
> shuffle and customizing to whatever seems the best to them. If you wanna 
> change the default behavior you need some data to show that your model solves 
> a real issue and actually brings benefits; do you have any real examples on 
> where that happens, or why GPU targets haven't yet tried to change this? 
> Maybe other custom front-ends based on clang do? Finding the historical 
> reason (if any) should be a good start point.

I did "git blame" and I read the commit's message. You can also see it with 
"c58dcdc8facb646d88675bb6fbcb5c787166c4be". It is same with clang code's 
comment. I also wonder how the vec3 --> vec4 load/store has not caused 
problems. As Akira's example, if struct type has float3 type as one of fields 
and it has 'packed' attribute, it overwrites next field. The vec3 load/store 
generates more instructions like stores and extract_vectors like below 
SelectionDAG.

LLVM IR for vec3

  define void @foo(<3 x float>* nocapture %a, <3 x float>* nocapture 

[PATCH] D30295: [analyzer] clarify undef shift result when shift count is negative or exceeds the bit width

2017-03-15 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki added a comment.

Ping


Repository:
  rL LLVM

https://reviews.llvm.org/D30295



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


[PATCH] D30295: [analyzer] clarify undef shift result when shift count is negative or exceeds the bit width

2017-03-15 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added a comment.

Hello Daniel,
Your patch looks mostly good to me. I have only minor naming comments.




Comment at: lib/StaticAnalyzer/Core/CheckerHelpers.cpp:99
+bool clang::ento::isExprResultConformsComparisonRule(CheckerContext &C,
+ BinaryOperatorKind BOK,
+ const Expr *LExpr,

CompRule?



Comment at: lib/StaticAnalyzer/Core/CheckerHelpers.cpp:100
+ BinaryOperatorKind BOK,
+ const Expr *LExpr,
+ const SVal RVal) {

I think we should rename these variables to LHSExpr, RHSVal, LHSVal. I don't 
like LVal/RVal because they may be associated with rvalue/lvalue types which is 
not what we want.


Repository:
  rL LLVM

https://reviews.llvm.org/D30295



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


[PATCH] D28136: [OpenCL] Implement as_type operator as alias of __builtin_astype.

2017-03-15 Thread Alexey Bader via Phabricator via cfe-commits
bader added a comment.

> From all the above arguments, I feel like the right approach would be to 
> implement it as Clang builtin which closely matches the operator semantic in 
> my opinion. We could of course reuse the implementation of  __bultin_astype 
> to avoid unnecessary extra work and code duplication.
> 
> Using the macro seems to me more like a workaround solution and overloaded 
> functions don't seem to be entirely the right thing either.  What do you 
> think about it?

I don't think we need another Clang built-in. __builtin_astype was added 
specifically for OpenCL needs (see rev. 132612).
Do you know better way to map astype operators (there are a lot of them 
as_#) to single Clang built-in?


https://reviews.llvm.org/D28136



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


[PATCH] D30582: [Driver] Restructure handling of -ffast-math and similar options

2017-03-15 Thread Renato Golin via Phabricator via cfe-commits
rengolin added inline comments.



Comment at: lib/Driver/ToolChains/Clang.cpp:2452
+  if (!HonorInfs && !HonorNans && !MathErrno && AssociativeMath &&
+  ReciprocalMath && !SignedZeros && !TrappingMath && FpContract == "fast")
+CmdArgs.push_back("-ffast-math");

rengolin wrote:
> This is technically correct, but users will be confused if they choose 
> `-ffast-math -ffp-contract=on` and not see `-ffast-math` coming out on the 
> other side.
> 
> Also, `fp-contract=on` doesn't preclude `-ffast-math` for the languages that 
> support it, so I wouldn't add `FpContract` to this list at all.
I've been thinking a bit more about this, and I started wondering, why do we 
even need to pass `-ffast-math` down?

If all the others are already being passed, shouldn't this flag be redundant?

Finally, we could possibly add instead `&& FpContract != "off"`. Would that be 
better?



Comment at: lib/Driver/ToolChains/Clang.cpp:2347
+// Validate and pass through -fp-contract option.
+case options::OPT_ffp_contract: {
+  StringRef Val = A->getValue();

Also, when `-ffast-math` is selected, and `-ffp-contract=on`, we should 
actually change it to `fast`, no?



Comment at: lib/Driver/ToolChains/Clang.cpp:2356
+}
+
+case options::OPT_ffinite_math_only:

Missing break?


Repository:
  rL LLVM

https://reviews.llvm.org/D30582



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


[PATCH] D30977: [CodeGen] Emit a CoreFoundation link guard when @available is used

2017-03-15 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.

After r297760, __isOSVersionAtLeast in compiler-rt loads the CoreFoundation 
symbols at runtime. This means that `@available` will always fail when used in 
a binary without a linked CoreFoundation.

This patch forces Clang to emit a reference to a CoreFoundation symbol when 
`@available` is used to ensure that linking will fail when CoreFoundation isn't 
linked with the build product.


Repository:
  rL LLVM

https://reviews.llvm.org/D30977

Files:
  lib/CodeGen/CGObjC.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  test/CodeGenObjC/availability-cf-link-guard.m

Index: test/CodeGenObjC/availability-cf-link-guard.m
===
--- /dev/null
+++ test/CodeGenObjC/availability-cf-link-guard.m
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.11 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.11 -emit-llvm -o - -D USE_BUILTIN %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.11 -emit-llvm -o - -D DEF_CF %s | FileCheck --check-prefix=CHECK_CF %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.12 -emit-llvm -o - %s | FileCheck --check-prefix=CHECK_NO_GUARD %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -emit-llvm -o - %s | FileCheck --check-prefix=CHECK_NO_GUARD %s
+
+#ifdef DEF_CF
+struct CFBundle;
+typedef struct CFBundle *CFBundleRef;
+unsigned CFBundleGetVersionNumber(CFBundleRef bundle);
+// CHECK_CF: declare i32 @CFBundleGetVersionNumber(%struct.CFBundle*)
+// CHECK_CF: @__clang_at_available_requires_core_foundation_framework
+// CHECK_CF-NEXT: call {{.*}}@CFBundleGetVersionNumber
+#endif
+
+void use_at_available() {
+#ifdef DEF_CF
+  CFBundleGetVersionNumber(0);
+#endif
+#ifdef USE_BUILTIN
+  if (__builtin_available(macos 10.12, *))
+;
+#else
+  if (@available(macos 10.12, *))
+;
+#endif
+}
+
+// CHECK: @llvm.compiler.used{{.*}}@__clang_at_available_requires_core_foundation_framework
+
+// CHECK: declare i32 @CFBundleGetVersionNumber(i8*)
+
+// CHECK-LABEL: linkonce void @__clang_at_available_requires_core_foundation_framework
+// CHECK: call i32 @CFBundleGetVersionNumber(i8* null)
+// CHECK-NEXT: unreachable
+
+// CHECK_NO_GUARD-NOT: __clang_at_available_requires_core_foundation_framework
+// CHECK_NO_GUARD-NOT: CFBundleGetVersionNumber
Index: lib/CodeGen/CodeGenModule.h
===
--- lib/CodeGen/CodeGenModule.h
+++ lib/CodeGen/CodeGenModule.h
@@ -1288,6 +1288,10 @@
   /// Emit any vtables which we deferred and still have a use for.
   void EmitDeferredVTables();
 
+  /// Emit a dummy function that reference a CoreFoundation symbol when
+  /// @available is used on Darwin.
+  void emitAtAvailableLinkGuard();
+
   /// Emit the llvm.used and llvm.compiler.used metadata.
   void emitLLVMUsed();
 
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -408,6 +408,7 @@
 CoverageMapping->emit();
   if (CodeGenOpts.SanitizeCfiCrossDso)
 CodeGenFunction(*this).EmitCfiCheckFail();
+  emitAtAvailableLinkGuard();
   emitLLVMUsed();
   if (SanStats)
 SanStats->finish();
Index: lib/CodeGen/CGObjC.cpp
===
--- lib/CodeGen/CGObjC.cpp
+++ lib/CodeGen/CGObjC.cpp
@@ -3416,4 +3416,28 @@
   return Builder.CreateICmpNE(CallRes, llvm::Constant::getNullValue(Int32Ty));
 }
 
+void CodeGenModule::emitAtAvailableLinkGuard() {
+  // @available requires CoreFoundation only on Darwin.
+  if (!Target.getTriple().isOSDarwin())
+return;
+  if (!IsOSVersionAtLeastFn)
+return;
+  // Emit a reference to a symbol from CoreFoundation to ensure that
+  // CoreFoundation is linked into the final binary.
+  llvm::FunctionType *FTy =
+  llvm::FunctionType::get(Int32Ty, {VoidPtrTy}, false);
+  llvm::Constant *CFFunc =
+  CreateRuntimeFunction(FTy, "CFBundleGetVersionNumber");
+
+  llvm::FunctionType *CheckFTy = llvm::FunctionType::get(VoidTy, {}, false);
+  llvm::Function *CFLinkCheckFunc = cast(CreateBuiltinFunction(
+  CheckFTy, "__clang_at_available_requires_core_foundation_framework"));
+  CFLinkCheckFunc->setLinkage(llvm::GlobalValue::LinkOnceAnyLinkage);
+  CodeGenFunction CGF(*this);
+  CGF.Builder.SetInsertPoint(CGF.createBasicBlock("", CFLinkCheckFunc));
+  CGF.EmitNounwindRuntimeCall(CFFunc, llvm::Constant::getNullValue(VoidPtrTy));
+  CGF.Builder.CreateUnreachable();
+  addCompilerUsedGlobal(CFLinkCheckFunc);
+}
+
 CGObjCRuntime::~CGObjCRuntime() {}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D30582: [Driver] Restructure handling of -ffast-math and similar options

2017-03-15 Thread John Brawn via Phabricator via cfe-commits
john.brawn added inline comments.



Comment at: lib/Driver/ToolChains/Clang.cpp:2452
+  if (!HonorInfs && !HonorNans && !MathErrno && AssociativeMath &&
+  ReciprocalMath && !SignedZeros && !TrappingMath && FpContract == "fast")
+CmdArgs.push_back("-ffast-math");

rengolin wrote:
> rengolin wrote:
> > This is technically correct, but users will be confused if they choose 
> > `-ffast-math -ffp-contract=on` and not see `-ffast-math` coming out on the 
> > other side.
> > 
> > Also, `fp-contract=on` doesn't preclude `-ffast-math` for the languages 
> > that support it, so I wouldn't add `FpContract` to this list at all.
> I've been thinking a bit more about this, and I started wondering, why do we 
> even need to pass `-ffast-math` down?
> 
> If all the others are already being passed, shouldn't this flag be redundant?
> 
> Finally, we could possibly add instead `&& FpContract != "off"`. Would that 
> be better?
As the comment above says, -ffast-math enables the __FAST_MATH__ macro.

As to FpContract, going back and checking gcc setting -ffp-contract has no 
effect on whether __FAST_MATH__ is defined so I think just not checking 
FpContract here is correct.



Comment at: lib/Driver/ToolChains/Clang.cpp:2347
+// Validate and pass through -fp-contract option.
+case options::OPT_ffp_contract: {
+  StringRef Val = A->getValue();

rengolin wrote:
> Also, when `-ffast-math` is selected, and `-ffp-contract=on`, we should 
> actually change it to `fast`, no?
Do you mean "clang -ffp-contract=on -ffast-math should set fp-contract to fast" 
or "clang -ffast-math -ffp-contract=on should set fp-contract to fast"? The 
first is already done by the -ffast-math handling below, and I think the second 
is a bad idea because it violates the principle that later command-line options 
have priority over earlier ones.



Comment at: lib/Driver/ToolChains/Clang.cpp:2356
+}
+
+case options::OPT_ffinite_math_only:

rengolin wrote:
> Missing break?
Whoops, will fix.


Repository:
  rL LLVM

https://reviews.llvm.org/D30582



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


[PATCH] D30582: [Driver] Restructure handling of -ffast-math and similar options

2017-03-15 Thread Renato Golin via Phabricator via cfe-commits
rengolin accepted this revision.
rengolin added a comment.
This revision is now accepted and ready to land.

Ok, with the break fix, this looks goof to me. Thanks!




Comment at: lib/Driver/ToolChains/Clang.cpp:2452
+  if (!HonorInfs && !HonorNans && !MathErrno && AssociativeMath &&
+  ReciprocalMath && !SignedZeros && !TrappingMath && FpContract == "fast")
+CmdArgs.push_back("-ffast-math");

john.brawn wrote:
> rengolin wrote:
> > rengolin wrote:
> > > This is technically correct, but users will be confused if they choose 
> > > `-ffast-math -ffp-contract=on` and not see `-ffast-math` coming out on 
> > > the other side.
> > > 
> > > Also, `fp-contract=on` doesn't preclude `-ffast-math` for the languages 
> > > that support it, so I wouldn't add `FpContract` to this list at all.
> > I've been thinking a bit more about this, and I started wondering, why do 
> > we even need to pass `-ffast-math` down?
> > 
> > If all the others are already being passed, shouldn't this flag be 
> > redundant?
> > 
> > Finally, we could possibly add instead `&& FpContract != "off"`. Would that 
> > be better?
> As the comment above says, -ffast-math enables the __FAST_MATH__ macro.
> 
> As to FpContract, going back and checking gcc setting -ffp-contract has no 
> effect on whether __FAST_MATH__ is defined so I think just not checking 
> FpContract here is correct.
Right, makes sense.



Comment at: lib/Driver/ToolChains/Clang.cpp:2347
+// Validate and pass through -fp-contract option.
+case options::OPT_ffp_contract: {
+  StringRef Val = A->getValue();

john.brawn wrote:
> rengolin wrote:
> > Also, when `-ffast-math` is selected, and `-ffp-contract=on`, we should 
> > actually change it to `fast`, no?
> Do you mean "clang -ffp-contract=on -ffast-math should set fp-contract to 
> fast" or "clang -ffast-math -ffp-contract=on should set fp-contract to fast"? 
> The first is already done by the -ffast-math handling below, and I think the 
> second is a bad idea because it violates the principle that later 
> command-line options have priority over earlier ones.
The former is done by overall design, the latter is different to most other 
options because of what "on" means and how it's *not* implemented, meaning 
it'll be effectively "off". Otherwise, I'd completely agree with you.

But that's not a strong point, for me. I'm happy to not have that now and 
involve this into a more general "what does on mean" later on.


Repository:
  rL LLVM

https://reviews.llvm.org/D30582



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


[PATCH] D30739: [OpenMP] "declare simd" for AArch64 Advanced SIMD.

2017-03-15 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli added a comment.

Gentle ping.

Thanks,

Francesco


https://reviews.llvm.org/D30739



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


[PATCH] D30739: [OpenMP] "declare simd" for AArch64 Advanced SIMD.

2017-03-15 Thread Renato Golin via Phabricator via cfe-commits
rengolin added reviewers: Hahnfeld, carlo.bertolli, arpith-jacob.
rengolin added a comment.

Looks ok to me, but I'm not very knowledgeable in that area. Hopefully some 
OpenMP Clang developers I added could give you a more concrete approval. :)




Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:6821
+  ISADataTy ISAData[] = {
+  {'n', 64},  // double-word Advanced SIMD
+  {'n', 128}, // quad-word Advanced SIMD

No f32?


https://reviews.llvm.org/D30739



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


[PATCH] D30739: [OpenMP] "declare simd" for AArch64 Advanced SIMD.

2017-03-15 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli added inline comments.



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:6821
+  ISADataTy ISAData[] = {
+  {'n', 64},  // double-word Advanced SIMD
+  {'n', 128}, // quad-word Advanced SIMD

rengolin wrote:
> No f32?
Sorry, I am not sure to understand what you mean here by f32.

I am considering the double-word registers (64 bits wide) and quad-word 
registers (128 bits wide) that are used in AdvSIMD (NEON) for AArch64 [1].

[1] 
https://developer.arm.com/docs/dui0473/latest/neon-programming/neon-views-of-the-extension-register-bank


https://reviews.llvm.org/D30739



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


[PATCH] D30739: [OpenMP] "declare simd" for AArch64 Advanced SIMD.

2017-03-15 Thread Renato Golin via Phabricator via cfe-commits
rengolin added inline comments.



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:6821
+  ISADataTy ISAData[] = {
+  {'n', 64},  // double-word Advanced SIMD
+  {'n', 128}, // quad-word Advanced SIMD

fpetrogalli wrote:
> rengolin wrote:
> > No f32?
> Sorry, I am not sure to understand what you mean here by f32.
> 
> I am considering the double-word registers (64 bits wide) and quad-word 
> registers (128 bits wide) that are used in AdvSIMD (NEON) for AArch64 [1].
> 
> [1] 
> https://developer.arm.com/docs/dui0473/latest/neon-programming/neon-views-of-the-extension-register-bank
Sorry, I meant S0~Sn, but that's silly, as it's VFP. Ignore me.


https://reviews.llvm.org/D30739



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


[PATCH] D30582: [Driver] Restructure handling of -ffast-math and similar options

2017-03-15 Thread John Brawn via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL297837: [Driver] Restructure handling of -ffast-math and 
similar options (authored by john.brawn).

Changed prior to commit:
  https://reviews.llvm.org/D30582?vs=91745&id=91871#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30582

Files:
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/test/Driver/fast-math.c

Index: cfe/trunk/test/Driver/fast-math.c
===
--- cfe/trunk/test/Driver/fast-math.c
+++ cfe/trunk/test/Driver/fast-math.c
@@ -148,20 +148,31 @@
 //
 // One umbrella flag is *really* weird and also changes the semantics of the
 // program by adding a special preprocessor macro. Check that the frontend flag
-// modeling this semantic change is provided. Also check that the semantic
-// impact remains even if every optimization is disabled.
+// modeling this semantic change is provided. Also check that the flag is not
+// present if any of the optimization is disabled.
 // RUN: %clang -### -ffast-math -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FAST-MATH %s
 // RUN: %clang -### -fno-fast-math -ffast-math -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FAST-MATH %s
-// RUN: %clang -### -ffast-math -fno-finite-math-only \
-// RUN: -fno-unsafe-math-optimizations -fmath-errno -c %s 2>&1 \
+// RUN: %clang -### -funsafe-math-optimizations -ffinite-math-only \
+// RUN: -fno-math-errno -ffp-contract=fast -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FAST-MATH %s
+// RUN: %clang -### -fno-honor-infinities -fno-honor-nans -fno-math-errno \
+// RUN: -fassociative-math -freciprocal-math -fno-signed-zeros \
+// RUN: -fno-trapping-math -ffp-contract=fast -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FAST-MATH %s
 // CHECK-FAST-MATH: "-cc1"
 // CHECK-FAST-MATH: "-ffast-math"
+// CHECK-FAST-MATH: "-ffinite-math-only"
 //
 // RUN: %clang -### -ffast-math -fno-fast-math -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH %s
+// RUN: %clang -### -ffast-math -fno-finite-math-only -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH %s
+// RUN: %clang -### -ffast-math -fno-unsafe-math-optimizations -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH %s
+// RUN: %clang -### -ffast-math -fmath-errno -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH %s
 // CHECK-NO-FAST-MATH: "-cc1"
 // CHECK-NO-FAST-MATH-NOT: "-ffast-math"
 //
@@ -179,6 +190,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-INFS %s
 // CHECK-NO-NO-INFS: "-cc1"
 // CHECK-NO-NO-INFS-NOT: "-menable-no-infs"
+// CHECK-NO-NO-INFS-NOT: "-ffinite-math-only"
 // CHECK-NO-NO-INFS: "-o"
 //
 // RUN: %clang -### -fno-honor-nans -fhonor-nans -c %s 2>&1 \
@@ -193,6 +205,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-NO-NO-NANS %s
 // CHECK-NO-NO-NANS: "-cc1"
 // CHECK-NO-NO-NANS-NOT: "-menable-no-nans"
+// CHECK-NO-NO-NANS-NOT: "-ffinite-math-only"
 // CHECK-NO-NO-NANS: "-o"
 //
 // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \
Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -2301,98 +2301,129 @@
   if (Args.hasArg(options::OPT_fsplit_stack))
 CmdArgs.push_back("-split-stacks");
 
-  // If -Ofast is the optimization level, then -ffast-math should be enabled.
-  // This alias option is being used to simplify the getLastArg logic.
-  OptSpecifier FastMathAliasOption =
-  OFastEnabled ? options::OPT_Ofast : options::OPT_ffast_math;
-
   // Handle various floating point optimization flags, mapping them to the
-  // appropriate LLVM code generation flags. The pattern for all of these is to
-  // default off the codegen optimizations, and if any flag enables them and no
-  // flag disables them after the flag enabling them, enable the codegen
-  // optimization. This is complicated by several "umbrella" flags.
-  if (Arg *A = Args.getLastArg(
-  options::OPT_ffast_math, FastMathAliasOption,
-  options::OPT_fno_fast_math, options::OPT_ffinite_math_only,
-  options::OPT_fno_finite_math_only, options::OPT_fhonor_infinities,
-  options::OPT_fno_honor_infinities))
-if (A->getOption().getID() != options::OPT_fno_fast_math &&
-A->getOption().getID() != options::OPT_fno_finite_math_only &&
-A->getOption().getID() != options::OPT_fhonor_infinities)
-  CmdArgs.push_back("-menable-no-infs");
-  if (Arg *A = Args.getLastArg(
-  options::OPT_ffast_math, FastMathAliasOption,
-  options::OPT_fno_fast_math, options::OPT_ffinite_math_only,
-  options::OPT_fno_finite_math_only, options::OPT_fhonor_nans,
-  options::OPT_fno_honor_nans))
-if (A->getOption().getID() != options::OPT_fno_fast_math &&
-   

r297837 - [Driver] Restructure handling of -ffast-math and similar options

2017-03-15 Thread John Brawn via cfe-commits
Author: john.brawn
Date: Wed Mar 15 09:03:32 2017
New Revision: 297837

URL: http://llvm.org/viewvc/llvm-project?rev=297837&view=rev
Log:
[Driver] Restructure handling of -ffast-math and similar options

The way -ffast-math and the various related options to tweak floating-point
handling are handled is inflexible and rather confusing. This patch restructures
things so that we go through the options adjusting our idea of what's enabled as
we go, instead of trying to figure each individual thing out by working
backwards from the end, as this makes the behaviour of each individual option
more clear.

Doing it this way also means we get gcc-compatible behaviour for when the
__FAST_MATH__ and __FINITE_MATH_ONLY__ macros are defined, as they should depend
on the final set of features that are enabled and not just on -ffast-math and
-ffinite-math-only specifically.

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

Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Driver/fast-math.c

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=297837&r1=297836&r2=297837&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Wed Mar 15 09:03:32 2017
@@ -2301,98 +2301,129 @@ void Clang::ConstructJob(Compilation &C,
   if (Args.hasArg(options::OPT_fsplit_stack))
 CmdArgs.push_back("-split-stacks");
 
-  // If -Ofast is the optimization level, then -ffast-math should be enabled.
-  // This alias option is being used to simplify the getLastArg logic.
-  OptSpecifier FastMathAliasOption =
-  OFastEnabled ? options::OPT_Ofast : options::OPT_ffast_math;
-
   // Handle various floating point optimization flags, mapping them to the
-  // appropriate LLVM code generation flags. The pattern for all of these is to
-  // default off the codegen optimizations, and if any flag enables them and no
-  // flag disables them after the flag enabling them, enable the codegen
-  // optimization. This is complicated by several "umbrella" flags.
-  if (Arg *A = Args.getLastArg(
-  options::OPT_ffast_math, FastMathAliasOption,
-  options::OPT_fno_fast_math, options::OPT_ffinite_math_only,
-  options::OPT_fno_finite_math_only, options::OPT_fhonor_infinities,
-  options::OPT_fno_honor_infinities))
-if (A->getOption().getID() != options::OPT_fno_fast_math &&
-A->getOption().getID() != options::OPT_fno_finite_math_only &&
-A->getOption().getID() != options::OPT_fhonor_infinities)
-  CmdArgs.push_back("-menable-no-infs");
-  if (Arg *A = Args.getLastArg(
-  options::OPT_ffast_math, FastMathAliasOption,
-  options::OPT_fno_fast_math, options::OPT_ffinite_math_only,
-  options::OPT_fno_finite_math_only, options::OPT_fhonor_nans,
-  options::OPT_fno_honor_nans))
-if (A->getOption().getID() != options::OPT_fno_fast_math &&
-A->getOption().getID() != options::OPT_fno_finite_math_only &&
-A->getOption().getID() != options::OPT_fhonor_nans)
-  CmdArgs.push_back("-menable-no-nans");
-
+  // appropriate LLVM code generation flags. This is complicated by several
+  // "umbrella" flags, so we do this by stepping through the flags 
incrementally
+  // adjusting what we think is enabled/disabled, then at the end settting the
+  // LLVM flags based on the final state.
+  bool HonorInfs = true;
+  bool HonorNans = true;
   // -fmath-errno is the default on some platforms, e.g. BSD-derived OSes.
   bool MathErrno = getToolChain().IsMathErrnoDefault();
-  if (Arg *A =
-  Args.getLastArg(options::OPT_ffast_math, FastMathAliasOption,
-  options::OPT_fno_fast_math, options::OPT_fmath_errno,
-  options::OPT_fno_math_errno)) {
-// Turning on -ffast_math (with either flag) removes the need for 
MathErrno.
-// However, turning *off* -ffast_math merely restores the toolchain default
-// (which may be false).
-if (A->getOption().getID() == options::OPT_fno_math_errno ||
-A->getOption().getID() == options::OPT_ffast_math ||
-A->getOption().getID() == options::OPT_Ofast)
-  MathErrno = false;
-else if (A->getOption().getID() == options::OPT_fmath_errno)
-  MathErrno = true;
-  }
-  if (MathErrno)
-CmdArgs.push_back("-fmath-errno");
-
-  // There are several flags which require disabling very specific
-  // optimizations. Any of these being disabled forces us to turn off the
-  // entire set of LLVM optimizations, so collect them through all the flag
-  // madness.
   bool AssociativeMath = false;
-  if (Arg *A = Args.getLastArg(
-  options::OPT_ffast_math, FastMathAliasOption,
-  options::OPT_fno_fast_math, options::OPT_funsafe_math_optimizations,
-  options::OPT_fno_unsafe_math_optimiz

[PATCH] D30896: [Clang-tidy] add check misc-prefer-switch-for-enums

2017-03-15 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe added a comment.

I've run the check on clang. It's noisy (690 warnings). The (few) cases I've 
manually inspected look like firm candidates for replacing with switches. Not 
my call though.

F3145418: reduced-clang-tidy-switch-checks 

I'm going to look at quantlib next as that's a domain of interest to me.


Repository:
  rL LLVM

https://reviews.llvm.org/D30896



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


[PATCH] D30977: [CodeGen] Emit a CoreFoundation link guard when @available is used

2017-03-15 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CGObjC.cpp:3435
+  CheckFTy, "__clang_at_available_requires_core_foundation_framework"));
+  CFLinkCheckFunc->setLinkage(llvm::GlobalValue::LinkOnceAnyLinkage);
+  CodeGenFunction CGF(*this);

Is this a public weak symbol?  Make it hidden, please.

Did you consider just adding "-framework CoreFoundation"  to the module link 
options?


Repository:
  rL LLVM

https://reviews.llvm.org/D30977



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


[PATCH] D30896: [Clang-tidy] add check misc-prefer-switch-for-enums

2017-03-15 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe added a comment.

Quantlib produces no warnings but relies heavily on virtual-dispatch so that 
may be unsurprising.


Repository:
  rL LLVM

https://reviews.llvm.org/D30896



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


[PATCH] D30896: [Clang-tidy] add check misc-prefer-switch-for-enums

2017-03-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D30896#701642, @jbcoe wrote:

> I've run the check on clang. It's noisy (690 warnings). The (few) cases I've 
> manually inspected look like firm candidates for replacing with switches. Not 
> my call though.
>
> F3145418: reduced-clang-tidy-switch-checks 


The first thing I noticed is that this definitely emits false positives that 
would not be improved by a switch. Consider SemaExprCXX.cpp:3288:

  return ConditionResult(*this, ConditionVar, MakeFullExpr(E.get(), StmtLoc),
 CK == ConditionKind::ConstexprIf);

or SemaLambda.cpp:1023:

  assert(C->InitKind == LambdaCaptureInitKind::NoInit &&
 "init capture has valid but null init?");

Out of the five random diagnostics I picked, three would be made worse by a 
switch (SemaExprCXX.cpp:3288, SemaLambda.cpp:1023, CGDebugInfo.cpp:4000), one 
would be made better (LLParser.cpp:6206), and one would be questionable 
(PDB.cpp:30), all in my opinion, of course. Given the number of diagnostics it 
produces, and the fact that my very small random sampling produced a 60% 
false-positive rate, that's a bit concerning. It could also be a total 
coincidence due to my small sample size, of course.

I think this check has utility and would be useful, but I think it needs some 
tuning (whether in the form of heuristics or options) to help reduce the noise 
out of the box. Taking a more thorough look at the results from running it over 
clang may identify some usage patterns that suggest what kind of heuristics or 
tuning would help.


Repository:
  rL LLVM

https://reviews.llvm.org/D30896



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


[PATCH] D28136: [OpenCL] Implement as_type operator as alias of __builtin_astype.

2017-03-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In https://reviews.llvm.org/D28136#701508, @bader wrote:

> > From all the above arguments, I feel like the right approach would be to 
> > implement it as Clang builtin which closely matches the operator semantic 
> > in my opinion. We could of course reuse the implementation of  
> > __bultin_astype to avoid unnecessary extra work and code duplication.
> > 
> > Using the macro seems to me more like a workaround solution and overloaded 
> > functions don't seem to be entirely the right thing either.  What do you 
> > think about it?
>
> I don't think we need another Clang built-in. __builtin_astype was added 
> specifically for OpenCL needs (see rev. 132612).
>  Do you know better way to map astype operators (there are a lot of them 
> as_#) to single Clang built-in?


Unfortunately,  __builtin_astype doesn't match the astype syntax from the spec 
exactly, which I wish it would. I don't feel strongly neither with macro (which 
messes up proper error reporting) nor with function declaration (for which 
implicit conversion would apply just like to other C functions). Having Clang 
builtin would feel the most natural way to me but I agree the way it is defined 
with the multiple distinct names for each type I am not going to advocate for 
it strongly.




Comment at: lib/Headers/opencl-c.h:6588
-char __ovld __cnfn as_char(char);
-char __ovld __cnfn as_char(uchar);
-

Why do we have some of the overloads omitted? Would this cause any extra 
conversions? uchar -> char in this case?


https://reviews.llvm.org/D28136



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


[PATCH] D28299: Module: use PCMCache to manage memory buffers for pcm files.

2017-03-15 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a comment.

Drive-by comment.




Comment at: clang/lib/Basic/MemoryBufferCache.cpp:18
+ std::unique_ptr Buffer) {
+  auto Insertion = Buffers.insert(std::make_pair(
+  Filename, BufferEntry{std::move(Buffer), NextIndex++}));

we should be able to replace the `std::make_pair()` with `{}`.


https://reviews.llvm.org/D28299



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


[PATCH] D30854: [ASTMatchers] Add ObjC matchers for fundamental decls

2017-03-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: unittests/ASTMatchers/ASTMatchersTest.h:64
 const std::string &Code, const T &AMatcher, bool ExpectMatch,
-llvm::StringRef CompileArg,
+std::vector Args,
 const FileContentMappings &VirtualMappedFiles = FileContentMappings(),

I think this might be better as an `llvm::ArrayRef`.



Comment at: unittests/ASTMatchers/ASTMatchersTest.h:114
+  return matchesConditionally(
+Code, AMatcher, ExpectMatch, std::vector{CompileArg},
+VirtualMappedFiles, Filename);

This could then use `makeArrayRef(CompileArg)`.


https://reviews.llvm.org/D30854



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


r297851 - Update clang-cl driver for MSVC 2017.

2017-03-15 Thread Zachary Turner via cfe-commits
Author: zturner
Date: Wed Mar 15 11:07:35 2017
New Revision: 297851

URL: http://llvm.org/viewvc/llvm-project?rev=297851&view=rev
Log:
Update clang-cl driver for MSVC 2017.

2017 changes the way you find an installed copy of
Visual Studio as well as its internal directory layout.
As a result, clang-cl was unable to find VS2017 even
when you had run vcvarsall to set up a toolchain
environment.  This patch updates everything for 2017
and cleans up the way we handle a tiered search a la
environment -> installation -> PATH for which copy
of Visual Studio to bind to.

Patch originally by Hamza Sood, with some fixups for landing.

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

Added:
cfe/trunk/lib/Driver/ToolChains/MSVCSetupApi.h
Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/lib/Driver/ToolChains/MSVC.cpp
cfe/trunk/lib/Driver/ToolChains/MSVC.h
cfe/trunk/test/Driver/cl-link-at-file.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=297851&r1=297850&r2=297851&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Wed Mar 15 11:07:35 
2017
@@ -283,4 +283,8 @@ def warn_drv_ps4_sdk_dir : Warning<
 def err_drv_unsupported_linker : Error<"unsupported value '%0' for -linker 
option">;
 def err_drv_defsym_invalid_format : Error<"defsym must be of the form: 
sym=value: %0">;
 def err_drv_defsym_invalid_symval : Error<"Value is not an integer: %0">;
+def warn_drv_msvc_not_found : Warning<
+  "unable to find a Visual Studio installation; "
+  "try running Clang from a developer command prompt">,
+  InGroup;
 }

Modified: cfe/trunk/lib/Driver/ToolChains/MSVC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/MSVC.cpp?rev=297851&r1=297850&r2=297851&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/MSVC.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/MSVC.cpp Wed Mar 15 11:07:35 2017
@@ -7,9 +7,9 @@
 //
 
//===--===//
 
-#include "Darwin.h"
 #include "MSVC.h"
 #include "CommonArgs.h"
+#include "Darwin.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/Version.h"
 #include "clang/Driver/Compilation.h"
@@ -25,6 +25,8 @@
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Host.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include 
@@ -42,6 +44,18 @@
 #define NOMINMAX
   #endif
   #include 
+
+// Make sure this comes before MSVCSetupApi.h
+#include 
+
+#include "MSVCSetupApi.h"
+#include "llvm/Support/COM.h"
+_COM_SMARTPTR_TYPEDEF(ISetupConfiguration, __uuidof(ISetupConfiguration));
+_COM_SMARTPTR_TYPEDEF(ISetupConfiguration2, __uuidof(ISetupConfiguration2));
+_COM_SMARTPTR_TYPEDEF(ISetupHelper, __uuidof(ISetupHelper));
+_COM_SMARTPTR_TYPEDEF(IEnumSetupInstances, __uuidof(IEnumSetupInstances));
+_COM_SMARTPTR_TYPEDEF(ISetupInstance, __uuidof(ISetupInstance));
+_COM_SMARTPTR_TYPEDEF(ISetupInstance2, __uuidof(ISetupInstance2));
 #endif
 
 using namespace clang::driver;
@@ -50,24 +64,232 @@ using namespace clang::driver::tools;
 using namespace clang;
 using namespace llvm::opt;
 
+// Defined below.
+// Forward declare this so there aren't too many things above the constructor.
+static bool getSystemRegistryString(const char *keyPath, const char *valueName,
+std::string &value, std::string *phValue);
+
+// Check various environment variables to try and find a toolchain.
+static bool findVCToolChainViaEnvironment(std::string &Path,
+  bool &IsVS2017OrNewer) {
+  // These variables are typically set by vcvarsall.bat
+  // when launching a developer command prompt.
+  if (llvm::Optional VCToolsInstallDir =
+  llvm::sys::Process::GetEnv("VCToolsInstallDir")) {
+// This is only set by newer Visual Studios, and it leads straight to
+// the toolchain directory.
+Path = std::move(*VCToolsInstallDir);
+IsVS2017OrNewer = true;
+return true;
+  }
+  if (llvm::Optional VCInstallDir =
+  llvm::sys::Process::GetEnv("VCINSTALLDIR")) {
+// If the previous variable isn't set but this one is, then we've found
+// an older Visual Studio. This variable is set by newer Visual Studios 
too,
+// so this check has to appear second.
+// In older Visual Studios, the VC directory is the toolchain.
+Path = std::move(*VCInstallDir);
+IsVS2017OrNewer = false;
+return true;
+  }
+
+  // We couldn't find any VC environment variables. Let's walk through PATH an

[PATCH] D30937: [OpenCL] Added diagnostic for checking length of vector

2017-03-15 Thread Egor Churaev via Phabricator via cfe-commits
echuraev updated this revision to Diff 91890.
echuraev marked 5 inline comments as done.
Herald added a subscriber: yaxunl.

https://reviews.llvm.org/D30937

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaExprMember.cpp
  test/SemaOpenCL/vector_swizzle_length.cl


Index: test/SemaOpenCL/vector_swizzle_length.cl
===
--- /dev/null
+++ test/SemaOpenCL/vector_swizzle_length.cl
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+
+typedef float float8 __attribute__((ext_vector_type(8)));
+
+void foo() {
+float8 f2 = (float8)(0, 0, 0, 0, 0, 0, 0, 0);
+
+f2.s01234; // expected-error {{vector component access has invalid length 
5.  Supported: 1,2,3,4,8,16}}
+f2.xyzxy; // expected-error {{vector component access has invalid length 
5.  Supported: 1,2,3,4,8,16}}
+}
Index: lib/Sema/SemaExprMember.cpp
===
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -284,6 +284,14 @@
   }
 }
 
+// OpenCL v1.1, s6.1.7
+// The component swizzle length must be in accordance with the acceptable
+// vector sizes.
+static bool IsValidOpenCLComponentSwizzleLength(unsigned len)
+{
+  return (len >= 1 && len <= 4) || len == 8 || len == 16;
+}
+
 /// Check an ext-vector component access expression.
 ///
 /// VK should be set in advance to the value kind of the base
@@ -376,6 +384,19 @@
 }
   }
 
+  if (!HalvingSwizzle) {
+unsigned SwizzleLength = CompName->getLength();
+
+if (HexSwizzle)
+  SwizzleLength--;
+
+if (IsValidOpenCLComponentSwizzleLength(SwizzleLength) == false) {
+  S.Diag(OpLoc, diag::err_opencl_ext_vector_component_invalid_length)
+<< SwizzleLength << SourceRange(CompLoc);
+  return QualType();
+}
+  }
+
   // The component accessor looks fine - now we need to compute the actual 
type.
   // The vector type is implied by the component accessor. For example,
   // vec4.b is a float, vec4.xy is a vec2, vec4.rgb is a vec3, etc.
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -8236,6 +8236,8 @@
 def err_kernel_arg_address_space : Error<
   "pointer arguments to kernel functions must reside in '__global', "
   "'__constant' or '__local' address space">;
+def err_opencl_ext_vector_component_invalid_length : Error<
+  "vector component access has invalid length %0.  Supported: 1,2,3,4,8,16.">;
 def err_opencl_function_variable : Error<
   "%select{non-kernel function|function scope}0 variable cannot be declared in 
%1 address space">;
 def err_static_function_scope : Error<


Index: test/SemaOpenCL/vector_swizzle_length.cl
===
--- /dev/null
+++ test/SemaOpenCL/vector_swizzle_length.cl
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+
+typedef float float8 __attribute__((ext_vector_type(8)));
+
+void foo() {
+float8 f2 = (float8)(0, 0, 0, 0, 0, 0, 0, 0);
+
+f2.s01234; // expected-error {{vector component access has invalid length 5.  Supported: 1,2,3,4,8,16}}
+f2.xyzxy; // expected-error {{vector component access has invalid length 5.  Supported: 1,2,3,4,8,16}}
+}
Index: lib/Sema/SemaExprMember.cpp
===
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -284,6 +284,14 @@
   }
 }
 
+// OpenCL v1.1, s6.1.7
+// The component swizzle length must be in accordance with the acceptable
+// vector sizes.
+static bool IsValidOpenCLComponentSwizzleLength(unsigned len)
+{
+  return (len >= 1 && len <= 4) || len == 8 || len == 16;
+}
+
 /// Check an ext-vector component access expression.
 ///
 /// VK should be set in advance to the value kind of the base
@@ -376,6 +384,19 @@
 }
   }
 
+  if (!HalvingSwizzle) {
+unsigned SwizzleLength = CompName->getLength();
+
+if (HexSwizzle)
+  SwizzleLength--;
+
+if (IsValidOpenCLComponentSwizzleLength(SwizzleLength) == false) {
+  S.Diag(OpLoc, diag::err_opencl_ext_vector_component_invalid_length)
+<< SwizzleLength << SourceRange(CompLoc);
+  return QualType();
+}
+  }
+
   // The component accessor looks fine - now we need to compute the actual type.
   // The vector type is implied by the component accessor. For example,
   // vec4.b is a float, vec4.xy is a vec2, vec4.rgb is a vec3, etc.
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -8236,6 +8236,8 @@
 def err_kernel_arg_address_space : Error<
   "pointer arguments to kernel functions must reside in '__global', "
   "'__constant' or '__local' address space">;
+def err_opencl_

[PATCH] D28136: [OpenCL] Implement as_type operator as alias of __builtin_astype.

2017-03-15 Thread Alexey Bader via Phabricator via cfe-commits
bader added inline comments.



Comment at: lib/Headers/opencl-c.h:6588
-char __ovld __cnfn as_char(char);
-char __ovld __cnfn as_char(uchar);
-

Anastasia wrote:
> Why do we have some of the overloads omitted? Would this cause any extra 
> conversions? uchar -> char in this case?
It's specific to how builtin_astype works. It drops first argument type and 
only cares about matching first argument size with the data type size provided 
as a second argument. So basically with single line we get all possible and 
impossible overloads of as_char(*).
This define will pass any variable type char,uchar to builtin_astype.


https://reviews.llvm.org/D28136



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


r297858 - Disable warning about MSVC not found.

2017-03-15 Thread Zachary Turner via cfe-commits
Author: zturner
Date: Wed Mar 15 11:35:13 2017
New Revision: 297858

URL: http://llvm.org/viewvc/llvm-project?rev=297858&view=rev
Log:
Disable warning about MSVC not found.

When this test runs on bots that are configured to default
to MSVC, but MSVC isn't actually installed, we can emit a
warning that MSVC is not found.  Since MSVC isn't actually
needed for this test to succeed, just disable this warning.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/test/Misc/backend-stack-frame-diagnostics.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=297858&r1=297857&r2=297858&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Wed Mar 15 11:35:13 
2017
@@ -286,5 +286,5 @@ def err_drv_defsym_invalid_symval : Erro
 def warn_drv_msvc_not_found : Warning<
   "unable to find a Visual Studio installation; "
   "try running Clang from a developer command prompt">,
-  InGroup;
+  InGroup>;
 }

Modified: cfe/trunk/test/Misc/backend-stack-frame-diagnostics.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/backend-stack-frame-diagnostics.cpp?rev=297858&r1=297857&r2=297858&view=diff
==
--- cfe/trunk/test/Misc/backend-stack-frame-diagnostics.cpp (original)
+++ cfe/trunk/test/Misc/backend-stack-frame-diagnostics.cpp Wed Mar 15 11:35:13 
2017
@@ -8,7 +8,7 @@
 
 // Test that link invocations don't emit an "argument unused during 
compilation" diagnostic.
 // RUN: touch %t.o
-// RUN: %clang -Werror -Wno-liblto -Wframe-larger-than=0 %t.o -###  2>&1 | not 
grep ' error: '
+// RUN: %clang -Werror -Wno-msvc-not-found -Wno-liblto -Wframe-larger-than=0 
%t.o -###  2>&1 | not grep ' error: '
 
 // TODO: Support rich backend diagnostics for Objective-C methods.
 


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


[PATCH] D30896: [Clang-tidy] add check misc-prefer-switch-for-enums

2017-03-15 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe planned changes to this revision.
jbcoe added a comment.

@Aaron I agree that some instances from your sample would not be improved by a 
switch. I'll look into narrowing the matched.


Repository:
  rL LLVM

https://reviews.llvm.org/D30896



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


Re: LLVM Lab SVN mirror is behind

2017-03-15 Thread Galina Kistanova via cfe-commits
I'm looking at that. Hope we will get a solution by the next release time.

Thanks

Galina


On Tue, Mar 14, 2017 at 9:10 AM, Hans Wennborg  wrote:

> r297634 was the 4.0.0 release commit. We'll probably see similar-size
> commits for 4.0.1 and 5.0.0. Can we make the buildbot svn mirror
> ignore that component of the repository to avoid this happening again?
>
>  - Hans
>
> On Tue, Mar 14, 2017 at 12:23 AM, Galina Kistanova via cfe-commits
>  wrote:
> > The SVN mirror is back up and running.
> > Please let me know if you would see any issues.
> >
> > Thanks for your patience.
> >
> >
> > On Mon, Mar 13, 2017 at 4:26 PM, Galina Kistanova 
> > wrote:
> >>
> >> A quick update.
> >>
> >> The SVN mirror got corrupted by r297634. Svnsync does not like huge
> >> commits.
> >> I'm in the middle of restoring and synch-ing up the mirror. Too soon to
> >> give any ETA, unfortunately.
> >>
> >> Thank you for your patience.
> >>
> >> Thanks
> >>
> >> Galina
> >>
> >>
> >>
> >>
> >> On Mon, Mar 13, 2017 at 12:36 PM, Galina Kistanova <
> gkistan...@gmail.com>
> >> wrote:
> >>>
> >>> Hello everyone,
> >>>
> >>> The SVN mirror in the LLVM Lab seems behind with the changes.
> >>> I'm looking at the issue.
> >>>
> >>> Thank you for understanding.
> >>>
> >>> Thanks
> >>>
> >>
> >
> >
> > ___
> > 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


r297861 - Don't use MSVC Setup Api on MinGW.

2017-03-15 Thread Zachary Turner via cfe-commits
Author: zturner
Date: Wed Mar 15 12:09:36 2017
New Revision: 297861

URL: http://llvm.org/viewvc/llvm-project?rev=297861&view=rev
Log:
Don't use MSVC Setup Api on MinGW.

Modified:
cfe/trunk/lib/Driver/ToolChains/MSVC.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/MSVC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/MSVC.cpp?rev=297861&r1=297860&r2=297861&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/MSVC.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/MSVC.cpp Wed Mar 15 12:09:36 2017
@@ -44,6 +44,11 @@
 #define NOMINMAX
   #endif
   #include 
+#endif
+
+#ifdef _MSC_VER
+// Don't support SetupApi on MinGW.
+#define USE_MSVC_SETUP_API
 
 // Make sure this comes before MSVCSetupApi.h
 #include 
@@ -170,7 +175,7 @@ static bool findVCToolChainViaEnvironmen
 // longer listed in the registry.
 static bool findVCToolChainViaSetupConfig(std::string &Path,
   bool &IsVS2017OrNewer) {
-#if !defined(USE_WIN32)
+#if !defined(USE_MSVC_SETUP_API)
   return false;
 #else
   // FIXME: This really should be done once in the top-level program's main


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


r297862 - [ObjC][Sema] Avoid warning about a call to an instance method on an

2017-03-15 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Wed Mar 15 12:16:41 2017
New Revision: 297862

URL: http://llvm.org/viewvc/llvm-project?rev=297862&view=rev
Log:
[ObjC][Sema] Avoid warning about a call to an instance method on an
instance of a qualified Class object when that instance method comes from
a protocol that's implemented by NSObject

Instance methods from a root class like NSObject are also class methods because
the metaclass of root class derives from that root class. Therefore, we can
avoid the warning for instances of qualified Class objects that point to classes
that derive from NSObject. Note that we actually don't know if a Class instance
points to a class that derives from NSObject at compile-time, so we have to
make a reasonable assumption that the majority of instances will do so.

rdar://22812517

Modified:
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/test/SemaObjC/class-message-protocol-lookup.m

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=297862&r1=297861&r2=297862&view=diff
==
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Wed Mar 15 12:16:41 2017
@@ -2556,6 +2556,24 @@ ExprResult Sema::BuildInstanceMessageImp
   /*isImplicit=*/true);
 }
 
+static bool isMethodDeclaredInRootProtocol(Sema &S, const ObjCMethodDecl *M) {
+  if (!S.NSAPIObj)
+return false;
+  const auto *Protocol = dyn_cast(M->getDeclContext());
+  if (!Protocol)
+return false;
+  const IdentifierInfo *II = S.NSAPIObj->getNSClassId(NSAPI::ClassId_NSObject);
+  if (const auto *RootClass = dyn_cast_or_null(
+  S.LookupSingleName(S.TUScope, II, Protocol->getLocStart(),
+ Sema::LookupOrdinaryName))) {
+for (const ObjCProtocolDecl *P : RootClass->all_referenced_protocols()) {
+  if (P->getCanonicalDecl() == Protocol->getCanonicalDecl())
+return true;
+}
+  }
+  return false;
+}
+
 /// \brief Build an Objective-C instance message expression.
 ///
 /// This routine takes care of both normal instance messages and
@@ -2731,7 +2749,7 @@ ExprResult Sema::BuildInstanceMessage(Ex
 if (!Method) {
   Method = LookupMethodInQualifiedType(Sel, QClassTy, true);
   // warn if instance method found for a Class message.
-  if (Method) {
+  if (Method && !isMethodDeclaredInRootProtocol(*this, Method)) {
 Diag(SelLoc, diag::warn_instance_method_on_class_found)
   << Method->getSelector() << Sel;
 Diag(Method->getLocation(), diag::note_method_declared_at)

Modified: cfe/trunk/test/SemaObjC/class-message-protocol-lookup.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/class-message-protocol-lookup.m?rev=297862&r1=297861&r2=297862&view=diff
==
--- cfe/trunk/test/SemaObjC/class-message-protocol-lookup.m (original)
+++ cfe/trunk/test/SemaObjC/class-message-protocol-lookup.m Wed Mar 15 12:16:41 
2017
@@ -32,3 +32,30 @@ int main ()
 Class c2 = [c2 alloc]; //  ok
 return 0;
 }
+
+// rdar://22812517
+
+@protocol NSObject
+
+- (int)respondsToSelector:(SEL)aSelector;
+
+@end
+
+__attribute__((objc_root_class))
+@interface NSObject 
+
+@end
+
+@protocol OtherProto
+
+- (void)otherInstanceMethod; // expected-note {{method 'otherInstanceMethod' 
declared here}}
+
+@end
+
+@protocol MyProto 
+@end
+
+void allowInstanceMethodsFromRootProtocols(Class c) {
+  [c respondsToSelector: @selector(instanceMethod)]; // no warning
+  [c otherInstanceMethod]; //  expected-warning {{instance method 
'otherInstanceMethod' found instead of class method 'otherInstanceMethod'}}
+}


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


[PATCH] D30854: [ASTMatchers] Add ObjC matchers for fundamental decls

2017-03-15 Thread Dave Lee via Phabricator via cfe-commits
kastiglione added inline comments.



Comment at: unittests/ASTMatchers/ASTMatchersTest.h:64
 const std::string &Code, const T &AMatcher, bool ExpectMatch,
-llvm::StringRef CompileArg,
+std::vector Args,
 const FileContentMappings &VirtualMappedFiles = FileContentMappings(),

aaron.ballman wrote:
> I think this might be better as an `llvm::ArrayRef`.
Ok. It needs to be a `std::vector` for `runToolOnCodeWithArgs()`. 
I don't see any built in way to do that conversion, so this function will have 
to manually do that I guess?


https://reviews.llvm.org/D30854



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


[PATCH] D30854: [ASTMatchers] Add ObjC matchers for fundamental decls

2017-03-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: unittests/ASTMatchers/ASTMatchersTest.h:64
 const std::string &Code, const T &AMatcher, bool ExpectMatch,
-llvm::StringRef CompileArg,
+std::vector Args,
 const FileContentMappings &VirtualMappedFiles = FileContentMappings(),

kastiglione wrote:
> aaron.ballman wrote:
> > I think this might be better as an `llvm::ArrayRef`.
> Ok. It needs to be a `std::vector` for 
> `runToolOnCodeWithArgs()`. I don't see any built in way to do that 
> conversion, so this function will have to manually do that I guess?
Can you do:
```
std::vector LocalArgs(Args.begin(), Args.end());
LocalArgs.insert(LocalArgs.end(), {"everything else"});
```
below?


https://reviews.llvm.org/D30854



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


[PATCH] D30841: [clang-tidy] readability-misleading-indentation: fix chained if

2017-03-15 Thread Florian Gross via Phabricator via cfe-commits
fgross added a comment.

I don't have commit access, so could someone please commit this for me? Thanks!


https://reviews.llvm.org/D30841



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


[PATCH] D30810: Preserve vec3 type.

2017-03-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

I don't think there is anything wrong with the generation of vec3->vec4 in 
Clang. I believe the motivation for this was the OpenCL spec treating vec3 as 
vec4 aligned type (see section 6.1.5: 
https://www.khronos.org/registry/OpenCL/specs/opencl-2.0-openclc.pdf#12). So in 
terms of memory layout vec3 wouldn't be any different to vec4. But in terms of 
operations (including loads/stores) there can be potential gain from not 
handling the 4th element.  This can be exploited by some targets. I think 
generating the vec3 from the frontend would be a better choice in the first 
place. Because backend can decide how to handle this. Including for 
architectures with no SIMD support it would just generate 3 separate loads. 
Right now it seems that it will be forced to generate 4 loads.

But considering that transformation to vec4 has been the default implementation 
for quite a while in the frontend, I think we would need a stronger motivation 
for switching to original vec3. So current approach with a special flag for 
preserving vec3 should be good enough to fit all needs.


https://reviews.llvm.org/D30810



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


[PATCH] D30896: [Clang-tidy] add check misc-prefer-switch-for-enums

2017-03-15 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

@jbcoe and @aaron.ballman i think an valid warning would be if there is another 
check in an `else if` statement. 
so singular `if(enum_value == Enum::Kind)` is still ok, but another branch 
checking on the enum is suspiscious.


Repository:
  rL LLVM

https://reviews.llvm.org/D30896



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


r297866 - [Driver] Define macro __APPLE_EMBEDDED_SIMULATOR__ when option

2017-03-15 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Wed Mar 15 13:04:13 2017
New Revision: 297866

URL: http://llvm.org/viewvc/llvm-project?rev=297866&view=rev
Log:
[Driver] Define macro __APPLE_EMBEDDED_SIMULATOR__ when option
-m(i|tv|watch)os-simulator-version-min is on the command line.

Previously the driver would treat -m(i|tv|watch)os-simulator-version-min
as an alias of -m(i|tv|watch)os-version-min. This no longer works since
we now need to distinguish between the two options (the latter is used
for iOS running in a VM, for example).

This commit stops making the simulator options the aliases of the OS
options and defines a macro to differentiate between the two groups of
options. 

rdar://problem/28872911

Added:
cfe/trunk/test/Driver/darwin-simulator-macro.c
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/ToolChains/Darwin.cpp

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=297866&r1=297865&r2=297866&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Mar 15 13:04:13 2017
@@ -1603,11 +1603,11 @@ def mpure_code : Flag<["-"], "mpure-code
 def mno_pure_code : Flag<["-"], "mno-pure-code">, Alias;
 def mtvos_version_min_EQ : Joined<["-"], "mtvos-version-min=">, Group;
 def mappletvos_version_min_EQ : Joined<["-"], "mappletvos-version-min=">, 
Alias;
-def mtvos_simulator_version_min_EQ : Joined<["-"], 
"mtvos-simulator-version-min=">, Alias;
-def mappletvsimulator_version_min_EQ : Joined<["-"], 
"mappletvsimulator-version-min=">, Alias;
+def mtvos_simulator_version_min_EQ : Joined<["-"], 
"mtvos-simulator-version-min=">;
+def mappletvsimulator_version_min_EQ : Joined<["-"], 
"mappletvsimulator-version-min=">, Alias;
 def mwatchos_version_min_EQ : Joined<["-"], "mwatchos-version-min=">, 
Group;
-def mwatchos_simulator_version_min_EQ : Joined<["-"], 
"mwatchos-simulator-version-min=">, Alias;
-def mwatchsimulator_version_min_EQ : Joined<["-"], 
"mwatchsimulator-version-min=">, Alias;
+def mwatchos_simulator_version_min_EQ : Joined<["-"], 
"mwatchos-simulator-version-min=">;
+def mwatchsimulator_version_min_EQ : Joined<["-"], 
"mwatchsimulator-version-min=">, Alias;
 def march_EQ : Joined<["-"], "march=">, Group;
 def masm_EQ : Joined<["-"], "masm=">, Group, Flags<[DriverOption]>;
 def mcmodel_EQ : Joined<["-"], "mcmodel=">, Group;
@@ -1636,8 +1636,8 @@ def mhard_float : Flag<["-"], "mhard-flo
 def miphoneos_version_min_EQ : Joined<["-"], "miphoneos-version-min=">, 
Group;
 def mios_version_min_EQ : Joined<["-"], "mios-version-min=">,
   Alias, HelpText<"Set iOS deployment target">;
-def mios_simulator_version_min_EQ : Joined<["-"], 
"mios-simulator-version-min=">, Alias;
-def miphonesimulator_version_min_EQ : Joined<["-"], 
"miphonesimulator-version-min=">, Alias;
+def mios_simulator_version_min_EQ : Joined<["-"], 
"mios-simulator-version-min=">;
+def miphonesimulator_version_min_EQ : Joined<["-"], 
"miphonesimulator-version-min=">, Alias;
 def mkernel : Flag<["-"], "mkernel">, Group;
 def mlinker_version_EQ : Joined<["-"], "mlinker-version=">,
   Flags<[DriverOption]>;

Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.cpp?rev=297866&r1=297865&r2=297866&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp Wed Mar 15 13:04:13 2017
@@ -1125,9 +1125,22 @@ void Darwin::AddDeploymentTarget(Derived
   }
 
   Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ);
-  Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ);
-  Arg *TvOSVersion = Args.getLastArg(options::OPT_mtvos_version_min_EQ);
-  Arg *WatchOSVersion = Args.getLastArg(options::OPT_mwatchos_version_min_EQ);
+  Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ,
+
options::OPT_mios_simulator_version_min_EQ);
+  Arg *TvOSVersion =
+  Args.getLastArg(options::OPT_mtvos_version_min_EQ,
+  options::OPT_mtvos_simulator_version_min_EQ);
+  Arg *WatchOSVersion =
+  Args.getLastArg(options::OPT_mwatchos_version_min_EQ,
+  options::OPT_mwatchos_simulator_version_min_EQ);
+
+  // Add a macro to differentiate between m(iphone|tv|watch)os-version-min=X.Y 
and
+  // -m(iphone|tv|watch)simulator-version-min=X.Y.
+  if (Args.hasArg(options::OPT_mios_simulator_version_min_EQ) ||
+  Args.hasArg(options::OPT_mtvos_simulator_version_min_EQ) ||
+  Args.hasArg(options::OPT_mwatchos_simulator_version_min_EQ))
+Args.append(Args.MakeSeparateArg(nullptr, Opts.getOption(options::OPT_D),
+ " __APPLE_EMBEDDED_SIMULATOR__=1"));
 

[PATCH] D30990: Add more examples to clang-format configuration

2017-03-15 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru created this revision.
Herald added a subscriber: klimek.

https://reviews.llvm.org/D30990

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h

Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -204,7 +204,7 @@
   bool AllowShortLoopsOnASingleLine;
 
   /// \brief Different ways to break after the function definition return type.
-  /// This option is deprecated and is retained for backwards compatibility.
+  /// This option is **deprecated** and is retained for backwards compatibility.
   enum DefinitionReturnTypeBreakingStyle {
 /// Break after return type automatically.
 /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
@@ -287,7 +287,7 @@
   };
 
   /// \brief The function definition return type breaking style to use.  This
-  /// option is deprecated and is retained for backwards compatibility.
+  /// option is **deprecated** and is retained for backwards compatibility.
   DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType;
 
   /// \brief The function declaration return type breaking style to use.
@@ -318,19 +318,73 @@
 
   /// \brief If ``false``, a function call's arguments will either be all on the
   /// same line or will have one line each.
+  /// \code
+  ///   true:
+  ///   void f() {
+  /// f(, ,
+  ///   aaa);
+  ///   }
+  ///
+  ///   false:
+  ///   void f() {
+  /// f(,
+  ///   ,
+  ///   aaa);
+  ///   }
+  /// \endcode
   bool BinPackArguments;
 
   /// \brief If ``false``, a function declaration's or function definition's
   /// parameters will either all be on the same line or will have one line each.
+  /// \code
+  ///   true:
+  ///   void f(int , int ,
+  ///  int aaa) {}
+  ///
+  ///   false:
+  ///   void f(int ,
+  ///  int ,
+  ///  int aaa) {}
+  /// \endcode
   bool BinPackParameters;
 
   /// \brief The style of breaking before or after binary operators.
   enum BinaryOperatorStyle {
 /// Break after operators.
+/// \code
+///LooongType loongVariable =
+///someLongFunction();
+///
+///bool value = a +
+/// a ==
+/// a &&
+/// a >
+/// c;
+/// \endcode
 BOS_None,
 /// Break before operators that aren't assignments.
+/// \code
+///LooongType loongVariable =
+///someLongFunction();
+///
+///bool value = a
+/// + a
+/// == a
+/// && a
+///> c;
+/// \endcode
 BOS_NonAssignment,
 /// Break before operators.
+/// \code
+///LooongType loongVariable
+///= someLongFunction();
+///
+///bool value = a
+/// + a
+/// == a
+/// && a
+///> c;
+/// \endcode
 BOS_All,
   };
 
@@ -665,6 +719,11 @@
 
   /// \brief A regular expression that describes comments with special meaning,
   /// which should not be split into lines or otherwise changed.
+  /// \code
+  ///CommentPragmas: '^ FOOBAR pragma:'
+  ///// Will leave the following line unaffected
+  ///#include  // FOOBAR pragma: keep
+  /// \endcode
   std::string CommentPragmas;
 
   /// \brief If ``true``, in the class inheritance expression clang-format will
@@ -824,6 +883,15 @@
   bool IndentCaseLabels;
 
   /// \brief The number of columns to use for indentation.
+  /// \code
+  ///IndentWidth: 3
+  ///void f() {
+  ///   someFunction();
+  ///   if (true, false) {
+  ///  f();
+  ///   }
+  ///}
+  /// \endcode
   unsigned IndentWidth;
 
   /// \brief Indent if a function

[PATCH] D30977: [CodeGen] Emit a CoreFoundation link guard when @available is used

2017-03-15 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: lib/CodeGen/CGObjC.cpp:3435
+  CheckFTy, "__clang_at_available_requires_core_foundation_framework"));
+  CFLinkCheckFunc->setLinkage(llvm::GlobalValue::LinkOnceAnyLinkage);
+  CodeGenFunction CGF(*this);

rjmccall wrote:
> Is this a public weak symbol?  Make it hidden, please.
> 
> Did you consider just adding "-framework CoreFoundation"  to the module link 
> options?
I'm not familiar with module link options, I'll look into them.


Repository:
  rL LLVM

https://reviews.llvm.org/D30977



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


[PATCH] D30990: Add more examples to clang-format configuration

2017-03-15 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added inline comments.



Comment at: docs/ClangFormatStyleOptions.rst:671
+
+   bool value = a
++ a

Is this example valid? I don't see why clang-format formats this this way?



Comment at: docs/ClangFormatStyleOptions.rst:686
+   bool value = a
++ a
+== a

Same
```
BasedOnStyle: LLVM
BreakBeforeBinaryOperators: All
```


https://reviews.llvm.org/D30990



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


[PATCH] D30991: [Driver] Fix cross compiling with Visual Studio 2017

2017-03-15 Thread Hamza Sood via Phabricator via cfe-commits
hamzasood created this revision.

- Adds a settable environment to clang::driver::Command.
- Fixes cross compiling with Visual Studio 2017 by ensuring the linker has the 
correct environment.

This was originally part of https://reviews.llvm.org/D28365, however it was 
removed for separate review as requested.
Now that the other patch has landed (in https://reviews.llvm.org/D30758), this 
can now be submitted.


https://reviews.llvm.org/D30991

Files:
  include/clang/Driver/Job.h
  lib/Driver/Job.cpp
  lib/Driver/ToolChains/MSVC.cpp

Index: lib/Driver/ToolChains/MSVC.cpp
===
--- lib/Driver/ToolChains/MSVC.cpp
+++ lib/Driver/ToolChains/MSVC.cpp
@@ -45,17 +45,21 @@
   #endif
   #include 
 
-// Make sure this comes before MSVCSetupApi.h
-#include 
+  // Undefine this macro so we can call the ANSI version of the function.
+  #undef GetEnvironmentStrings
+  #define GetEnvironmentStringsA GetEnvironmentStrings
 
-#include "MSVCSetupApi.h"
-#include "llvm/Support/COM.h"
-_COM_SMARTPTR_TYPEDEF(ISetupConfiguration, __uuidof(ISetupConfiguration));
-_COM_SMARTPTR_TYPEDEF(ISetupConfiguration2, __uuidof(ISetupConfiguration2));
-_COM_SMARTPTR_TYPEDEF(ISetupHelper, __uuidof(ISetupHelper));
-_COM_SMARTPTR_TYPEDEF(IEnumSetupInstances, __uuidof(IEnumSetupInstances));
-_COM_SMARTPTR_TYPEDEF(ISetupInstance, __uuidof(ISetupInstance));
-_COM_SMARTPTR_TYPEDEF(ISetupInstance2, __uuidof(ISetupInstance2));
+  // Make sure this comes before MSVCSetupApi.h
+  #include 
+
+  #include "MSVCSetupApi.h"
+  #include "llvm/Support/COM.h"
+  _COM_SMARTPTR_TYPEDEF(ISetupConfiguration, __uuidof(ISetupConfiguration));
+  _COM_SMARTPTR_TYPEDEF(ISetupConfiguration2, __uuidof(ISetupConfiguration2));
+  _COM_SMARTPTR_TYPEDEF(ISetupHelper, __uuidof(ISetupHelper));
+  _COM_SMARTPTR_TYPEDEF(IEnumSetupInstances, __uuidof(IEnumSetupInstances));
+  _COM_SMARTPTR_TYPEDEF(ISetupInstance, __uuidof(ISetupInstance));
+  _COM_SMARTPTR_TYPEDEF(ISetupInstance2, __uuidof(ISetupInstance2));
 #endif
 
 using namespace clang::driver;
@@ -441,6 +445,8 @@
 
   TC.addProfileRTLibs(Args, CmdArgs);
 
+  std::vector Environment;
+
   // We need to special case some linker paths.  In the case of lld, we need to
   // translate 'lld' into 'lld-link', and in the case of the regular msvc
   // linker, we need to use a special search algorithm.
@@ -454,6 +460,59 @@
 // from the program PATH, because other environments like GnuWin32 install
 // their own link.exe which may come first.
 linkPath = FindVisualStudioExecutable(TC, "link.exe");
+
+#ifdef USE_WIN32
+if (TC.getIsVS2017OrNewer()) {
+  // When cross-compiling with VS2017 or newer, link.exe expects to have
+  // its containing bin directory at the top of PATH, followed by the
+  // native target bin directory.
+  // e.g. when compiling for x86 on an x64 host, PATH should start with:
+  // /bin/HostX64/x86;/bin/HostX64/x64
+  llvm::Triple Host(llvm::sys::getProcessTriple());
+  if (Host.getArch() == TC.getArch()) goto SkipSettingEnvironment;
+
+  char *EnvBlock = GetEnvironmentStringsA();
+  if (EnvBlock == nullptr) goto SkipSettingEnvironment;
+
+  size_t EnvCount = 0;
+  for (const char *Cursor = EnvBlock;
+   *Cursor != '\0';
+   Cursor += strlen(Cursor) + 1/*null-terminator*/)
+++EnvCount;
+
+  Environment.reserve(EnvCount);
+
+  // Now loop over each string in the block and copy them into the
+  // environment vector, adjusting the PATH variable as needed when we
+  // find it.
+  for (const char *Cursor = EnvBlock; *Cursor != '\0';) {
+llvm::StringRef EnvVar(Cursor);
+if (EnvVar.startswith_lower("path=")) {
+  using SubDirectoryType = toolchains::MSVCToolChain::SubDirectoryType;
+  constexpr size_t PrefixLen = 5;  // strlen("path=")
+  Environment.push_back(Args.MakeArgString(
+  EnvVar.substr(0, PrefixLen)
++ TC.getSubDirectoryPath(SubDirectoryType::Bin)
++ llvm::Twine(llvm::sys::EnvPathSeparator)
++ TC.getSubDirectoryPath(SubDirectoryType::Bin, Host.getArch())
++ (EnvVar.size() > PrefixLen
+ ? llvm::Twine(llvm::sys::EnvPathSeparator)
+   + EnvVar.substr(PrefixLen)
+ : "")
+  ));
+}
+else {
+  Environment.push_back(Args.MakeArgString(EnvVar));
+}
+Cursor += EnvVar.size() + 1/*null-terminator*/;
+  }
+
+  FreeEnvironmentStringsA(EnvBlock);
+
+SkipSettingEnvironment:
+  ;
+}
+#endif
   } else {
 linkPath = Linker;
 llvm::sys::path::replace_extension(linkPath, "exe");
@@ -460,8 +519,11 @@
 linkPath = TC.GetProgramPath(linkPath.c_str());
   }
 
-  const char *Exec = Args.MakeArgString(linkPath);
-  C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs));
+  auto LinkCmd = llvm::make_unique(
+   JA, *this

[PATCH] D30991: [Driver] Fix cross compiling with Visual Studio 2017

2017-03-15 Thread Zachary Turner via Phabricator via cfe-commits
zturner requested changes to this revision.
zturner added inline comments.
This revision now requires changes to proceed.



Comment at: lib/Driver/ToolChains/MSVC.cpp:48-50
+  // Undefine this macro so we can call the ANSI version of the function.
+  #undef GetEnvironmentStrings
+  #define GetEnvironmentStringsA GetEnvironmentStrings

I think you will need to delete this part (see comment below).



Comment at: lib/Driver/ToolChains/MSVC.cpp:474
+
+  char *EnvBlock = GetEnvironmentStringsA();
+  if (EnvBlock == nullptr) goto SkipSettingEnvironment;

This is all wrong.  In the implementation of `ExecuteAndWait`, we construct a 
wide environment by calling `UTF8toUTF16` on each string.  
`GetEnvironmentStringsA` not only doesn't return UTF8, it doesn't even return 
ANSI characters.

I think you need to do the work to call `GetEnvironmentStringsW`, then do the 
reverse of the operation performed in `llvm/lib/Support/Windows/Program.inc` in 
the `static bool Execute` function.  It's unfortunate that there's not a 
version that already takes a wide character array, though.


https://reviews.llvm.org/D30991



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


[PATCH] D27800: Add overload of TransformToPotentiallyEvaluated for TypeSourceInfo

2017-03-15 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: test/SemaCXX/pr31042.cpp:1
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only 
-disable-free %s
+

Oh, this testcase doesn't actually crash on trunk without at least -emit-llvm 
because semantic analysis doesn't actually verify the used bit. :(  Better to 
include that, I think.


https://reviews.llvm.org/D27800



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


[libcxx] r297872 - Implement LWG#2761: 'basic_string should require that charT match traits::char_type'. Tests for string_view, too

2017-03-15 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Wed Mar 15 13:41:11 2017
New Revision: 297872

URL: http://llvm.org/viewvc/llvm-project?rev=297872&view=rev
Log:
Implement LWG#2761: 'basic_string should require that charT match 
traits::char_type'. Tests for string_view, too

Added:
libcxx/trunk/test/std/strings/basic.string/traits_mismatch.fail.cpp
libcxx/trunk/test/std/strings/string.view/traits_mismatch.fail.cpp
Removed:
libcxx/trunk/test/std/strings/string.view/nothing_to_do.pass.cpp
Modified:
libcxx/trunk/include/string
libcxx/trunk/include/string_view
libcxx/trunk/www/cxx1z_status.html

Modified: libcxx/trunk/include/string
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=297872&r1=297871&r2=297872&view=diff
==
--- libcxx/trunk/include/string (original)
+++ libcxx/trunk/include/string Wed Mar 15 13:41:11 2017
@@ -637,7 +637,7 @@ public:
 typedef basic_string __self;
 typedef basic_string_view<_CharT, _Traits>   __self_view;
 typedef _Traits  traits_type;
-typedef typename traits_type::char_type  value_type;
+typedef _CharT   value_type;
 typedef _Allocator   allocator_type;
 typedef allocator_traits __alloc_traits;
 typedef typename __alloc_traits::size_type   size_type;
@@ -648,7 +648,7 @@ public:
 typedef typename __alloc_traits::const_pointer   const_pointer;
 
 static_assert(is_pod::value, "Character type of basic_string 
must be a POD");
-static_assert((is_same<_CharT, value_type>::value),
+static_assert((is_same<_CharT, typename traits_type::char_type>::value),
   "traits_type::char_type must be the same type as CharT");
 static_assert((is_same::value),
   "Allocator::value_type must be same type as value_type");

Modified: libcxx/trunk/include/string_view
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string_view?rev=297872&r1=297871&r2=297872&view=diff
==
--- libcxx/trunk/include/string_view (original)
+++ libcxx/trunk/include/string_view Wed Mar 15 13:41:11 2017
@@ -199,6 +199,10 @@ public:
typedef ptrdiff_t  difference_type;
static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1);
 
+static_assert(is_pod::value, "Character type of 
basic_string_view must be a POD");
+static_assert((is_same<_CharT, typename traits_type::char_type>::value),
+  "traits_type::char_type must be the same type as CharT");
+
// [string.view.cons], construct/copy
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
basic_string_view() _NOEXCEPT : __data (nullptr), __size(0) {}

Added: libcxx/trunk/test/std/strings/basic.string/traits_mismatch.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/traits_mismatch.fail.cpp?rev=297872&view=auto
==
--- libcxx/trunk/test/std/strings/basic.string/traits_mismatch.fail.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/traits_mismatch.fail.cpp Wed Mar 
15 13:41:11 2017
@@ -0,0 +1,18 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+//   The strings's value type must be the same as the traits's char_type
+
+#include 
+
+int main()
+{
+std::basic_string> s;
+}

Removed: libcxx/trunk/test/std/strings/string.view/nothing_to_do.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/string.view/nothing_to_do.pass.cpp?rev=297871&view=auto
==
--- libcxx/trunk/test/std/strings/string.view/nothing_to_do.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/string.view/nothing_to_do.pass.cpp (removed)
@@ -1,12 +0,0 @@
-//===--===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===--===//
-
-#include 
-
-int main () {}

Added: libcxx/trunk/test/std/strings/string.view/traits_mismatch.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/string.view/traits_mismatch.fail.cpp?rev=297872&

Re: LLVM Lab SVN mirror is behind

2017-03-15 Thread Tim Northover via cfe-commits
On 15 March 2017 at 10:19, Galina Kistanova via llvm-commits
 wrote:
> I'm looking at that. Hope we will get a solution by the next release time.

Moving to git at last would be ideal, but I wouldn't bet on it either.

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


[PATCH] D30854: [ASTMatchers] Add ObjC matchers for fundamental decls

2017-03-15 Thread Dave Lee via Phabricator via cfe-commits
kastiglione updated this revision to Diff 91914.
kastiglione added a comment.

Use ArrayRef


https://reviews.llvm.org/D30854

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

Index: unittests/ASTMatchers/ASTMatchersTest.h
===
--- unittests/ASTMatchers/ASTMatchersTest.h
+++ unittests/ASTMatchers/ASTMatchersTest.h
@@ -61,7 +61,7 @@
 template 
 testing::AssertionResult matchesConditionally(
 const std::string &Code, const T &AMatcher, bool ExpectMatch,
-llvm::StringRef CompileArg,
+llvm::ArrayRef CompileArgs,
 const FileContentMappings &VirtualMappedFiles = FileContentMappings(),
 const std::string &Filename = "input.cc") {
   bool Found = false, DynamicFound = false;
@@ -81,8 +81,9 @@
   // FIXME: This is a hack to work around the fact that there's no way to do the
   // equivalent of runToolOnCodeWithArgs without instantiating a full Driver.
   // We should consider having a function, at least for tests, that invokes cc1.
-  std::vector Args = {CompileArg, "-frtti", "-fexceptions",
-   "-target", "i386-unknown-unknown"};
+  std::vector Args(CompileArgs.begin(), CompileArgs.end());
+  Args.insert(Args.end(), {"-frtti", "-fexceptions",
+   "-target", "i386-unknown-unknown"});
   if (!runToolOnCodeWithArgs(
   Factory->create(), Code, Args, Filename, "clang-tool",
   std::make_shared(), VirtualMappedFiles)) {
@@ -105,6 +106,17 @@
 }
 
 template 
+testing::AssertionResult matchesConditionally(
+const std::string &Code, const T &AMatcher, bool ExpectMatch,
+llvm::StringRef CompileArg,
+const FileContentMappings &VirtualMappedFiles = FileContentMappings(),
+const std::string &Filename = "input.cc") {
+  return matchesConditionally(
+Code, AMatcher, ExpectMatch, llvm::makeArrayRef(CompileArg),
+VirtualMappedFiles, Filename);
+}
+
+template 
 testing::AssertionResult matches(const std::string &Code, const T &AMatcher) {
   return matchesConditionally(Code, AMatcher, true, "-std=c++11");
 }
@@ -117,10 +129,13 @@
 
 template 
 testing::AssertionResult matchesObjC(const std::string &Code,
- const T &AMatcher) {
+ const T &AMatcher,
+ bool ExpectMatch = true) {
   return matchesConditionally(
-Code, AMatcher, true,
-"", FileContentMappings(), "input.m");
+Code, AMatcher, ExpectMatch,
+{"-fobjc-nonfragile-abi",
+ "-Wno-objc-root-class", "-Wno-incomplete-implementation"},
+FileContentMappings(), "input.m");
 }
 
 template 
@@ -145,10 +160,8 @@
 
 template 
 testing::AssertionResult notMatchesObjC(const std::string &Code,
- const T &AMatcher) {
-  return matchesConditionally(
-Code, AMatcher, false,
-"", FileContentMappings(), "input.m");
+const T &AMatcher) {
+  return matchesObjC(Code, AMatcher, false);
 }
 
 
Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1500,9 +1500,10 @@
 
   std::string Objc1String =
 "@interface Str "
-  " - (Str *)uppercaseString:(Str *)str;"
+  " - (Str *)uppercaseString;"
   "@end "
   "@interface foo "
+  "- (void)contents;"
   "- (void)meth:(Str *)text;"
   "@end "
   " "
@@ -1540,5 +1541,45 @@
 )));
 }
 
+TEST(ObjCDeclMacher, CoreDecls) {
+  std::string ObjCString =
+"@protocol Proto "
+"- (void)protoDidThing; "
+"@end "
+"@interface Thing "
+"@property int enabled; "
+"@end "
+"@interface Thing (ABC) "
+"- (void)abc_doThing; "
+"@end "
+"@implementation Thing "
+"{ id _ivar; } "
+"- (void)anything {} "
+"@end "
+;
+
+  EXPECT_TRUE(matchesObjC(
+ObjCString,
+objcProtocolDecl(hasName("Proto";
+  EXPECT_TRUE(matchesObjC(
+ObjCString,
+objcCategoryDecl(hasName("ABC";
+  EXPECT_TRUE(matchesObjC(
+ObjCString,
+objcMethodDecl(hasName("protoDidThing";
+  EXPECT_TRUE(matchesObjC(
+ObjCString,
+objcMethodDecl(hasName("abc_doThing";
+  EXPECT_TRUE(matchesObjC(
+ObjCString,
+objcMethodDecl(hasName("anything";
+  EXPECT_TRUE(matchesObjC(
+ObjCString,
+objcIvarDecl(hasName("_ivar";
+  EXPECT_TRUE(matchesObjC(
+ObjCString,
+objcPropertyDecl(hasName("enabled";
+}
+
 } // namespace ast_matchers
 } // namespace clang
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.c

[PATCH] D30854: [ASTMatchers] Add ObjC matchers for fundamental decls

2017-03-15 Thread Dave Lee via Phabricator via cfe-commits
kastiglione added inline comments.



Comment at: unittests/ASTMatchers/ASTMatchersTest.h:64
 const std::string &Code, const T &AMatcher, bool ExpectMatch,
-llvm::StringRef CompileArg,
+std::vector Args,
 const FileContentMappings &VirtualMappedFiles = FileContentMappings(),

aaron.ballman wrote:
> kastiglione wrote:
> > aaron.ballman wrote:
> > > I think this might be better as an `llvm::ArrayRef`.
> > Ok. It needs to be a `std::vector` for 
> > `runToolOnCodeWithArgs()`. I don't see any built in way to do that 
> > conversion, so this function will have to manually do that I guess?
> Can you do:
> ```
> std::vector LocalArgs(Args.begin(), Args.end());
> LocalArgs.insert(LocalArgs.end(), {"everything else"});
> ```
> below?
right, thanks!


https://reviews.llvm.org/D30854



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


[PATCH] D30854: [ASTMatchers] Add ObjC matchers for fundamental decls

2017-03-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM! I'll go ahead and commit for you.




Comment at: unittests/ASTMatchers/ASTMatchersTest.h:114
+const std::string &Filename = "input.cc") {
+  return matchesConditionally(
+Code, AMatcher, ExpectMatch, llvm::makeArrayRef(CompileArg),

The formatting of this line is incorrect, but I can fix it when I commit.


https://reviews.llvm.org/D30854



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


r297881 - Fix uninitialized value.

2017-03-15 Thread Zachary Turner via cfe-commits
Author: zturner
Date: Wed Mar 15 14:54:25 2017
New Revision: 297881

URL: http://llvm.org/viewvc/llvm-project?rev=297881&view=rev
Log:
Fix uninitialized value.

Modified:
cfe/trunk/lib/Driver/ToolChains/MSVC.h

Modified: cfe/trunk/lib/Driver/ToolChains/MSVC.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/MSVC.h?rev=297881&r1=297880&r2=297881&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/MSVC.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/MSVC.h Wed Mar 15 14:54:25 2017
@@ -130,7 +130,7 @@ protected:
   Tool *buildAssembler() const override;
 private:
   std::string VCToolChainPath;
-  bool IsVS2017OrNewer;
+  bool IsVS2017OrNewer = false;
   CudaInstallationDetector CudaInstallation;
 };
 


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


[PATCH] D30854: [ASTMatchers] Add ObjC matchers for fundamental decls

2017-03-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

I've commit in r297882, thanks!


https://reviews.llvm.org/D30854



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


r297882 - Add AST matchers for ObjCProtocolDecl, ObjCCategoryDecl, ObjCMethodDecl, ObjCIvarDecl, and ObjCPropertyDecl.

2017-03-15 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Wed Mar 15 15:14:25 2017
New Revision: 297882

URL: http://llvm.org/viewvc/llvm-project?rev=297882&view=rev
Log:
Add AST matchers for ObjCProtocolDecl, ObjCCategoryDecl, ObjCMethodDecl, 
ObjCIvarDecl, and ObjCPropertyDecl.

Patch by Dave Lee.

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

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=297882&r1=297881&r2=297882&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Wed Mar 15 15:14:25 2017
@@ -337,6 +337,15 @@ nonTypeTemplateParmDecl()
 
 
 
+MatcherDecl>objcCategoryDeclMatcherObjCCategoryDecl>...
+Matches 
Objective-C category declarations.
+
+Example matches Foo (Additions)
+  @interface Foo (Additions)
+  @end
+
+
+
 MatcherDecl>objcInterfaceDeclMatcherObjCInterfaceDecl>...
 Matches 
Objective-C interface declarations.
 
@@ -345,6 +354,50 @@ Example matches Foo
   @end
 
 
+
+MatcherDecl>objcIvarDeclMatcherObjCIvarDecl>...
+Matches Objective-C 
instance variable declarations.
+
+Example matches _enabled
+  @implementation Foo {
+BOOL _enabled;
+  }
+  @end
+
+
+
+MatcherDecl>objcMethodDeclMatcherObjCMethodDecl>...
+Matches Objective-C 
method declarations.
+
+Example matches both declaration and definition of -[Foo method]
+  @interface Foo
+  - (void)method;
+  @end
+
+  @implementation Foo
+  - (void)method {}
+  @end
+
+
+
+MatcherDecl>objcPropertyDeclMatcherObjCPropertyDecl>...
+Matches 
Objective-C property declarations.
+
+Example matches enabled
+  @interface Foo
+  @property BOOL enabled;
+  @end
+
+
+
+MatcherDecl>objcProtocolDeclMatcherObjCProtocolDecl>...
+Matches 
Objective-C protocol declarations.
+
+Example matches FooDelegate
+  @protocol FooDelegate
+  @end
+
+
 
 MatcherDecl>parmVarDeclMatcherParmVarDecl>...
 Matches parameter 
variable declarations.

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=297882&r1=297881&r2=297882&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Wed Mar 15 15:14:25 2017
@@ -1118,6 +1118,69 @@ const internal::VariadicDynCastAllOfMatc
   Decl,
   ObjCInterfaceDecl> objcInterfaceDecl;
 
+/// \brief Matches Objective-C protocol declarations.
+///
+/// Example matches FooDelegate
+/// \code
+///   @protocol FooDelegate
+///   @end
+/// \endcode
+const internal::VariadicDynCastAllOfMatcher<
+  Decl,
+  ObjCProtocolDecl> objcProtocolDecl;
+
+/// \brief Matches Objective-C category declarations.
+///
+/// Example matches Foo (Additions)
+/// \code
+///   @interface Foo (Additions)
+///   @end
+/// \endcode
+const internal::VariadicDynCastAllOfMatcher<
+  Decl,
+  ObjCCategoryDecl> objcCategoryDecl;
+
+/// \brief Matches Objective-C method declarations.
+///
+/// Example matches both declaration and definition of -[Foo method]
+/// \code
+///   @interface Foo
+///   - (void)method;
+///   @end
+///
+///   @implementation Foo
+///   - (void)method {}
+///   @end
+/// \endcode
+const internal::VariadicDynCastAllOfMatcher<
+  Decl,
+  ObjCMethodDecl> objcMethodDecl;
+
+/// \brief Matches Objective-C instance variable declarations.
+///
+/// Example matches _enabled
+/// \code
+///   @implementation Foo {
+/// BOOL _enabled;
+///   }
+///   @end
+/// \endcode
+const internal::VariadicDynCastAllOfMatcher<
+  Decl,
+  ObjCIvarDecl> objcIvarDecl;
+
+/// \brief Matches Objective-C property declarations.
+///
+/// Example matches enabled
+/// \code
+///   @interface Foo
+///   @property BOOL enabled;
+///   @end
+/

[PATCH] D30932: [clang-format] disabled adding extra space after MSVC '__super' keyword

2017-03-15 Thread Juliusz Toczydłowski via Phabricator via cfe-commits
jutocz added a comment.

As this is my first patch, can someone please help me in commiting it?


https://reviews.llvm.org/D30932



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


r297885 - [X86][XOP] Add codegen tests for vector integer comparison intrinsics (PR15844)

2017-03-15 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Wed Mar 15 15:20:43 2017
New Revision: 297885

URL: http://llvm.org/viewvc/llvm-project?rev=297885&view=rev
Log:
[X86][XOP] Add codegen tests for vector integer comparison intrinsics (PR15844)

We were testing for the generic _mm_com_* intrinsics, but not the specific 
comparison mode versions.

Added:
cfe/trunk/test/CodeGen/xop-builtins-cmp.c   (with props)

Added: cfe/trunk/test/CodeGen/xop-builtins-cmp.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/xop-builtins-cmp.c?rev=297885&view=auto
==
--- cfe/trunk/test/CodeGen/xop-builtins-cmp.c (added)
+++ cfe/trunk/test/CodeGen/xop-builtins-cmp.c Wed Mar 15 15:20:43 2017
@@ -0,0 +1,405 @@
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +xop -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +xop -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck 
%s
+
+
+#include 
+
+// _MM_PCOMCTRL_LT
+
+__m128i test_mm_comlt_epu8(__m128i a, __m128i b) {
+  // CHECK-LABEL: test_mm_comlt_epu8
+  // CHECK: call <16 x i8> @llvm.x86.xop.vpcomub(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}}, i8 0)
+  return _mm_comlt_epu8(a, b);
+}
+
+__m128i test_mm_comlt_epu16(__m128i a, __m128i b) {
+  // CHECK-LABEL: test_mm_comlt_epu16
+  // CHECK: call <8 x i16> @llvm.x86.xop.vpcomuw(<8 x i16> %{{.*}}, <8 x i16> 
%{{.*}}, i8 0)
+  return _mm_comlt_epu16(a, b);
+}
+
+__m128i test_mm_comlt_epu32(__m128i a, __m128i b) {
+  // CHECK-LABEL: test_mm_comlt_epu32
+  // CHECK: call <4 x i32> @llvm.x86.xop.vpcomud(<4 x i32> %{{.*}}, <4 x i32> 
%{{.*}}, i8 0)
+  return _mm_comlt_epu32(a, b);
+}
+
+__m128i test_mm_comlt_epu64(__m128i a, __m128i b) {
+  // CHECK-LABEL: test_mm_comlt_epu64
+  // CHECK: call <2 x i64> @llvm.x86.xop.vpcomuq(<2 x i64> %{{.*}}, <2 x i64> 
%{{.*}}, i8 0)
+  return _mm_comlt_epu64(a, b);
+}
+
+__m128i test_mm_comlt_epi8(__m128i a, __m128i b) {
+  // CHECK-LABEL: test_mm_comlt_epi8
+  // CHECK: call <16 x i8> @llvm.x86.xop.vpcomb(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}}, i8 0)
+  return _mm_comlt_epi8(a, b);
+}
+
+__m128i test_mm_comlt_epi16(__m128i a, __m128i b) {
+  // CHECK-LABEL: test_mm_comlt_epi16
+  // CHECK: call <8 x i16> @llvm.x86.xop.vpcomw(<8 x i16> %{{.*}}, <8 x i16> 
%{{.*}}, i8 0)
+  return _mm_comlt_epi16(a, b);
+}
+
+__m128i test_mm_comlt_epi32(__m128i a, __m128i b) {
+  // CHECK-LABEL: test_mm_comlt_epi32
+  // CHECK: call <4 x i32> @llvm.x86.xop.vpcomd(<4 x i32> %{{.*}}, <4 x i32> 
%{{.*}}, i8 0)
+  return _mm_comlt_epi32(a, b);
+}
+
+__m128i test_mm_comlt_epi64(__m128i a, __m128i b) {
+  // CHECK-LABEL: test_mm_comlt_epi64
+  // CHECK: call <2 x i64> @llvm.x86.xop.vpcomq(<2 x i64> %{{.*}}, <2 x i64> 
%{{.*}}, i8 0)
+  return _mm_comlt_epi64(a, b);
+}
+
+// _MM_PCOMCTRL_LE
+
+__m128i test_mm_comle_epu8(__m128i a, __m128i b) {
+  // CHECK-LABEL: test_mm_comle_epu8
+  // CHECK: call <16 x i8> @llvm.x86.xop.vpcomub(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}}, i8 1)
+  return _mm_comle_epu8(a, b);
+}
+
+__m128i test_mm_comle_epu16(__m128i a, __m128i b) {
+  // CHECK-LABEL: test_mm_comle_epu16
+  // CHECK: call <8 x i16> @llvm.x86.xop.vpcomuw(<8 x i16> %{{.*}}, <8 x i16> 
%{{.*}}, i8 1)
+  return _mm_comle_epu16(a, b);
+}
+
+__m128i test_mm_comle_epu32(__m128i a, __m128i b) {
+  // CHECK-LABEL: test_mm_comle_epu32
+  // CHECK: call <4 x i32> @llvm.x86.xop.vpcomud(<4 x i32> %{{.*}}, <4 x i32> 
%{{.*}}, i8 1)
+  return _mm_comle_epu32(a, b);
+}
+
+__m128i test_mm_comle_epu64(__m128i a, __m128i b) {
+  // CHECK-LABEL: test_mm_comle_epu64
+  // CHECK: call <2 x i64> @llvm.x86.xop.vpcomuq(<2 x i64> %{{.*}}, <2 x i64> 
%{{.*}}, i8 1)
+  return _mm_comle_epu64(a, b);
+}
+
+__m128i test_mm_comle_epi8(__m128i a, __m128i b) {
+  // CHECK-LABEL: test_mm_comle_epi8
+  // CHECK: call <16 x i8> @llvm.x86.xop.vpcomb(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}}, i8 1)
+  return _mm_comle_epi8(a, b);
+}
+
+__m128i test_mm_comle_epi16(__m128i a, __m128i b) {
+  // CHECK-LABEL: test_mm_comle_epi16
+  // CHECK: call <8 x i16> @llvm.x86.xop.vpcomw(<8 x i16> %{{.*}}, <8 x i16> 
%{{.*}}, i8 1)
+  return _mm_comle_epi16(a, b);
+}
+
+__m128i test_mm_comle_epi32(__m128i a, __m128i b) {
+  // CHECK-LABEL: test_mm_comle_epi32
+  // CHECK: call <4 x i32> @llvm.x86.xop.vpcomd(<4 x i32> %{{.*}}, <4 x i32> 
%{{.*}}, i8 1)
+  return _mm_comle_epi32(a, b);
+}
+
+__m128i test_mm_comle_epi64(__m128i a, __m128i b) {
+  // CHECK-LABEL: test_mm_comle_epi64
+  // CHECK: call <2 x i64> @llvm.x86.xop.vpcomq(<2 x i64> %{{.*}}, <2 x i64> 
%{{.*}}, i8 1)
+  return _mm_comle_epi64(a, b);
+}
+
+// _MM_PCOMCTRL_GT
+
+__m128i test_mm_comgt_epu8(__m128i a, __m128i b) {
+  // CHECK-LABEL: test_mm_comgt_epu8
+  // CHECK: call <16 x i8> @llvm.x86.xop.vpcomub(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}}, i8 2)
+  return _mm_comgt_epu8(a, b);
+}
+
+__m128i test_mm_comgt_epu16(__m128i a, __m128i b) {
+  // CHECK-L

[PATCH] D30990: Add more examples to clang-format configuration

2017-03-15 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru updated this revision to Diff 91925.
sylvestre.ledru added a comment.

More example (JS)


https://reviews.llvm.org/D30990

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h

Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -204,7 +204,7 @@
   bool AllowShortLoopsOnASingleLine;
 
   /// \brief Different ways to break after the function definition return type.
-  /// This option is deprecated and is retained for backwards compatibility.
+  /// This option is **deprecated** and is retained for backwards compatibility.
   enum DefinitionReturnTypeBreakingStyle {
 /// Break after return type automatically.
 /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
@@ -287,7 +287,7 @@
   };
 
   /// \brief The function definition return type breaking style to use.  This
-  /// option is deprecated and is retained for backwards compatibility.
+  /// option is **deprecated** and is retained for backwards compatibility.
   DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType;
 
   /// \brief The function declaration return type breaking style to use.
@@ -318,19 +318,73 @@
 
   /// \brief If ``false``, a function call's arguments will either be all on the
   /// same line or will have one line each.
+  /// \code
+  ///   true:
+  ///   void f() {
+  /// f(, ,
+  ///   aaa);
+  ///   }
+  ///
+  ///   false:
+  ///   void f() {
+  /// f(,
+  ///   ,
+  ///   aaa);
+  ///   }
+  /// \endcode
   bool BinPackArguments;
 
   /// \brief If ``false``, a function declaration's or function definition's
   /// parameters will either all be on the same line or will have one line each.
+  /// \code
+  ///   true:
+  ///   void f(int , int ,
+  ///  int aaa) {}
+  ///
+  ///   false:
+  ///   void f(int ,
+  ///  int ,
+  ///  int aaa) {}
+  /// \endcode
   bool BinPackParameters;
 
   /// \brief The style of breaking before or after binary operators.
   enum BinaryOperatorStyle {
 /// Break after operators.
+/// \code
+///LooongType loongVariable =
+///someLongFunction();
+///
+///bool value = a +
+/// a ==
+/// a &&
+/// a >
+/// c;
+/// \endcode
 BOS_None,
 /// Break before operators that aren't assignments.
+/// \code
+///LooongType loongVariable =
+///someLongFunction();
+///
+///bool value = a
+/// + a
+/// == a
+/// && a
+///> c;
+/// \endcode
 BOS_NonAssignment,
 /// Break before operators.
+/// \code
+///LooongType loongVariable
+///= someLongFunction();
+///
+///bool value = a
+/// + a
+/// == a
+/// && a
+///> c;
+/// \endcode
 BOS_All,
   };
 
@@ -665,6 +719,11 @@
 
   /// \brief A regular expression that describes comments with special meaning,
   /// which should not be split into lines or otherwise changed.
+  /// \code
+  ///CommentPragmas: '^ FOOBAR pragma:'
+  ///// Will leave the following line unaffected
+  ///#include  // FOOBAR pragma: keep
+  /// \endcode
   std::string CommentPragmas;
 
   /// \brief If ``true``, in the class inheritance expression clang-format will
@@ -824,6 +883,15 @@
   bool IndentCaseLabels;
 
   /// \brief The number of columns to use for indentation.
+  /// \code
+  ///IndentWidth: 3
+  ///void f() {
+  ///   someFunction();
+  ///   if (true, false) {
+  ///  f();
+  ///   }
+  ///}
+  /// \endcode
   unsigned IndentWidth;
 
  

[PATCH] D30283: [ubsan] Reduce alignment checking of C++ object pointers

2017-03-15 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

I'm not sure we actually want to skip these checks for DeclRefExps.  I mean, 
you can rely on the backend to correctly align a local variable (assuming the 
stack is correctly aligned), but it's very easy to misalign a global.


https://reviews.llvm.org/D30283



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


[PATCH] D30990: Add more examples to clang-format configuration

2017-03-15 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru updated this revision to Diff 91928.
sylvestre.ledru added a comment.

Improve consistency on an example


https://reviews.llvm.org/D30990

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h

Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -204,7 +204,7 @@
   bool AllowShortLoopsOnASingleLine;
 
   /// \brief Different ways to break after the function definition return type.
-  /// This option is deprecated and is retained for backwards compatibility.
+  /// This option is **deprecated** and is retained for backwards compatibility.
   enum DefinitionReturnTypeBreakingStyle {
 /// Break after return type automatically.
 /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
@@ -287,7 +287,7 @@
   };
 
   /// \brief The function definition return type breaking style to use.  This
-  /// option is deprecated and is retained for backwards compatibility.
+  /// option is **deprecated** and is retained for backwards compatibility.
   DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType;
 
   /// \brief The function declaration return type breaking style to use.
@@ -318,19 +318,73 @@
 
   /// \brief If ``false``, a function call's arguments will either be all on the
   /// same line or will have one line each.
+  /// \code
+  ///   true:
+  ///   void f() {
+  /// f(, ,
+  ///   aaa);
+  ///   }
+  ///
+  ///   false:
+  ///   void f() {
+  /// f(,
+  ///   ,
+  ///   aaa);
+  ///   }
+  /// \endcode
   bool BinPackArguments;
 
   /// \brief If ``false``, a function declaration's or function definition's
   /// parameters will either all be on the same line or will have one line each.
+  /// \code
+  ///   true:
+  ///   void f(int , int ,
+  ///  int aaa) {}
+  ///
+  ///   false:
+  ///   void f(int ,
+  ///  int ,
+  ///  int aaa) {}
+  /// \endcode
   bool BinPackParameters;
 
   /// \brief The style of breaking before or after binary operators.
   enum BinaryOperatorStyle {
 /// Break after operators.
+/// \code
+///LooongType loongVariable =
+///someLongFunction();
+///
+///bool value = a +
+/// a ==
+/// a &&
+/// a >
+/// c;
+/// \endcode
 BOS_None,
 /// Break before operators that aren't assignments.
+/// \code
+///LooongType loongVariable =
+///someLongFunction();
+///
+///bool value = a
+/// + a
+/// == a
+/// && a
+///> c;
+/// \endcode
 BOS_NonAssignment,
 /// Break before operators.
+/// \code
+///LooongType loongVariable
+///= someLongFunction();
+///
+///bool value = a
+/// + a
+/// == a
+/// && a
+///> c;
+/// \endcode
 BOS_All,
   };
 
@@ -665,6 +719,11 @@
 
   /// \brief A regular expression that describes comments with special meaning,
   /// which should not be split into lines or otherwise changed.
+  /// \code
+  ///CommentPragmas: '^ FOOBAR pragma:'
+  ///// Will leave the following line unaffected
+  ///#include  // FOOBAR pragma: keep
+  /// \endcode
   std::string CommentPragmas;
 
   /// \brief If ``true``, in the class inheritance expression clang-format will
@@ -824,6 +883,15 @@
   bool IndentCaseLabels;
 
   /// \brief The number of columns to use for indentation.
+  /// \code
+  ///IndentWidth: 3
+  ///void f() {
+  ///   someFunction();
+  ///   if (true, false) {
+  ///  f();
+  ///   }
+  ///}
+  /// \endcode
   unsigned I

r297890 - enable -save-temps with -finclude-defult-header

2017-03-15 Thread Guansong Zhang via cfe-commits
Author: guansong
Date: Wed Mar 15 15:57:11 2017
New Revision: 297890

URL: http://llvm.org/viewvc/llvm-project?rev=297890&view=rev
Log:
enable -save-temps with -finclude-defult-header

Currently the two flags can not work together.

To illustrate the issue, we can have an one line file a.cl contains only an 
empty function

cat a.cl

void test(){}

Then use

clang -v -save-temps -x cl -Xclang -cl-std=CL2.0 -Xclang 
-finclude-default-header -target amdgcn -S -c a.cl

we will get redefinition errors for various things.

The reason is that the -finclude-default-header flag is not meant to be on cc1 
command other than the preprocessor.

The fix is modeled after the code just below the change to filter the 
-finclude-default-header flag out when we are not in the preprocess phase.

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

Added:
cfe/trunk/test/Driver/include-default-header.cl
Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=297890&r1=297889&r2=297890&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Wed Mar 15 15:57:11 2017
@@ -4268,7 +4268,19 @@ void Clang::ConstructJob(Compilation &C,
 
   // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
   // parser.
-  Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
+  // -finclude-default-header flag is for preprocessor,
+  // do not pass it to other cc1 commands when save-temps is enabled
+  if (C.getDriver().isSaveTempsEnabled() &&
+  !isa(JA)) {
+for (auto Arg : Args.filtered(options::OPT_Xclang)) {
+  Arg->claim();
+  if (StringRef(Arg->getValue()) != "-finclude-default-header")
+CmdArgs.push_back(Arg->getValue());
+}
+  }
+  else {
+Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
+  }
   for (const Arg *A : Args.filtered(options::OPT_mllvm)) {
 A->claim();
 

Added: cfe/trunk/test/Driver/include-default-header.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/include-default-header.cl?rev=297890&view=auto
==
--- cfe/trunk/test/Driver/include-default-header.cl (added)
+++ cfe/trunk/test/Driver/include-default-header.cl Wed Mar 15 15:57:11 2017
@@ -0,0 +1,4 @@
+// RUN: %clang -v -save-temps -x cl -Xclang -cl-std=CL2.0 -Xclang 
-finclude-default-header -target amdgcn -S -c %s
+
+void test() {}
+


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


[PATCH] D30743: enable -save-temps with -finclude-defult-header

2017-03-15 Thread Guansong Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL297890: enable -save-temps with -finclude-defult-header 
(authored by guansong).

Changed prior to commit:
  https://reviews.llvm.org/D30743?vs=91718&id=91935#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30743

Files:
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/test/Driver/include-default-header.cl


Index: cfe/trunk/test/Driver/include-default-header.cl
===
--- cfe/trunk/test/Driver/include-default-header.cl
+++ cfe/trunk/test/Driver/include-default-header.cl
@@ -0,0 +1,4 @@
+// RUN: %clang -v -save-temps -x cl -Xclang -cl-std=CL2.0 -Xclang 
-finclude-default-header -target amdgcn -S -c %s
+
+void test() {}
+
Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -4268,7 +4268,19 @@
 
   // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
   // parser.
-  Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
+  // -finclude-default-header flag is for preprocessor,
+  // do not pass it to other cc1 commands when save-temps is enabled
+  if (C.getDriver().isSaveTempsEnabled() &&
+  !isa(JA)) {
+for (auto Arg : Args.filtered(options::OPT_Xclang)) {
+  Arg->claim();
+  if (StringRef(Arg->getValue()) != "-finclude-default-header")
+CmdArgs.push_back(Arg->getValue());
+}
+  }
+  else {
+Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
+  }
   for (const Arg *A : Args.filtered(options::OPT_mllvm)) {
 A->claim();
 


Index: cfe/trunk/test/Driver/include-default-header.cl
===
--- cfe/trunk/test/Driver/include-default-header.cl
+++ cfe/trunk/test/Driver/include-default-header.cl
@@ -0,0 +1,4 @@
+// RUN: %clang -v -save-temps -x cl -Xclang -cl-std=CL2.0 -Xclang -finclude-default-header -target amdgcn -S -c %s
+
+void test() {}
+
Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -4268,7 +4268,19 @@
 
   // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
   // parser.
-  Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
+  // -finclude-default-header flag is for preprocessor,
+  // do not pass it to other cc1 commands when save-temps is enabled
+  if (C.getDriver().isSaveTempsEnabled() &&
+  !isa(JA)) {
+for (auto Arg : Args.filtered(options::OPT_Xclang)) {
+  Arg->claim();
+  if (StringRef(Arg->getValue()) != "-finclude-default-header")
+CmdArgs.push_back(Arg->getValue());
+}
+  }
+  else {
+Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
+  }
   for (const Arg *A : Args.filtered(options::OPT_mllvm)) {
 A->claim();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r297896 - fix build break by removing the target on command line

2017-03-15 Thread Guansong Zhang via cfe-commits
Author: guansong
Date: Wed Mar 15 16:46:44 2017
New Revision: 297896

URL: http://llvm.org/viewvc/llvm-project?rev=297896&view=rev
Log:
fix build break by removing the target on command line

Modified:
cfe/trunk/test/Driver/include-default-header.cl

Modified: cfe/trunk/test/Driver/include-default-header.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/include-default-header.cl?rev=297896&r1=297895&r2=297896&view=diff
==
--- cfe/trunk/test/Driver/include-default-header.cl (original)
+++ cfe/trunk/test/Driver/include-default-header.cl Wed Mar 15 16:46:44 2017
@@ -1,4 +1,4 @@
-// RUN: %clang -v -save-temps -x cl -Xclang -cl-std=CL2.0 -Xclang 
-finclude-default-header -target amdgcn -S -c %s
+// RUN: %clang -v -save-temps -x cl -Xclang -cl-std=CL2.0 -Xclang 
-finclude-default-header -emit-llvm -c %s
 
 void test() {}
 


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


[PATCH] D30810: Preserve vec3 type.

2017-03-15 Thread JinGu Kang via Phabricator via cfe-commits
jaykang10 added a comment.

In https://reviews.llvm.org/D30810#701861, @Anastasia wrote:

> I don't think there is anything wrong with the generation of vec3->vec4 in 
> Clang. I believe the motivation for this was the OpenCL spec treating vec3 as 
> vec4 aligned type (see section 6.1.5: 
> https://www.khronos.org/registry/OpenCL/specs/opencl-2.0-openclc.pdf#12). So 
> in terms of memory layout vec3 wouldn't be any different to vec4. But in 
> terms of operations (including loads/stores) there can be potential gain from 
> not handling the 4th element.  This can be exploited by some targets. I think 
> generating the vec3 from the frontend would be a better choice in the first 
> place. Because backend can decide how to handle this. Including for 
> architectures with no SIMD support it would just generate 3 separate 
> loads/stores. Right now it seems that it will be forced to generate 4 
> loads/stores.
>
> But considering that transformation to vec4 has been the default 
> implementation for quite a while in the frontend, I think we would need a 
> stronger motivation for switching to original vec3. So current approach with 
> a special flag for preserving vec3 should be good enough to fit all needs.


Thank you, Anastasia. Can we go ahead and commit this patch?


https://reviews.llvm.org/D30810



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


[PATCH] D31003: [Objective-C] C++ Classes with __weak Members non-POD Types when using -fobjc-weak

2017-03-15 Thread Brian T. Kelley via Phabricator via cfe-commits
bkelley created this revision.

When adding an Objective-C retainable type member to a C++ class, also check 
the LangOpts.ObjCWeak flag and the lifetime qualifier so __weak qualified 
Objective-C pointer members cause the class to be a non-POD type with 
non-trivial special members, so the compiler always emits the necessary runtime 
calls for copying, moving, and destroying the weak member. Otherwise, 
Objective-C++ classes with weak Objective-C pointer members compiled with 
-fobjc-weak exhibit undefined behavior if the C++ class is classified as a POD 
type.


https://reviews.llvm.org/D31003

Files:
  lib/AST/DeclCXX.cpp
  lib/Sema/SemaDeclCXX.cpp
  test/CodeGenObjCXX/objc-weak.mm

Index: test/CodeGenObjCXX/objc-weak.mm
===
--- /dev/null
+++ test/CodeGenObjCXX/objc-weak.mm
@@ -0,0 +1,69 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-weak -fobjc-runtime-has-weak -std=c++11 -o - %s | FileCheck %s
+
+struct A { __weak id x; };
+
+id test0() {
+  A a;
+  A b = a;
+  A c(static_cast(b));
+  a = c;
+  c = static_cast(a);
+  return c.x;
+}
+
+// Copy Assignment Operator
+// CHECK-LABEL: define linkonce_odr dereferenceable({{[0-9]+}}) %struct.A* @_ZN1AaSERKS_(
+// CHECK:   [[THISADDR:%this.*]] = alloca [[A:.*]]*
+// CHECK:   [[OBJECTADDR:%.*]] = alloca [[A:.*]]*
+// CHECK:   [[THIS:%this.*]] = load [[A]]*, [[A]]** [[THISADDR]]
+// CHECK:   [[OBJECT:%.*]] = load [[A]]*, [[A]]** [[OBJECTADDR]]
+// CHECK:   [[T0:%.*]] = getelementptr inbounds [[A]], [[A]]* [[OBJECT]], i32 0, i32 0
+// CHECK-NEXT:  [[T1:%.*]] = call i8* @objc_loadWeak(i8** [[T0]])
+// CHECK-NEXT:  [[T2:%.*]] = getelementptr inbounds [[A]], [[A]]* [[THIS]], i32 0, i32 0
+// CHECK-NEXT:  [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[T2]], i8* [[T1]])
+
+// Move Assignment Operator
+// CHECK-LABEL: define linkonce_odr dereferenceable({{[0-9]+}}) %struct.A* @_ZN1AaSEOS_(
+// CHECK:   [[THISADDR:%this.*]] = alloca [[A:.*]]*
+// CHECK:   [[OBJECTADDR:%.*]] = alloca [[A:.*]]*
+// CHECK:   [[THIS:%this.*]] = load [[A]]*, [[A]]** [[THISADDR]]
+// CHECK:   [[OBJECT:%.*]] = load [[A]]*, [[A]]** [[OBJECTADDR]]
+// CHECK:   [[T0:%.*]] = getelementptr inbounds [[A]], [[A]]* [[OBJECT]], i32 0, i32 0
+// CHECK-NEXT:  [[T1:%.*]] = call i8* @objc_loadWeak(i8** [[T0]])
+// CHECK-NEXT:  [[T2:%.*]] = getelementptr inbounds [[A]], [[A]]* [[THIS]], i32 0, i32 0
+// CHECK-NEXT:  [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[T2]], i8* [[T1]])
+
+// Default Constructor
+// CHECK-LABEL: define linkonce_odr void @_ZN1AC2Ev(
+// CHECK:   [[THISADDR:%this.*]] = alloca [[A:.*]]*
+// CHECK:   [[THIS:%this.*]] = load [[A]]*, [[A]]** [[THISADDR]]
+// CHECK:   [[T0:%.*]] = getelementptr inbounds [[A]], [[A]]* [[THIS]], i32 0, i32 0
+// CHECK-NEXT:  store i8* null, i8** [[T0]]
+
+// Copy Constructor
+// CHECK-LABEL: define linkonce_odr void @_ZN1AC2ERKS_(
+// CHECK:   [[THISADDR:%this.*]] = alloca [[A:.*]]*
+// CHECK:   [[OBJECTADDR:%.*]] = alloca [[A:.*]]*
+// CHECK:   [[THIS:%this.*]] = load [[A]]*, [[A]]** [[THISADDR]]
+// CHECK:   [[T0:%.*]] = getelementptr inbounds [[A]], [[A]]* [[THIS]], i32 0, i32 0
+// CHECK-NEXT:  [[OBJECT:%.*]] = load [[A]]*, [[A]]** [[OBJECTADDR]]
+// CHECK-NEXT:  [[T1:%.*]] = getelementptr inbounds [[A]], [[A]]* [[OBJECT]], i32 0, i32 0
+// CHECK-NEXT:  call void @objc_copyWeak(i8** [[T0]], i8** [[T1]])
+
+// Move Constructor
+// CHECK-LABEL: define linkonce_odr void @_ZN1AC2EOS_(
+// CHECK:   [[THISADDR:%this.*]] = alloca [[A:.*]]*
+// CHECK:   [[OBJECTADDR:%.*]] = alloca [[A:.*]]*
+// CHECK:   [[THIS:%this.*]] = load [[A]]*, [[A]]** [[THISADDR]]
+// CHECK:   [[T0:%.*]] = getelementptr inbounds [[A]], [[A]]* [[THIS]], i32 0, i32 0
+// CHECK-NEXT:  [[OBJECT:%.*]] = load [[A]]*, [[A]]** [[OBJECTADDR]]
+// CHECK-NEXT:  [[T1:%.*]] = getelementptr inbounds [[A]], [[A]]* [[OBJECT]], i32 0, i32 0
+// CHECK-NEXT:  call void @objc_moveWeak(i8** [[T0]], i8** [[T1]])
+
+// Destructor
+// CHECK-LABEL: define linkonce_odr void @_ZN1AD2Ev(
+// CHECK:   [[THISADDR:%this.*]] = alloca [[A:.*]]*
+// CHECK:   [[THIS:%this.*]] = load [[A]]*, [[A]]** [[THISADDR]]
+// CHECK-NEXT:  [[T0:%.*]] = getelementptr inbounds [[A]], [[A]]* [[THIS]], i32 0, i32 0
+// CHECK-NEXT:  call void @objc_destroyWeak(i8** [[T0]])
+
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -4399,11 +4399,13 @@
 }
   }
   
-  if (SemaRef.getLangOpts().ObjCAutoRefCount &&
-  FieldBaseElementType->isObjCRetainableType() &&
-  FieldBaseElementType.getObjCLifetime() != Qualifiers::OCL_None &&
-  FieldBaseElementType.getObjCLifetime() != Qualifiers::OCL_ExplicitNone) {
-// ARC:
+  if (FieldBaseElementType->isObjCRetainableType() &&
+  ((SemaRef.getLangOpts().ObjCAutoRefCount &&
+FieldBa

[PATCH] D31004: [Objective-C] Fix __weak type traits with -fobjc-weak

2017-03-15 Thread Brian T. Kelley via Phabricator via cfe-commits
bkelley created this revision.

Similar to ARC, in ObjCWeak Objective-C object pointers qualified with a weak 
lifetime are not POD or trivial types. Update the type trait code to reflect 
this. Copy and adapt the arc-type-traits.mm test case to verify correctness.


https://reviews.llvm.org/D31004

Files:
  lib/AST/Type.cpp
  lib/Sema/SemaExprCXX.cpp
  test/SemaObjCXX/objc-weak-type-traits.mm

Index: test/SemaObjCXX/objc-weak-type-traits.mm
===
--- /dev/null
+++ test/SemaObjCXX/objc-weak-type-traits.mm
@@ -0,0 +1,210 @@
+// RUN: %clang_cc1 -fsyntax-only -fobjc-weak -fobjc-runtime-has-weak -verify -std=c++11 %s
+// expected-no-diagnostics
+
+// Check the results of the various type-trait query functions on
+// lifetime-qualified types in ObjC Weak.
+
+#define TRAIT_IS_TRUE(Trait, Type) static_assert(Trait(Type), "")
+#define TRAIT_IS_FALSE(Trait, Type) static_assert(!Trait(Type), "")
+#define TRAIT_IS_TRUE_2(Trait, Type1, Type2) static_assert(Trait(Type1, Type2), "")
+#define TRAIT_IS_FALSE_2(Trait, Type1, Type2) static_assert(!Trait(Type1, Type2), "")
+  
+struct HasStrong { id obj; };
+struct HasWeak { __weak id obj; };
+struct HasUnsafeUnretained { __unsafe_unretained id obj; };
+
+// __has_nothrow_assign
+TRAIT_IS_TRUE(__has_nothrow_assign, __strong id);
+TRAIT_IS_TRUE(__has_nothrow_assign, __weak id);
+TRAIT_IS_TRUE(__has_nothrow_assign, __autoreleasing id);
+TRAIT_IS_TRUE(__has_nothrow_assign, __unsafe_unretained id);
+TRAIT_IS_TRUE(__has_nothrow_assign, HasStrong);
+TRAIT_IS_TRUE(__has_nothrow_assign, HasWeak);
+TRAIT_IS_TRUE(__has_nothrow_assign, HasUnsafeUnretained);
+
+// __has_nothrow_copy
+TRAIT_IS_TRUE(__has_nothrow_copy, __strong id);
+TRAIT_IS_TRUE(__has_nothrow_copy, __weak id);
+TRAIT_IS_TRUE(__has_nothrow_copy, __autoreleasing id);
+TRAIT_IS_TRUE(__has_nothrow_copy, __unsafe_unretained id);
+TRAIT_IS_TRUE(__has_nothrow_copy, HasStrong);
+TRAIT_IS_TRUE(__has_nothrow_copy, HasWeak);
+TRAIT_IS_TRUE(__has_nothrow_copy, HasUnsafeUnretained);
+
+// __has_nothrow_constructor
+TRAIT_IS_TRUE(__has_nothrow_constructor, __strong id);
+TRAIT_IS_TRUE(__has_nothrow_constructor, __weak id);
+TRAIT_IS_TRUE(__has_nothrow_constructor, __autoreleasing id);
+TRAIT_IS_TRUE(__has_nothrow_constructor, __unsafe_unretained id);
+TRAIT_IS_TRUE(__has_nothrow_constructor, HasStrong);
+TRAIT_IS_TRUE(__has_nothrow_constructor, HasWeak);
+TRAIT_IS_TRUE(__has_nothrow_constructor, HasUnsafeUnretained);
+
+// __has_trivial_assign
+TRAIT_IS_TRUE(__has_trivial_assign, __strong id);
+TRAIT_IS_FALSE(__has_trivial_assign, __weak id);
+TRAIT_IS_TRUE(__has_trivial_assign, __autoreleasing id);
+TRAIT_IS_TRUE(__has_trivial_assign, __unsafe_unretained id);
+TRAIT_IS_TRUE(__has_trivial_assign, HasStrong);
+TRAIT_IS_FALSE(__has_trivial_assign, HasWeak);
+TRAIT_IS_TRUE(__has_trivial_assign, HasUnsafeUnretained);
+
+// __has_trivial_copy
+TRAIT_IS_TRUE(__has_trivial_copy, __strong id);
+TRAIT_IS_FALSE(__has_trivial_copy, __weak id);
+TRAIT_IS_TRUE(__has_trivial_copy, __autoreleasing id);
+TRAIT_IS_TRUE(__has_trivial_copy, __unsafe_unretained id);
+TRAIT_IS_TRUE(__has_trivial_copy, HasStrong);
+TRAIT_IS_FALSE(__has_trivial_copy, HasWeak);
+TRAIT_IS_TRUE(__has_trivial_copy, HasUnsafeUnretained);
+
+// __has_trivial_constructor
+TRAIT_IS_TRUE(__has_trivial_constructor, __strong id);
+TRAIT_IS_FALSE(__has_trivial_constructor, __weak id);
+TRAIT_IS_TRUE(__has_trivial_constructor, __autoreleasing id);
+TRAIT_IS_TRUE(__has_trivial_constructor, __unsafe_unretained id);
+TRAIT_IS_TRUE(__has_trivial_constructor, HasStrong);
+TRAIT_IS_FALSE(__has_trivial_constructor, HasWeak);
+TRAIT_IS_TRUE(__has_trivial_constructor, HasUnsafeUnretained);
+
+// __has_trivial_destructor
+TRAIT_IS_TRUE(__has_trivial_destructor, __strong id);
+TRAIT_IS_FALSE(__has_trivial_destructor, __weak id);
+TRAIT_IS_TRUE(__has_trivial_destructor, __autoreleasing id);
+TRAIT_IS_TRUE(__has_trivial_destructor, __unsafe_unretained id);
+TRAIT_IS_TRUE(__has_trivial_destructor, HasStrong);
+TRAIT_IS_FALSE(__has_trivial_destructor, HasWeak);
+TRAIT_IS_TRUE(__has_trivial_destructor, HasUnsafeUnretained);
+
+// __is_literal
+TRAIT_IS_TRUE(__is_literal, __strong id);
+TRAIT_IS_TRUE(__is_literal, __weak id);
+TRAIT_IS_TRUE(__is_literal, __autoreleasing id);
+TRAIT_IS_TRUE(__is_literal, __unsafe_unretained id);
+
+// __is_literal_type
+TRAIT_IS_TRUE(__is_literal_type, __strong id);
+TRAIT_IS_TRUE(__is_literal_type, __weak id);
+TRAIT_IS_TRUE(__is_literal_type, __autoreleasing id);
+TRAIT_IS_TRUE(__is_literal_type, __unsafe_unretained id);
+
+// __is_pod
+TRAIT_IS_TRUE(__is_pod, __strong id);
+TRAIT_IS_FALSE(__is_pod, __weak id);
+TRAIT_IS_TRUE(__is_pod, __autoreleasing id);
+TRAIT_IS_TRUE(__is_pod, __unsafe_unretained id);
+TRAIT_IS_TRUE(__is_pod, HasStrong);
+TRAIT_IS_FALSE(__is_pod, HasWeak);
+TRAIT_IS_TRUE(__is_pod, HasUnsafeUnretained);
+
+// __is_trivial
+TRAIT_IS_TRUE(__is_trivial, __strong id);
+TRAIT_IS_FALSE(__is_tr

[PATCH] D31005: [Objective-C] Fix "repeated use of weak" warning with -fobjc-weak

2017-03-15 Thread Brian T. Kelley via Phabricator via cfe-commits
bkelley created this revision.

-Warc-repeated-use-of-weak should produce the same warnings with -fobjc-weak as 
it does with -objc-arc. Also check for ObjCWeak along with ObjCAutoRefCount 
when recording the use of an evaluated weak variable. Add a -fobjc-weak run to 
the existing arc-repeated-weak test case and adapt it slightly to work in both 
modes.


https://reviews.llvm.org/D31005

Files:
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaExprMember.cpp
  lib/Sema/SemaExprObjC.cpp
  lib/Sema/SemaPseudoObject.cpp
  test/SemaObjC/arc-repeated-weak.mm

Index: test/SemaObjC/arc-repeated-weak.mm
===
--- test/SemaObjC/arc-repeated-weak.mm
+++ test/SemaObjC/arc-repeated-weak.mm
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -fblocks -Wno-objc-root-class -std=c++11 -Warc-repeated-use-of-weak -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-weak -fblocks -Wno-objc-root-class -std=c++11 -Warc-repeated-use-of-weak -verify %s
 
 @interface Test {
 @public
@@ -445,8 +446,8 @@
 @class NSString;
 @interface NSBundle
 +(NSBundle *)foo;
-@property (class) NSBundle *foo2;
-@property NSString *prop;
+@property (class, strong) NSBundle *foo2;
+@property (strong) NSString *prop;
 @property(weak) NSString *weakProp;
 @end
 
@@ -463,6 +464,8 @@
   use(NSBundle2.foo2.weakProp); // expected-note{{also accessed here}}
 }
 
+// With -fobjc-weak, the cast below is allowed.
+#if __has_feature(objc_arc)
 // This used to crash in the constructor of WeakObjectProfileTy when a
 // DeclRefExpr was passed that didn't reference a VarDecl.
 
@@ -475,3 +478,4 @@
 void foo1() {
   INTFPtrTy tmp = (INTFPtrTy)e1; // expected-error{{cast of 'E' to 'INTFPtrTy' (aka 'INTF *') is disallowed with ARC}}
 }
+#endif
Index: lib/Sema/SemaPseudoObject.cpp
===
--- lib/Sema/SemaPseudoObject.cpp
+++ lib/Sema/SemaPseudoObject.cpp
@@ -841,7 +841,7 @@
   result = S.ImpCastExprToType(result.get(), propType, CK_BitCast);
   }
 }
-if (S.getLangOpts().ObjCAutoRefCount) {
+if (S.getLangOpts().ObjCAutoRefCount || S.getLangOpts().ObjCWeak) {
   Qualifiers::ObjCLifetime LT = propType.getObjCLifetime();
   if (LT == Qualifiers::OCL_Weak)
 if (!S.Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, RefExpr->getLocation()))
@@ -962,11 +962,12 @@
 }
 
 ExprResult ObjCPropertyOpBuilder::complete(Expr *SyntacticForm) {
-  if (S.getLangOpts().ObjCAutoRefCount && isWeakProperty() &&
+  if ((S.getLangOpts().ObjCAutoRefCount || S.getLangOpts().ObjCWeak) &&
+  isWeakProperty() &&
   !S.Diags.isIgnored(diag::warn_arc_repeated_use_of_weak,
  SyntacticForm->getLocStart()))
-  S.recordUseOfEvaluatedWeak(SyntacticRefExpr,
- SyntacticRefExpr->isMessagingGetter());
+S.recordUseOfEvaluatedWeak(SyntacticRefExpr,
+   SyntacticRefExpr->isMessagingGetter());
 
   return PseudoOpBuilder::complete(SyntacticForm);
 }
Index: lib/Sema/SemaExprObjC.cpp
===
--- lib/Sema/SemaExprObjC.cpp
+++ lib/Sema/SemaExprObjC.cpp
@@ -3100,7 +3100,9 @@
 // In ARC, check for message sends which are likely to introduce
 // retain cycles.
 checkRetainCycles(Result);
+  }
 
+  if (getLangOpts().ObjCAutoRefCount || getLangOpts().ObjCWeak) {
 if (!isImplicit && Method) {
   if (const ObjCPropertyDecl *Prop = Method->findPropertyDecl()) {
 bool IsWeak =
Index: lib/Sema/SemaExprMember.cpp
===
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -1475,7 +1475,7 @@
   }
 }
 bool warn = true;
-if (S.getLangOpts().ObjCAutoRefCount) {
+if (S.getLangOpts().ObjCAutoRefCount || S.getLangOpts().ObjCWeak) {
   Expr *BaseExp = BaseExpr.get()->IgnoreParenImpCasts();
   if (UnaryOperator *UO = dyn_cast(BaseExp))
 if (UO->getOpcode() == UO_Deref)
@@ -1502,7 +1502,7 @@
 IV, IV->getUsageType(BaseType), MemberLoc, OpLoc, BaseExpr.get(),
 IsArrow);
 
-if (S.getLangOpts().ObjCAutoRefCount) {
+if (S.getLangOpts().ObjCAutoRefCount || S.getLangOpts().ObjCWeak) {
   if (IV->getType().getObjCLifetime() == Qualifiers::OCL_Weak) {
 if (!S.Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, MemberLoc))
   S.recordUseOfEvaluatedWeak(Result);
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -704,7 +704,7 @@
   
   // Loading a __weak object implicitly retains the value, so we need a cleanup to 
   // balance that.
-  if (getLangOpts().ObjCAutoRefCount &&
+  if ((getLangOpts().ObjCAutoRefCount || getLangOpts().ObjCWeak) &&
   E->getType().getObjCLifetime()

[PATCH] D31006: [Objective-C] Fix "weak-unavailable" warning with -fobjc-weak

2017-03-15 Thread Brian T. Kelley via Phabricator via cfe-commits
bkelley created this revision.

clang should produce the same errors Objective-C classes that cannot be 
assigned to weak pointers under both -fobjc-arc and -fobjc-weak. Check for 
ObjCWeak along with ObjCAutoRefCount when analyzing pointer conversions. Add an 
-fobjc-weak pass to the existing arc-unavailable-for-weakref test cases to 
verify the behavior is the same.


https://reviews.llvm.org/D31006

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaCast.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaExprObjC.cpp
  lib/Sema/SemaPseudoObject.cpp
  test/SemaObjC/arc-unavailable-for-weakref.m
  test/SemaObjCXX/arc-unavailable-for-weakref.mm

Index: test/SemaObjCXX/arc-unavailable-for-weakref.mm
===
--- test/SemaObjCXX/arc-unavailable-for-weakref.mm
+++ test/SemaObjCXX/arc-unavailable-for-weakref.mm
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify %s
+// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-weak -verify %s
 // rdar://9693477
 
 __attribute__((objc_arc_weak_reference_unavailable))
Index: test/SemaObjC/arc-unavailable-for-weakref.m
===
--- test/SemaObjC/arc-unavailable-for-weakref.m
+++ test/SemaObjC/arc-unavailable-for-weakref.m
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-weak -verify -Wno-objc-root-class %s
 // rdar://9693477
 
 __attribute__((objc_arc_weak_reference_unavailable))
Index: lib/Sema/SemaPseudoObject.cpp
===
--- lib/Sema/SemaPseudoObject.cpp
+++ lib/Sema/SemaPseudoObject.cpp
@@ -1128,8 +1128,8 @@
   if (!Getter)
 return;
   QualType T = Getter->parameters()[0]->getType();
-  S.CheckObjCARCConversion(Key->getSourceRange(), 
- T, Key, Sema::CCK_ImplicitConversion);
+  S.CheckObjCConversion(Key->getSourceRange(), T, Key,
+Sema::CCK_ImplicitConversion);
 }
 
 bool ObjCSubscriptOpBuilder::findAtIndexGetter() {
Index: lib/Sema/SemaExprObjC.cpp
===
--- lib/Sema/SemaExprObjC.cpp
+++ lib/Sema/SemaExprObjC.cpp
@@ -4108,11 +4108,10 @@
 }
 
 Sema::ARCConversionResult
-Sema::CheckObjCARCConversion(SourceRange castRange, QualType castType,
- Expr *&castExpr, CheckedConversionKind CCK,
- bool Diagnose,
- bool DiagnoseCFAudited,
- BinaryOperatorKind Opc) {
+Sema::CheckObjCConversion(SourceRange castRange, QualType castType,
+  Expr *&castExpr, CheckedConversionKind CCK,
+  bool Diagnose, bool DiagnoseCFAudited,
+  BinaryOperatorKind Opc) {
   QualType castExprType = castExpr->getType();
 
   // For the purposes of the classification, we assume reference types
@@ -4152,7 +4151,12 @@
 }
 return ACR_okay;
   }
-  
+
+  // The life-time qualifier cast check above is all we need for ObjCWeak.
+  // ObjCAutoRefCount has more restrictions on what is legal.
+  if (!getLangOpts().ObjCAutoRefCount)
+return ACR_okay;
+
   if (isAnyCLike(exprACTC) && isAnyCLike(castACTC)) return ACR_okay;
 
   // Allow all of these types to be cast to integer types (but not
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -3744,10 +3744,9 @@
   if (From->getType()->isObjCObjectPointerType() &&
   ToType->isObjCObjectPointerType())
 EmitRelatedResultTypeNote(From);
-}
-else if (getLangOpts().ObjCAutoRefCount &&
- !CheckObjCARCUnavailableWeakConversion(ToType,
-From->getType())) {
+} else if ((getLangOpts().ObjCAutoRefCount || getLangOpts().ObjCWeak) &&
+   !CheckObjCARCUnavailableWeakConversion(ToType,
+  From->getType())) {
   if (Action == AA_Initializing)
 Diag(From->getLocStart(),
  diag::err_arc_weak_unavailable_assign);
@@ -3770,8 +3769,8 @@
   (void) PrepareCastToObjCObjectPointer(E);
   From = E.get();
 }
-if (getLangOpts().ObjCAutoRefCount)
-  CheckObjCARCConversion(SourceRange(), ToType, From, CCK);
+if (getLangOpts().ObjCAutoRefCount || getLangOpts().ObjCWeak)
+  CheckObjCConversion(SourceRange(), ToType, From, CCK);
 From = ImpCastExprToType(From, ToType, Kind, VK_RValue, &BasePath, CCK)
  .get();
 break;
Index: lib/Sema/

[PATCH] D31005: [Objective-C] Fix "repeated use of weak" warning with -fobjc-weak

2017-03-15 Thread Jordan Rose via Phabricator via cfe-commits
jordan_rose added a reviewer: rjmccall.
jordan_rose added a subscriber: rjmccall.
jordan_rose added a comment.

The warning-related parts look reasonable to me.




Comment at: lib/Sema/SemaDecl.cpp:10184
+ (!getLangOpts().ObjCAutoRefCount && getLangOpts().ObjCWeak &&
+  VDecl->getType().getObjCLifetime() != Qualifiers::OCL_Weak)) &&
 !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak,

This condition's getting complicated, and it shows up in a few places. Would it 
make sense to factor it out?



Comment at: lib/Sema/SemaExpr.cpp:707
   // balance that.
-  if (getLangOpts().ObjCAutoRefCount &&
+  if ((getLangOpts().ObjCAutoRefCount || getLangOpts().ObjCWeak) &&
   E->getType().getObjCLifetime() == Qualifiers::OCL_Weak)

This is the one section that //isn't// dealing with the warning. I'd like 
@rjmccall to verify that it's correct.



Comment at: lib/Sema/SemaExpr.cpp:10340
 
-  } else if (getLangOpts().ObjCAutoRefCount) {
+  } else if (getLangOpts().ObjCAutoRefCount || getLangOpts().ObjCWeak) {
 checkUnsafeExprAssigns(Loc, LHSExpr, RHS.get());

Does ObjCAutoRefCount imply ObjCWeak? If so, you could just use the latter.


https://reviews.llvm.org/D31005



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


[PATCH] D31007: [Objective-C] Miscellaneous -fobjc-weak Fixes

2017-03-15 Thread Brian T. Kelley via Phabricator via cfe-commits
bkelley created this revision.

After examining the remaining uses of LangOptions.ObjCAutoRefCount, found a 
some additional places to also check for ObjCWeak not covered by previous test 
cases. Added a test file to verify all the code paths that were changed.


https://reviews.llvm.org/D31007

Files:
  lib/Sema/SemaCast.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaInit.cpp
  test/SemaObjCXX/objc-weak.mm

Index: test/SemaObjCXX/objc-weak.mm
===
--- /dev/null
+++ test/SemaObjCXX/objc-weak.mm
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-weak -fblocks -Wno-objc-root-class -std=c++98 -Wno-c++0x-extensions -verify %s
+
+@interface AnObject
+@property(weak) id value;
+@end
+
+__attribute__((objc_arc_weak_reference_unavailable))
+@interface NOWEAK : AnObject // expected-note 2 {{class is declared here}}
+@end
+
+struct S {
+  __weak id a; // expected-note {{because type 'S' has a member with __weak ownership}}
+};
+
+union U {
+  __weak id a; // expected-error {{ARC forbids Objective-C objects in union}}
+  S b; // expected-error {{union member 'b' has a non-trivial copy constructor}}
+};
+
+void testCast(AnObject *o) {
+  __weak id a = reinterpret_cast<__weak NOWEAK *>(o); // expected-error {{class is incompatible with __weak references}} \
+  // expected-error {{explicit ownership qualifier on cast result has no effect}} \
+  // expected-error {{assignment of a weak-unavailable object to a __weak object}}
+
+  __weak id b = static_cast<__weak NOWEAK *>(o); // expected-error {{class is incompatible with __weak references}} \
+ // expected-error {{explicit ownership qualifier on cast result has no effect}} \
+ // expected-error {{assignment of a weak-unavailable object to a __weak object}}
+}
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -6680,6 +6680,8 @@
   // full-expression's cleanups.
   if ((S.getLangOpts().ObjCAutoRefCount &&
MTE->getType()->isObjCLifetimeType()) ||
+  (S.getLangOpts().ObjCWeak &&
+   MTE->getType().getObjCLifetime() == Qualifiers::OCL_Weak) ||
   (MTE->getStorageDuration() == SD_Automatic &&
MTE->getType().isDestructedType()))
 S.Cleanup.setExprNeedsCleanups(true);
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -7150,8 +7150,10 @@
 //   [...] nontrivally ownership-qualified types are [...] not trivially
 //   default constructible, copy constructible, move constructible, copy
 //   assignable, move assignable, or destructible [...]
-if (S.getLangOpts().ObjCAutoRefCount &&
-FieldType.hasNonTrivialObjCLifetime()) {
+if ((S.getLangOpts().ObjCAutoRefCount &&
+ FieldType.hasNonTrivialObjCLifetime()) ||
+(S.getLangOpts().ObjCWeak &&
+ FieldType.getObjCLifetime() == Qualifiers::OCL_Weak)) {
   if (Diagnose)
 S.Diag(FI->getLocation(), diag::note_nontrivial_objc_ownership)
   << RD << FieldType.getObjCLifetime();
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -14493,7 +14493,7 @@
   // Verify that all the fields are okay.
   SmallVector RecFields;
 
-  bool ARCErrReported = false;
+  bool ObjCFieldLifetimeErrReported = false;
   for (ArrayRef::iterator i = Fields.begin(), end = Fields.end();
i != end; ++i) {
 FieldDecl *FD = cast(*i);
@@ -14628,16 +14628,20 @@
 << FixItHint::CreateInsertion(FD->getLocation(), "*");
   QualType T = Context.getObjCObjectPointerType(FD->getType());
   FD->setType(T);
-} else if (getLangOpts().ObjCAutoRefCount && Record && !ARCErrReported &&
+} else if ((getLangOpts().ObjCAutoRefCount || getLangOpts().ObjCWeak) &&
+   Record && !ObjCFieldLifetimeErrReported &&
(!getLangOpts().CPlusPlus || Record->isUnion())) {
-  // It's an error in ARC if a field has lifetime.
+  // It's an error in ARC or Weak if a field has lifetime.
   // We don't want to report this in a system header, though,
   // so we just make the field unavailable.
   // FIXME: that's really not sufficient; we need to make the type
   // itself invalid to, say, initialize or copy.
   QualType T = FD->getType();
   Qualifiers::ObjCLifetime lifetime = T.getObjCLifetime();
-  if (lifetime && lifetime != Qualifiers::OCL_ExplicitNone) {
+  if (lifetime &&
+  ((getLangOpts().ObjCAutoRefCount &&
+lifetime != Qua

r297905 - Remove repeated code (PR32250). NFCI.

2017-03-15 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Wed Mar 15 17:43:36 2017
New Revision: 297905

URL: http://llvm.org/viewvc/llvm-project?rev=297905&view=rev
Log:
Remove repeated code (PR32250). NFCI.

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorPastEndChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorPastEndChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorPastEndChecker.cpp?rev=297905&r1=297904&r2=297905&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorPastEndChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorPastEndChecker.cpp Wed Mar 15 
17:43:36 2017
@@ -415,8 +415,6 @@ bool IteratorPastEndChecker::evalCall(co
 return evalFindFirstOf(C, CE);
   } else if (FD->getIdentifier() == II_find_if) {
 return evalFindIf(C, CE);
-  } else if (FD->getIdentifier() == II_find_if) {
-return evalFindIf(C, CE);
   } else if (FD->getIdentifier() == II_find_if_not) {
 return evalFindIfNot(C, CE);
   } else if (FD->getIdentifier() == II_upper_bound) {


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


[PATCH] D31005: [Objective-C] Fix "repeated use of weak" warning with -fobjc-weak

2017-03-15 Thread Brian T. Kelley via Phabricator via cfe-commits
bkelley added inline comments.



Comment at: lib/Sema/SemaDecl.cpp:10184
+ (!getLangOpts().ObjCAutoRefCount && getLangOpts().ObjCWeak &&
+  VDecl->getType().getObjCLifetime() != Qualifiers::OCL_Weak)) &&
 !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak,

jordan_rose wrote:
> This condition's getting complicated, and it shows up in a few places. Would 
> it make sense to factor it out?
What do you think about adding a member function like 
`hasMRCNonTrivialWeakObjCLifetime(const ASTContext &Context)` to QualType to 
factor out lines 10183-10184? We could use that in D31003, D31004, here, and 
D31007.



Comment at: lib/Sema/SemaExpr.cpp:10340
 
-  } else if (getLangOpts().ObjCAutoRefCount) {
+  } else if (getLangOpts().ObjCAutoRefCount || getLangOpts().ObjCWeak) {
 checkUnsafeExprAssigns(Loc, LHSExpr, RHS.get());

jordan_rose wrote:
> Does ObjCAutoRefCount imply ObjCWeak? If so, you could just use the latter.
I don't believe so. For Snow Leopard, ARC without weak references was supported 
so they can be independent. 


https://reviews.llvm.org/D31005



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


[PATCH] D30848: Implement DR 373 "Lookup on namespace qualified name in using-directive"

2017-03-15 Thread Matthias Gehre via Phabricator via cfe-commits
mgehre updated this revision to Diff 91956.
mgehre added a comment.

Improve diagnostics and add tests for them.


https://reviews.llvm.org/D30848

Files:
  include/clang/Parse/Parser.h
  include/clang/Sema/Sema.h
  lib/Parse/ParseDeclCXX.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Sema/SemaCXXScopeSpec.cpp
  test/CXX/drs/dr3xx.cpp
  www/cxx_dr_status.html

Index: www/cxx_dr_status.html
===
--- www/cxx_dr_status.html
+++ www/cxx_dr_status.html
@@ -2279,7 +2279,7 @@
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#373";>373
 C++11
 Lookup on namespace qualified name in using-directive
-No
+SVN
   
   
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#374";>374
Index: test/CXX/drs/dr3xx.cpp
===
--- test/CXX/drs/dr3xx.cpp
+++ test/CXX/drs/dr3xx.cpp
@@ -908,18 +908,21 @@
   }
 }
 
-namespace dr373 { // dr373: no
-  // FIXME: This is valid.
-  namespace X { int dr373; } // expected-note 2{{here}}
+namespace dr373 { // dr373: 5
+  namespace X { int dr373; }
   struct dr373 { // expected-note {{here}}
 void f() {
-  using namespace dr373::X; // expected-error {{no namespace named 'X' in 'dr373::dr373'}}
+  using namespace dr373::X;
   int k = dr373; // expected-error {{does not refer to a value}}
 
-  namespace Y = dr373::X; // expected-error {{no namespace named 'X' in 'dr373::dr373'}}
+  namespace Y = dr373::X;
   k = Y::dr373;
 }
   };
+
+  struct A { struct B {}; }; // expected-note 2{{here}}
+  namespace X = A::B;   // expected-error {{expected namespace name}}
+  using namespace A::B; // expected-error {{expected namespace name}}
 }
 
 namespace dr374 { // dr374: yes c++11
Index: lib/Sema/SemaCXXScopeSpec.cpp
===
--- lib/Sema/SemaCXXScopeSpec.cpp
+++ lib/Sema/SemaCXXScopeSpec.cpp
@@ -461,6 +461,7 @@
 ///are allowed.  The bool value pointed by this parameter is set to
 ///   'true' if the identifier is treated as if it was followed by ':',
 ///not '::'.
+/// \param OnlyNamespace If true, only considers namespaces in lookup.
 ///
 /// This routine differs only slightly from ActOnCXXNestedNameSpecifier, in
 /// that it contains an extra parameter \p ScopeLookupResult, which provides
@@ -473,15 +474,15 @@
 /// scope if it *knows* that the result is correct.  It should not return in a
 /// dependent context, for example. Nor will it extend \p SS with the scope
 /// specifier.
-bool Sema::BuildCXXNestedNameSpecifier(Scope *S,
-   NestedNameSpecInfo &IdInfo,
-   bool EnteringContext,
-   CXXScopeSpec &SS,
+bool Sema::BuildCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo,
+   bool EnteringContext, CXXScopeSpec &SS,
NamedDecl *ScopeLookupResult,
bool ErrorRecoveryLookup,
-   bool *IsCorrectedToColon) {
+   bool *IsCorrectedToColon,
+   bool OnlyNamespace) {
   LookupResult Found(*this, IdInfo.Identifier, IdInfo.IdentifierLoc,
- LookupNestedNameSpecifierName);
+ OnlyNamespace ? LookupNamespaceName
+   : LookupNestedNameSpecifierName);
   QualType ObjectType = GetTypeFromParser(IdInfo.ObjectType);
 
   // Determine where to perform name lookup
@@ -594,7 +595,9 @@
 return true;
   }
   // Replacement '::' -> ':' is not allowed, just issue respective error.
-  Diag(R.getNameLoc(), diag::err_expected_class_or_namespace)
+  Diag(R.getNameLoc(), OnlyNamespace
+   ? diag::err_expected_namespace_name
+   : diag::err_expected_class_or_namespace)
   << IdInfo.Identifier << getLangOpts().CPlusPlus;
   if (NamedDecl *ND = R.getAsSingle())
 Diag(ND->getLocation(), diag::note_entity_declared_at)
@@ -819,19 +822,17 @@
   return true;
 }
 
-bool Sema::ActOnCXXNestedNameSpecifier(Scope *S,
-   NestedNameSpecInfo &IdInfo,
-   bool EnteringContext,
-   CXXScopeSpec &SS,
+bool Sema::ActOnCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo,
+   bool EnteringContext, CXXScopeSpec &SS,
bool ErrorRecoveryLookup,
-   bool *IsCorrectedToColon) {
+   bool *IsCorrectedToColon,
+   bool OnlyNamespace) {
   if (SS.isInvalid())
 return true;
 
-  return BuildCXX

r297917 - Fix up testcase to:

2017-03-15 Thread Eric Christopher via cfe-commits
Author: echristo
Date: Wed Mar 15 18:41:58 2017
New Revision: 297917

URL: http://llvm.org/viewvc/llvm-project?rev=297917&view=rev
Log:
Fix up testcase to:

a) avoid actually compiling anything
b) avoid depositing files in the test directory
c) use a check line to make sure that we're looking for the correct behavior

Modified:
cfe/trunk/test/Driver/include-default-header.cl

Modified: cfe/trunk/test/Driver/include-default-header.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/include-default-header.cl?rev=297917&r1=297916&r2=297917&view=diff
==
--- cfe/trunk/test/Driver/include-default-header.cl (original)
+++ cfe/trunk/test/Driver/include-default-header.cl Wed Mar 15 18:41:58 2017
@@ -1,4 +1,6 @@
-// RUN: %clang -v -save-temps -x cl -Xclang -cl-std=CL2.0 -Xclang 
-finclude-default-header -emit-llvm -c %s
+// RUN: %clang -save-temps -x cl -Xclang -cl-std=CL2.0 -Xclang 
-finclude-default-header -emit-llvm -S -### %s
+// CHECK-NOT: finclude-default-header
+// Make sure we don't pass -finclude-default-header to any commands other than 
the driver.
 
 void test() {}
 


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


Re: r297890 - enable -save-temps with -finclude-defult-header

2017-03-15 Thread Eric Christopher via cfe-commits
Hi Guansong,

So this wasn't quite the right way to write this testcase. You really
wanted a CHECK/CHECK-NOT line along with the actual commands. You also
didn't want to (as you noticed later) depend on full compilation. You can
check for this sort of thing in the future by using the -### command line
option to get the subcommands that clang -would- invoke if it were actually
going to do it.

I've gone ahead and fixed this thusly:
Committing to https://llvm.org/svn/llvm-project/cfe/trunk ...
M test/Driver/include-default-header.cl
Committed r297917

Thanks!

-eric

On Wed, Mar 15, 2017 at 2:09 PM Guansong Zhang via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: guansong
> Date: Wed Mar 15 15:57:11 2017
> New Revision: 297890
>
> URL: http://llvm.org/viewvc/llvm-project?rev=297890&view=rev
> Log:
> enable -save-temps with -finclude-defult-header
>
> Currently the two flags can not work together.
>
> To illustrate the issue, we can have an one line file a.cl contains only
> an empty function
>
> cat a.cl
>
> void test(){}
>
> Then use
>
> clang -v -save-temps -x cl -Xclang -cl-std=CL2.0 -Xclang
> -finclude-default-header -target amdgcn -S -c a.cl
>
> we will get redefinition errors for various things.
>
> The reason is that the -finclude-default-header flag is not meant to be on
> cc1 command other than the preprocessor.
>
> The fix is modeled after the code just below the change to filter the
> -finclude-default-header flag out when we are not in the preprocess phase.
>
> Differential Revision: https://reviews.llvm.org/D30743
>
> Added:
> cfe/trunk/test/Driver/include-default-header.cl
> Modified:
> cfe/trunk/lib/Driver/ToolChains/Clang.cpp
>
> Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=297890&r1=297889&r2=297890&view=diff
>
> ==
> --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Wed Mar 15 15:57:11 2017
> @@ -4268,7 +4268,19 @@ void Clang::ConstructJob(Compilation &C,
>
>// Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM
> option
>// parser.
> -  Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
> +  // -finclude-default-header flag is for preprocessor,
> +  // do not pass it to other cc1 commands when save-temps is enabled
> +  if (C.getDriver().isSaveTempsEnabled() &&
> +  !isa(JA)) {
> +for (auto Arg : Args.filtered(options::OPT_Xclang)) {
> +  Arg->claim();
> +  if (StringRef(Arg->getValue()) != "-finclude-default-header")
> +CmdArgs.push_back(Arg->getValue());
> +}
> +  }
> +  else {
> +Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
> +  }
>for (const Arg *A : Args.filtered(options::OPT_mllvm)) {
>  A->claim();
>
>
> Added: cfe/trunk/test/Driver/include-default-header.cl
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/include-default-header.cl?rev=297890&view=auto
>
> ==
> --- cfe/trunk/test/Driver/include-default-header.cl (added)
> +++ cfe/trunk/test/Driver/include-default-header.cl Wed Mar 15 15:57:11
> 2017
> @@ -0,0 +1,4 @@
> +// RUN: %clang -v -save-temps -x cl -Xclang -cl-std=CL2.0 -Xclang
> -finclude-default-header -target amdgcn -S -c %s
> +
> +void test() {}
> +
>
>
> ___
> 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] D30854: [ASTMatchers] Add ObjC matchers for fundamental decls

2017-03-15 Thread Dave Lee via Phabricator via cfe-commits
kastiglione added a comment.

@aaron.ballman @malcolm.parsons Thanks for the reviews and the commit. I plan 
to do follow ups for more ObjC ASTMatcher support.


https://reviews.llvm.org/D30854



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


[PATCH] D31005: [Objective-C] Fix "repeated use of weak" warning with -fobjc-weak

2017-03-15 Thread Jordan Rose via Phabricator via cfe-commits
jordan_rose added inline comments.



Comment at: lib/Sema/SemaDecl.cpp:10184
+ (!getLangOpts().ObjCAutoRefCount && getLangOpts().ObjCWeak &&
+  VDecl->getType().getObjCLifetime() != Qualifiers::OCL_Weak)) &&
 !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak,

bkelley wrote:
> jordan_rose wrote:
> > This condition's getting complicated, and it shows up in a few places. 
> > Would it make sense to factor it out?
> What do you think about adding a member function like 
> `hasMRCNonTrivialWeakObjCLifetime(const ASTContext &Context)` to QualType to 
> factor out lines 10183-10184? We could use that in D31003, D31004, here, and 
> D31007.
I'm fine with it myself but I don't work on Clang very much anymore. Maybe 
someone else can say whether it's actually a good idea.

(By the way, the conventional abbreviation for this mode is "MRR" for "Manual 
Retain/Release", even though it's "ARC" and "Automated Reference Counting".)



Comment at: lib/Sema/SemaExpr.cpp:10340
 
-  } else if (getLangOpts().ObjCAutoRefCount) {
+  } else if (getLangOpts().ObjCAutoRefCount || getLangOpts().ObjCWeak) {
 checkUnsafeExprAssigns(Loc, LHSExpr, RHS.get());

bkelley wrote:
> jordan_rose wrote:
> > Does ObjCAutoRefCount imply ObjCWeak? If so, you could just use the latter.
> I don't believe so. For Snow Leopard, ARC without weak references was 
> supported so they can be independent. 
Sure, but in that case we don't need the warning, right?


https://reviews.llvm.org/D31005



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


[PATCH] D30991: [Driver] Fix cross compiling with Visual Studio 2017

2017-03-15 Thread Hamza Sood via Phabricator via cfe-commits
hamzasood updated this revision to Diff 91962.
hamzasood added a comment.

Changed the call to GetEnvironmentStrings to use the unicode version


https://reviews.llvm.org/D30991

Files:
  include/clang/Driver/Job.h
  lib/Driver/Job.cpp
  lib/Driver/ToolChains/MSVC.cpp

Index: lib/Driver/ToolChains/MSVC.cpp
===
--- lib/Driver/ToolChains/MSVC.cpp
+++ lib/Driver/ToolChains/MSVC.cpp
@@ -45,17 +45,17 @@
   #endif
   #include 
 
-// Make sure this comes before MSVCSetupApi.h
-#include 
+  // Make sure this comes before MSVCSetupApi.h
+  #include 
 
-#include "MSVCSetupApi.h"
-#include "llvm/Support/COM.h"
-_COM_SMARTPTR_TYPEDEF(ISetupConfiguration, __uuidof(ISetupConfiguration));
-_COM_SMARTPTR_TYPEDEF(ISetupConfiguration2, __uuidof(ISetupConfiguration2));
-_COM_SMARTPTR_TYPEDEF(ISetupHelper, __uuidof(ISetupHelper));
-_COM_SMARTPTR_TYPEDEF(IEnumSetupInstances, __uuidof(IEnumSetupInstances));
-_COM_SMARTPTR_TYPEDEF(ISetupInstance, __uuidof(ISetupInstance));
-_COM_SMARTPTR_TYPEDEF(ISetupInstance2, __uuidof(ISetupInstance2));
+  #include "MSVCSetupApi.h"
+  #include "llvm/Support/COM.h"
+  _COM_SMARTPTR_TYPEDEF(ISetupConfiguration, __uuidof(ISetupConfiguration));
+  _COM_SMARTPTR_TYPEDEF(ISetupConfiguration2, __uuidof(ISetupConfiguration2));
+  _COM_SMARTPTR_TYPEDEF(ISetupHelper, __uuidof(ISetupHelper));
+  _COM_SMARTPTR_TYPEDEF(IEnumSetupInstances, __uuidof(IEnumSetupInstances));
+  _COM_SMARTPTR_TYPEDEF(ISetupInstance, __uuidof(ISetupInstance));
+  _COM_SMARTPTR_TYPEDEF(ISetupInstance2, __uuidof(ISetupInstance2));
 #endif
 
 using namespace clang::driver;
@@ -441,6 +441,8 @@
 
   TC.addProfileRTLibs(Args, CmdArgs);
 
+  std::vector Environment;
+
   // We need to special case some linker paths.  In the case of lld, we need to
   // translate 'lld' into 'lld-link', and in the case of the regular msvc
   // linker, we need to use a special search algorithm.
@@ -454,6 +456,68 @@
 // from the program PATH, because other environments like GnuWin32 install
 // their own link.exe which may come first.
 linkPath = FindVisualStudioExecutable(TC, "link.exe");
+
+#ifdef USE_WIN32
+// When cross-compiling with VS2017 or newer, link.exe expects to have
+// its containing bin directory at the top of PATH, followed by the
+// native target bin directory.
+// e.g. when compiling for x86 on an x64 host, PATH should start with:
+// /bin/HostX64/x86;/bin/HostX64/x64
+if (TC.getIsVS2017OrNewer() &&
+llvm::Triple(llvm::sys::getProcessTriple()).getArch() != TC.getArch()) {
+  auto HostArch = llvm::Triple(llvm::sys::getProcessTriple()).getArch();
+
+  auto EnvBlockWide = std::unique_ptr(
+GetEnvironmentStringsW(), FreeEnvironmentStringsW);
+  if (!EnvBlockWide)
+goto SkipSettingEnvironment;
+
+  size_t EnvCount = 0;
+  size_t EnvBlockLen = 0;
+  while (EnvBlockWide[EnvBlockLen] != '\0') {
+++EnvCount;
+EnvBlockLen += std::wcslen(&EnvBlockWide[EnvBlockLen])
+   + 1/*string null-terminator*/;
+  }
+  ++EnvBlockLen;  // add the block null-terminator
+
+  std::string EnvBlock;
+  if (!llvm::convertUTF16ToUTF8String(
+ llvm::ArrayRef(reinterpret_cast(EnvBlockWide.get()),
+  EnvBlockLen * sizeof(EnvBlockWide[0])),
+ EnvBlock))
+goto SkipSettingEnvironment;
+
+  Environment.reserve(EnvCount);
+
+  // Now loop over each string in the block and copy them into the
+  // environment vector, adjusting the PATH variable as needed when we
+  // find it.
+  for (const char *Cursor = EnvBlock.data(); *Cursor != '\0';) {
+llvm::StringRef EnvVar(Cursor);
+if (EnvVar.startswith_lower("path=")) {
+  using SubDirectoryType = toolchains::MSVCToolChain::SubDirectoryType;
+  constexpr size_t PrefixLen = 5;  // strlen("path=")
+  Environment.push_back(Args.MakeArgString(
+  EnvVar.substr(0, PrefixLen)
++ TC.getSubDirectoryPath(SubDirectoryType::Bin)
++ llvm::Twine(llvm::sys::EnvPathSeparator)
++ TC.getSubDirectoryPath(SubDirectoryType::Bin, HostArch)
++ (EnvVar.size() > PrefixLen
+  ? llvm::Twine(llvm::sys::EnvPathSeparator)
++ EnvVar.substr(PrefixLen)
+  : "")
+  ));
+} else {
+  Environment.push_back(Args.MakeArgString(EnvVar));
+}
+Cursor += EnvVar.size() + 1/*null-terminator*/;
+  }
+}
+  SkipSettingEnvironment:
+;
+#endif
   } else {
 linkPath = Linker;
 llvm::sys::path::replace_extension(linkPath, "exe");
@@ -460,8 +524,11 @@
 linkPath = TC.GetProgramPath(linkPath.c_str());
   }
 
-  const char *Exec = Args.MakeArgString(linkPath);
-  C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs));
+  auto LinkCmd = llvm::make_unique(
+  

[PATCH] D30810: Preserve vec3 type.

2017-03-15 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a comment.



> As you can see, the type legalizer handle vec3 load/store properly. It does 
> not write 4th element. The vec3 load/store generates more instructions but it 
> has correct behavior. I am not 100% sure the vec3 --> vec4 load/store is 
> correct or not because no one has complained about it.  But if the vec3 --> 
> vec4 load/store is correct, llvm's type legalizer or somewhere on llvm's 
> codegen could follow the approach too to generate optimal code.

Thanks for the nice investigation/explanation on amdgcn.

> As a result, I think it would be good for clang to have both of features and 
> I would like to stick to the option "-fpresereve-vec3' to change the behavior 
> easily.

The motivation doesn't seem solid to me, who else is going to benefit from this 
flag? You also didn't explain why doing this transformation yourself (looking 
through the shuffle) on your downstream pass isn't enough for you. We generally 
try to avoid adding flags if not for a good reason.


https://reviews.llvm.org/D30810



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


[PATCH] D30991: [Driver] Fix cross compiling with Visual Studio 2017

2017-03-15 Thread Zachary Turner via Phabricator via cfe-commits
zturner added inline comments.



Comment at: lib/Driver/Job.cpp:312
   SmallVector Argv;
+  auto Envp = Environment.size() > 1
+? const_cast(Environment.data())

Can you add `assert(Environment.back() == nullptr);`?



Comment at: lib/Driver/ToolChains/MSVC.cpp:478
+  size_t EnvBlockLen = 0;
+  while (EnvBlockWide[EnvBlockLen] != '\0') {
+++EnvCount;

`L'\0'`



Comment at: lib/Driver/ToolChains/MSVC.cpp:487-488
+  if (!llvm::convertUTF16ToUTF8String(
+ llvm::ArrayRef(reinterpret_cast(EnvBlockWide.get()),
+  EnvBlockLen * sizeof(EnvBlockWide[0])),
+ EnvBlock))

There's an overload of `convertUTF16ToUTF8String` that takes an 
`ArrayRef`.  So I think you can just write this:

```
if (!llvm::convertUTF16ToUTF8String(makeArrayRef(EnvBlockWide.get(), 
EnvBlockLen)))
```



Comment at: lib/Driver/ToolChains/MSVC.cpp:492
+
+  Environment.reserve(EnvCount);
+

`EnvCount+1`, for the extra null terminator.



Comment at: lib/Driver/ToolChains/MSVC.cpp:497
+  // find it.
+  for (const char *Cursor = EnvBlock.data(); *Cursor != '\0';) {
+llvm::StringRef EnvVar(Cursor);

We could avoid the manual index and loop counters if we do something like this:

```
StringRef Cursor(EnvBlock);
while (!Cursor.empty()) {
  StringRef ThisVar;
  std::tie(ThisVar, Cursor) = Cursor.split('\0');
}
```





Comment at: lib/Driver/ToolChains/MSVC.cpp:499
+llvm::StringRef EnvVar(Cursor);
+if (EnvVar.startswith_lower("path=")) {
+  using SubDirectoryType = toolchains::MSVCToolChain::SubDirectoryType;

Too bad `StringRef` doesn't have `consume_front_lower()`.  That would have been 
perfect here.



Comment at: lib/Driver/ToolChains/MSVC.cpp:517
+  }
+}
+  SkipSettingEnvironment:

I think you need to push 1 more null terminator onto the end here to terminate 
the block.


https://reviews.llvm.org/D30991



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


[PATCH] D30991: [Driver] Fix cross compiling with Visual Studio 2017

2017-03-15 Thread Zachary Turner via Phabricator via cfe-commits
zturner added inline comments.



Comment at: lib/Driver/ToolChains/MSVC.cpp:517
+  }
+}
+  SkipSettingEnvironment:

zturner wrote:
> I think you need to push 1 more null terminator onto the end here to 
> terminate the block.
Actually if you use the `std::tie()` algorithm I proposed, then it will enter 
the body of the loop on the terminating null and push it back (as long as 
`MakeArgString` returns `nullptr` when its argument is empty, which I haven't 
checked)


https://reviews.llvm.org/D30991



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


[PATCH] D30991: [Driver] Fix cross compiling with Visual Studio 2017

2017-03-15 Thread Hamza Sood via Phabricator via cfe-commits
hamzasood marked an inline comment as done.
hamzasood added inline comments.



Comment at: lib/Driver/ToolChains/MSVC.cpp:487-488
+  if (!llvm::convertUTF16ToUTF8String(
+ llvm::ArrayRef(reinterpret_cast(EnvBlockWide.get()),
+  EnvBlockLen * sizeof(EnvBlockWide[0])),
+ EnvBlock))

zturner wrote:
> There's an overload of `convertUTF16ToUTF8String` that takes an 
> `ArrayRef`.  So I think you can just write this:
> 
> ```
> if (!llvm::convertUTF16ToUTF8String(makeArrayRef(EnvBlockWide.get(), 
> EnvBlockLen)))
> ```
Using that overload would involve casting wchar_t* to UTF16* (i.e. unsigned 
char*), which I think breaks aliasing rules.



Comment at: lib/Driver/ToolChains/MSVC.cpp:517
+  }
+}
+  SkipSettingEnvironment:

zturner wrote:
> zturner wrote:
> > I think you need to push 1 more null terminator onto the end here to 
> > terminate the block.
> Actually if you use the `std::tie()` algorithm I proposed, then it will enter 
> the body of the loop on the terminating null and push it back (as long as 
> `MakeArgString` returns `nullptr` when its argument is empty, which I haven't 
> checked)
Command::setEnvironment adds a nullptr onto the end of any vector it's given. I 
figured it's simpler to do it there than to rely on the caller. Do you think 
that should be changed?


https://reviews.llvm.org/D30991



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


[PATCH] D30991: [Driver] Fix cross compiling with Visual Studio 2017

2017-03-15 Thread Hamza Sood via Phabricator via cfe-commits
hamzasood added inline comments.



Comment at: lib/Driver/ToolChains/MSVC.cpp:487-488
+  if (!llvm::convertUTF16ToUTF8String(
+ llvm::ArrayRef(reinterpret_cast(EnvBlockWide.get()),
+  EnvBlockLen * sizeof(EnvBlockWide[0])),
+ EnvBlock))

hamzasood wrote:
> zturner wrote:
> > There's an overload of `convertUTF16ToUTF8String` that takes an 
> > `ArrayRef`.  So I think you can just write this:
> > 
> > ```
> > if (!llvm::convertUTF16ToUTF8String(makeArrayRef(EnvBlockWide.get(), 
> > EnvBlockLen)))
> > ```
> Using that overload would involve casting wchar_t* to UTF16* (i.e. unsigned 
> char*), which I think breaks aliasing rules.
Sorry, I meant unsigned short.


https://reviews.llvm.org/D30991



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


[PATCH] D30810: Preserve vec3 type.

2017-03-15 Thread JinGu Kang via Phabricator via cfe-commits
jaykang10 added a comment.

> The motivation doesn't seem solid to me, who else is going to benefit from 
> this flag? You also didn't explain why doing this transformation yourself 
> (looking through the shuffle) on your downstream pass isn't enough for you. 
> We generally try to avoid adding flags if not for a good reason.

If you turn on optimization with -O option, the shufflevector is gone on 
'InstructionCombining' pass. I showed you the IR example and source code on 
previous comment. You could mention bitcast instead of shufflevector. The 
bitcast could be constant expression with global variables and it makes code 
dirty. I think Anastasia has already explained the motivation well on her 
comments. If you need something more, please let me know.


https://reviews.llvm.org/D30810



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


[PATCH] D31022: Implement P0298R3: `std::byte`

2017-03-15 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists created this revision.

Implement `std::byte` from the paper http://wg21.link/P0298R3.

Split the implementation across two files; putting the stuff that needs 
`enable_if` into  and the rest in , where it belongs.  
Sadly, this means that  now includes  (at the end).


https://reviews.llvm.org/D31022

Files:
  include/cstddef
  include/type_traits
  test/std/language.support/support.types/byte.pass.cpp
  test/std/language.support/support.types/byteops/and.assign.pass.cpp
  test/std/language.support/support.types/byteops/and.pass.cpp
  test/std/language.support/support.types/byteops/lshift.assign.fail.cpp
  test/std/language.support/support.types/byteops/lshift.assign.pass.cpp
  test/std/language.support/support.types/byteops/lshift.fail.cpp
  test/std/language.support/support.types/byteops/lshift.pass.cpp
  test/std/language.support/support.types/byteops/not.pass.cpp
  test/std/language.support/support.types/byteops/or.assign.pass.cpp
  test/std/language.support/support.types/byteops/or.pass.cpp
  test/std/language.support/support.types/byteops/rshift.assign.fail.cpp
  test/std/language.support/support.types/byteops/rshift.assign.pass.cpp
  test/std/language.support/support.types/byteops/rshift.fail.cpp
  test/std/language.support/support.types/byteops/rshift.pass.cpp
  test/std/language.support/support.types/byteops/to_integer.fail.cpp
  test/std/language.support/support.types/byteops/to_integer.pass.cpp
  test/std/language.support/support.types/byteops/xor.assign.pass.cpp
  test/std/language.support/support.types/byteops/xor.pass.cpp
  www/cxx1z_status.html

Index: www/cxx1z_status.html
===
--- www/cxx1z_status.html
+++ www/cxx1z_status.html
@@ -142,23 +142,25 @@
 	http://wg21.link/P0517R0";>P0517R0LWGMake future_error ConstructibleIssaquahComplete4.0
 	http://wg21.link/P0521R0";>P0521R0LWGProposed Resolution for CA 14 (shared_ptr use_count/unique)IssaquahNothing to don/a
   	
+	http://wg21.link/P0156R2";>P0156R2LWGVariadic Lock guardKona
+	http://wg21.link/P0270R3";>P0270R3CWGRemoving C dependencies from signal handler wordingKona
+	http://wg21.link/P0298R3";>P0298R3CWGA byte type definitionKonaComplete5.0
 	http://wg21.link/P0317R1";>P0317R1LWGDirectory Entry Caching for FilesystemKona
-	http://wg21.link/P0492R2";>P0492R2LWGProposed Resolution of C++17 National Body Comments for FilesystemsKona
 	http://wg21.link/P0430R2";>P0430R2LWGFile system library on non-POSIX-like operating systemsKona
+	http://wg21.link/P0433R2";>P0433R2LWGToward a resolution of US7 and US14: Integrating template deduction for class templates into the standard libraryKona
 	http://wg21.link/P0452R1";>P0452R1LWGUnifying  Parallel AlgorithmsKona
+	http://wg21.link/P0467R2";>P0467R2LWGIterator Concerns for Parallel AlgorithmsKona
+	http://wg21.link/P0492R2";>P0492R2LWGProposed Resolution of C++17 National Body Comments for FilesystemsKona
 	http://wg21.link/P0518R1";>P0518R1LWGAllowing copies as arguments to function objects given to parallel algorithms in response to CH11Kona
 	http://wg21.link/P0523R1";>P0523R1LWGWording for CH 10: Complexity of parallel algorithmsKona
+	http://wg21.link/P0548R1";>P0548R1LWGcommon_type and durationKona
+	http://wg21.link/P0558R1";>P0558R1LWGResolving atomic named base class inconsistenciesKona
 	http://wg21.link/P0574R1";>P0574R1LWGAlgorithm Complexity Constraints and Parallel OverloadsKona
-	http://wg21.link/P0467R2";>P0467R2LWGIterator Concerns for Parallel AlgorithmsKona
-	http://wg21.link/P0623R0";>P0623R0LWGFinal C++17 Parallel Algorithms FixesKona
+	http://wg21.link/P0599R1";>P0599R1LWGnoexcept for hash functionsKona
 	http://wg21.link/P0604R0";>P0604R0LWGResolving GB 55, US 84, US 85, US 86Kona
 	http://wg21.link/P0607R0";>P0607R0LWGInline Variables for the Standard LibraryKona
 	http://wg21.link/P0618R0";>P0618R0LWGDeprecating Kona
-	http://wg21.link/P0156R2";>P0156R2LWGVariadic Lock guardKona
-	http://wg21.link/P0599R1";>P0599R1LWGnoexcept for hash functionsKona
-	http://wg21.link/P0433R2";>P0433R2LWGToward a resolution of US7 and US14: Integrating template deduction for class templates into the standard libraryKona
-	http://wg21.link/P0558R1";>P0558R1LWGResolving atomic named base class inconsistenciesKona
-	http://wg21.link/P0548R1";>P0548R1LWGcommon_type and durationKona
+	http://wg21.link/P0623R0";>P0623R0LWGFinal C++17 Parallel Algorithms FixesKona
 
 
   
Index: test/std/language.support/support.types/byteops/xor.pass.cpp
===
--- test/std/language.support/support.types/byteops/xor.pass.cpp
+++ test/std/language.support/support.types/byteops/xor.pass.cpp
@@ -0,0 +1,31 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See L

[PATCH] D31022: Implement P0298R3: `std::byte`

2017-03-15 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added inline comments.



Comment at: www/cxx1z_status.html:144
http://wg21.link/P0521R0";>P0521R0LWGProposed 
Resolution for CA 14 (shared_ptr 
use_count/unique)IssaquahNothing to 
don/a

+   http://wg21.link/P0156R2";>P0156R2LWGVariadic Lock 
guardKona

Note: the reason for the churn here is that I sorted them by paper number.
The only significant change in this file is the addition of P0298R3 and P0298R3.



https://reviews.llvm.org/D31022



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


[PATCH] D31019: [clangd] [RFC] Use libclang and CXTranslationUnit instead of ASTUnit

2017-03-15 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle-ericsson added a comment.

Just to make things clear, I'm really not sure if this is the right approach 
and I'm looking for opinions before going further in that direction (code 
completion).


Repository:
  rL LLVM

https://reviews.llvm.org/D31019



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


[PATCH] D30810: Preserve vec3 type.

2017-03-15 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

In https://reviews.llvm.org/D30810#701141, @jaykang10 wrote:

> In https://reviews.llvm.org/D30810#701132, @ahatanak wrote:
>
> > Actually, it's not a mis-compile. The record layout shows that there is a 
> > padding before field f2 and f2 starts at byte 16. So using "store <4 x 
> > float>" doesn't overwrite the field.
>
>
> It depends on float3's alignment. I guess the float3's alignment is 16 on 
> your target so there is a padding bytes before f2 to be aligned by 16. If you 
> add __attribute__((packed)) on struct type, you could see overwrite.


I looked at ItaniumRecordLayoutBuilder to understand how 
__attribute__((packed)) affects the struct's layout.

If the number of elements of a vector is not a power of 2, 
ASTContext::getTypeInfoImpl rounds up the width and alignment to the next power 
of 2. So the size of float3 is 16 bytes. __attribute__((packed)) can change the 
alignment of float3, but it doesn't change its size, so there is a 4-byte 
padding between field f1 and f2.


https://reviews.llvm.org/D30810



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