[PATCH] D49718: [CodeGen][ObjC] Make block copy/dispose helper function exception-safe.

2018-07-24 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In https://reviews.llvm.org/D49718#1174281, @ahatanak wrote:

> Merge pushBlockObjectRelease and enterByrefCleanup.
>
> In https://reviews.llvm.org/D49718#1174113, @rjmccall wrote:
>
> > Heh, okay.  It looks like the runtime doesn't do anything different, but I 
> > think it's probably more correct to always pass `BLOCK_FIELD_IS_WEAK` when 
> > destroying a `__weak` block in GC modes.
>
>
> I tried passing `BLOCK_FIELD_IS_WEAK | BLOCK_FIELD_IS_BYREF` to the call to 
> enterByrefCleanup in EmitAutoVarCleanups, but it looks like 
> test/CodeGenObjC/blocks.m fails if I do so. The test was committed in r125823 
> and there is a comment that says " We're not supposed to pass 
> BLOCK_FIELD_IS_WEAK here".
>
> http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20110214/038996.html
>
> Should we change the check in the test?


Thanks for the archaeology; that's a very good question.  It looks to me like 
that comment was unrelated to the functionality change made by that patch, and 
nothing in the radar history explains it, either.  I don't see anything in the 
runtime source which suggests that it's wrong to pass `BYREF|WEAK` to 
`Block_object_dispose`.  Going way back, it does seem to have been necessary 
under GC to pass `BYREF|WEAK` for `Block_object_assign`, but the runtime never 
did anything special with the flag for `Block_object_dispose`; it just always 
treated it exactly the same as `BYREF` alone.

I think it's fine to just change the test.


Repository:
  rC Clang

https://reviews.llvm.org/D49718



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


[PATCH] D49774: [libc++] Use __int128_t to represent file_time_type.

2018-07-24 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

In https://reviews.llvm.org/D49774#1174565, @mclow.lists wrote:

> I haven't reviewed this closely, but you might want to look at 
> http://wg21.link/P0355, where we added a `file_clock` and `file_time` types.


Thanks for the information. It doesn't look to have too much bearing on this 
from a design standpoint. Except to note that it seems to solve
the streaming problem by adding explicit streaming overload for time points.


Repository:
  rCXX libc++

https://reviews.llvm.org/D49774



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


[PATCH] D49765: [CMake] Use LIBCXXABI_LIBDIR_SUFFIX in libc++abi build

2018-07-24 Thread Michał Górny via Phabricator via cfe-commits
mgorny accepted this revision.
mgorny added a comment.
This revision is now accepted and ready to land.

Looks good, thanks!


Repository:
  rCXXA libc++abi

https://reviews.llvm.org/D49765



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


[libcxx] r337888 - Fix bugs in create_directory implementation.

2018-07-24 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Tue Jul 24 21:46:32 2018
New Revision: 337888

URL: http://llvm.org/viewvc/llvm-project?rev=337888=rev
Log:
Fix bugs in create_directory implementation.

Libc++ was incorrectly reporting an error when the target of create_directory
already exists, but was not a directory. This behavior is not specified
in the most recent standard, which says no error should be reported.

Additionally, libc++ failed to report an error when the attribute directory
path didn't exist or didn't name a directory. This has been fixed as well.

Although it's not clear if we should call status or symlink_status on the
attribute directory. This patch chooses to still call status.

Modified:
libcxx/trunk/src/experimental/filesystem/operations.cpp

libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp

libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.create_directory/create_directory.pass.cpp

libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.create_directory/create_directory_with_attributes.pass.cpp

Modified: libcxx/trunk/src/experimental/filesystem/operations.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/experimental/filesystem/operations.cpp?rev=337888=337887=337888=diff
==
--- libcxx/trunk/src/experimental/filesystem/operations.cpp (original)
+++ libcxx/trunk/src/experimental/filesystem/operations.cpp Tue Jul 24 21:46:32 
2018
@@ -830,7 +830,7 @@ bool __create_directory(const path& p, e
 
   if (::mkdir(p.c_str(), static_cast(perms::all)) == 0)
 return true;
-  if (errno != EEXIST || !is_directory(p))
+  if (errno != EEXIST)
 err.report(capture_errno());
   return false;
 }
@@ -845,10 +845,12 @@ bool __create_directory(path const & p,
   auto st = detail::posix_stat(attributes, attr_stat, );
   if (!status_known(st))
 return err.report(mec);
+  if (!is_directory(st))
+return err.report(errc::not_a_directory, "the specified attribute path is 
invalid");
 
   if (::mkdir(p.c_str(), attr_stat.st_mode) == 0)
 return true;
-  if (errno != EEXIST || !is_directory(p))
+  if (errno != EEXIST)
 err.report(capture_errno());
   return false;
 }

Modified: 
libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp?rev=337888=337887=337888=diff
==
--- 
libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp
 Tue Jul 24 21:46:32 2018
@@ -66,4 +66,36 @@ TEST_CASE(create_directories_multi_level
 TEST_CHECK(is_directory(dir));
 }
 
+TEST_CASE(create_directory_symlinks) {
+  scoped_test_env env;
+  const path root = env.create_dir("dir");
+  const path sym_dest_dead = env.make_env_path("dead");
+  const path dead_sym = env.create_symlink(sym_dest_dead, "dir/sym_dir");
+  const path target = env.make_env_path("dir/sym_dir/foo");
+  {
+std::error_code ec = GetTestEC();
+TEST_CHECK(create_directories(target, ec) == false);
+TEST_CHECK(ec);
+TEST_CHECK(!exists(sym_dest_dead));
+TEST_CHECK(!exists(dead_sym));
+  }
+}
+
+
+TEST_CASE(create_directory_through_symlinks) {
+  scoped_test_env env;
+  const path root = env.create_dir("dir");
+  const path sym_dir = env.create_symlink(root, "sym_dir");
+  const path target = env.make_env_path("sym_dir/foo");
+  const path resolved_target = env.make_env_path("dir/foo");
+  TEST_REQUIRE(is_directory(sym_dir));
+  {
+std::error_code ec = GetTestEC();
+TEST_CHECK(create_directories(target, ec) == true);
+TEST_CHECK(!ec);
+TEST_CHECK(is_directory(target));
+TEST_CHECK(is_directory(resolved_target));
+  }
+}
+
 TEST_SUITE_END()

Modified: 
libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.create_directory/create_directory.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.create_directory/create_directory.pass.cpp?rev=337888=337887=337888=diff
==
--- 
libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.create_directory/create_directory.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.create_directory/create_directory.pass.cpp
 Tue Jul 24 21:46:32 2018
@@ -94,9 +94,9 @@ TEST_CASE(dest_is_file)
 {
 scoped_test_env env;
 const path file = env.create_file("file", 42);
-std::error_code ec;
+std::error_code ec = GetTestEC();
 TEST_CHECK(fs::create_directory(file, 

[PATCH] D49771: CodeGen: use non-zero memset when possible for automatic variables

2018-07-24 Thread JF Bastien via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL337887: CodeGen: use non-zero memset when possible for 
automatic variables (authored by jfb, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D49771

Files:
  cfe/trunk/lib/CodeGen/CGDecl.cpp
  cfe/trunk/test/CodeGen/init.c

Index: cfe/trunk/lib/CodeGen/CGDecl.cpp
===
--- cfe/trunk/lib/CodeGen/CGDecl.cpp
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp
@@ -948,6 +948,113 @@
  canEmitInitWithFewStoresAfterBZero(Init, StoreBudget);
 }
 
+/// A byte pattern.
+///
+/// Can be "any" pattern if the value was padding or known to be undef.
+/// Can be "none" pattern if a sequence doesn't exist.
+class BytePattern {
+  uint8_t Val;
+  enum class ValueType : uint8_t { Specific, Any, None } Type;
+  BytePattern(ValueType Type) : Type(Type) {}
+
+public:
+  BytePattern(uint8_t Value) : Val(Value), Type(ValueType::Specific) {}
+  static BytePattern Any() { return BytePattern(ValueType::Any); }
+  static BytePattern None() { return BytePattern(ValueType::None); }
+  bool isAny() const { return Type == ValueType::Any; }
+  bool isNone() const { return Type == ValueType::None; }
+  bool isValued() const { return Type == ValueType::Specific; }
+  uint8_t getValue() const {
+assert(isValued());
+return Val;
+  }
+  BytePattern merge(const BytePattern Other) const {
+if (isNone() || Other.isNone())
+  return None();
+if (isAny())
+  return Other;
+if (Other.isAny())
+  return *this;
+if (getValue() == Other.getValue())
+  return *this;
+return None();
+  }
+};
+
+/// Figures out whether the constant can be initialized with memset.
+static BytePattern constantIsRepeatedBytePattern(llvm::Constant *C) {
+  if (isa(C) || isa(C))
+return BytePattern(0x00);
+  if (isa(C))
+return BytePattern::Any();
+
+  if (isa(C)) {
+auto *Int = cast(C);
+if (Int->getBitWidth() % 8 != 0)
+  return BytePattern::None();
+const llvm::APInt  = Int->getValue();
+if (Value.isSplat(8))
+  return BytePattern(Value.getLoBits(8).getLimitedValue());
+return BytePattern::None();
+  }
+
+  if (isa(C)) {
+auto *FP = cast(C);
+llvm::APInt Bits = FP->getValueAPF().bitcastToAPInt();
+if (Bits.getBitWidth() % 8 != 0)
+  return BytePattern::None();
+if (!Bits.isSplat(8))
+  return BytePattern::None();
+return BytePattern(Bits.getLimitedValue() & 0xFF);
+  }
+
+  if (isa(C)) {
+llvm::Constant *Splat = cast(C)->getSplatValue();
+if (Splat)
+  return constantIsRepeatedBytePattern(Splat);
+return BytePattern::None();
+  }
+
+  if (isa(C) || isa(C)) {
+BytePattern Pattern(BytePattern::Any());
+for (unsigned I = 0, E = C->getNumOperands(); I != E; ++I) {
+  llvm::Constant *Elt = cast(C->getOperand(I));
+  Pattern = Pattern.merge(constantIsRepeatedBytePattern(Elt));
+  if (Pattern.isNone())
+return Pattern;
+}
+return Pattern;
+  }
+
+  if (llvm::ConstantDataSequential *CDS =
+  dyn_cast(C)) {
+BytePattern Pattern(BytePattern::Any());
+for (unsigned I = 0, E = CDS->getNumElements(); I != E; ++I) {
+  llvm::Constant *Elt = CDS->getElementAsConstant(I);
+  Pattern = Pattern.merge(constantIsRepeatedBytePattern(Elt));
+  if (Pattern.isNone())
+return Pattern;
+}
+return Pattern;
+  }
+
+  // BlockAddress, ConstantExpr, and everything else is scary.
+  return BytePattern::None();
+}
+
+/// Decide whether we should use memset to initialize a local variable instead
+/// of using a memcpy from a constant global. Assumes we've already decided to
+/// not user bzero.
+/// FIXME We could be more clever, as we are for bzero above, and generate
+///   memset followed by stores. It's unclear that's worth the effort.
+static BytePattern shouldUseMemSetToInitialize(llvm::Constant *Init,
+   uint64_t GlobalSize) {
+  uint64_t SizeLimit = 32;
+  if (GlobalSize <= SizeLimit)
+return BytePattern::None();
+  return constantIsRepeatedBytePattern(Init);
+}
+
 /// EmitAutoVarDecl - Emit code and set up an entry in LocalDeclMap for a
 /// variable declaration with auto, register, or no storage class specifier.
 /// These turn into simple stack objects, or GlobalValues depending on target.
@@ -1401,41 +1508,49 @@
   if (Loc.getType() != BP)
 Loc = Builder.CreateBitCast(Loc, BP);
 
-  // If the initializer is all or mostly zeros, codegen with bzero then do a
-  // few stores afterward.
-  if (shouldUseBZeroPlusStoresToInitialize(
-  constant,
-  CGM.getDataLayout().getTypeAllocSize(constant->getType( {
+  // If the initializer is all or mostly the same, codegen with bzero / memset
+  // then do a few stores afterward.
+  uint64_t ConstantSize =
+  CGM.getDataLayout().getTypeAllocSize(constant->getType());
+  if 

r337887 - CodeGen: use non-zero memset when possible for automatic variables

2018-07-24 Thread JF Bastien via cfe-commits
Author: jfb
Date: Tue Jul 24 21:29:03 2018
New Revision: 337887

URL: http://llvm.org/viewvc/llvm-project?rev=337887=rev
Log:
CodeGen: use non-zero memset when possible for automatic variables

Summary:
Right now automatic variables are either initialized with bzero followed by a 
few stores, or memcpy'd from a synthesized global. We end up encountering a 
fair amount of code where memcpy of non-zero byte patterns would be better than 
memcpy from a global because it touches less memory and generates a smaller 
binary. The optimizer could reason about this, but it's not really worth it 
when clang already knows.

This code could definitely be more clever but I'm not sure it's worth it. In 
particular we could track a histogram of bytes seen and figure out (as we do 
with bzero) if a memset could be followed by a handful of stores. Similarly, we 
could tune the heuristics for GlobalSize, but using the same as for bzero seems 
conservatively OK for now.



Reviewers: dexonsmith

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/test/CodeGen/init.c

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=337887=337886=337887=diff
==
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Tue Jul 24 21:29:03 2018
@@ -948,6 +948,113 @@ static bool shouldUseBZeroPlusStoresToIn
  canEmitInitWithFewStoresAfterBZero(Init, StoreBudget);
 }
 
+/// A byte pattern.
+///
+/// Can be "any" pattern if the value was padding or known to be undef.
+/// Can be "none" pattern if a sequence doesn't exist.
+class BytePattern {
+  uint8_t Val;
+  enum class ValueType : uint8_t { Specific, Any, None } Type;
+  BytePattern(ValueType Type) : Type(Type) {}
+
+public:
+  BytePattern(uint8_t Value) : Val(Value), Type(ValueType::Specific) {}
+  static BytePattern Any() { return BytePattern(ValueType::Any); }
+  static BytePattern None() { return BytePattern(ValueType::None); }
+  bool isAny() const { return Type == ValueType::Any; }
+  bool isNone() const { return Type == ValueType::None; }
+  bool isValued() const { return Type == ValueType::Specific; }
+  uint8_t getValue() const {
+assert(isValued());
+return Val;
+  }
+  BytePattern merge(const BytePattern Other) const {
+if (isNone() || Other.isNone())
+  return None();
+if (isAny())
+  return Other;
+if (Other.isAny())
+  return *this;
+if (getValue() == Other.getValue())
+  return *this;
+return None();
+  }
+};
+
+/// Figures out whether the constant can be initialized with memset.
+static BytePattern constantIsRepeatedBytePattern(llvm::Constant *C) {
+  if (isa(C) || isa(C))
+return BytePattern(0x00);
+  if (isa(C))
+return BytePattern::Any();
+
+  if (isa(C)) {
+auto *Int = cast(C);
+if (Int->getBitWidth() % 8 != 0)
+  return BytePattern::None();
+const llvm::APInt  = Int->getValue();
+if (Value.isSplat(8))
+  return BytePattern(Value.getLoBits(8).getLimitedValue());
+return BytePattern::None();
+  }
+
+  if (isa(C)) {
+auto *FP = cast(C);
+llvm::APInt Bits = FP->getValueAPF().bitcastToAPInt();
+if (Bits.getBitWidth() % 8 != 0)
+  return BytePattern::None();
+if (!Bits.isSplat(8))
+  return BytePattern::None();
+return BytePattern(Bits.getLimitedValue() & 0xFF);
+  }
+
+  if (isa(C)) {
+llvm::Constant *Splat = cast(C)->getSplatValue();
+if (Splat)
+  return constantIsRepeatedBytePattern(Splat);
+return BytePattern::None();
+  }
+
+  if (isa(C) || isa(C)) {
+BytePattern Pattern(BytePattern::Any());
+for (unsigned I = 0, E = C->getNumOperands(); I != E; ++I) {
+  llvm::Constant *Elt = cast(C->getOperand(I));
+  Pattern = Pattern.merge(constantIsRepeatedBytePattern(Elt));
+  if (Pattern.isNone())
+return Pattern;
+}
+return Pattern;
+  }
+
+  if (llvm::ConstantDataSequential *CDS =
+  dyn_cast(C)) {
+BytePattern Pattern(BytePattern::Any());
+for (unsigned I = 0, E = CDS->getNumElements(); I != E; ++I) {
+  llvm::Constant *Elt = CDS->getElementAsConstant(I);
+  Pattern = Pattern.merge(constantIsRepeatedBytePattern(Elt));
+  if (Pattern.isNone())
+return Pattern;
+}
+return Pattern;
+  }
+
+  // BlockAddress, ConstantExpr, and everything else is scary.
+  return BytePattern::None();
+}
+
+/// Decide whether we should use memset to initialize a local variable instead
+/// of using a memcpy from a constant global. Assumes we've already decided to
+/// not user bzero.
+/// FIXME We could be more clever, as we are for bzero above, and generate
+///   memset followed by stores. It's unclear that's worth the effort.
+static BytePattern shouldUseMemSetToInitialize(llvm::Constant *Init,
+   

[PATCH] D49774: [libc++] Use __int128_t to represent file_time_type.

2018-07-24 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

I haven't reviewed this closely, but you might want to look at 
http://wg21.link/P0355, where we added a `file_clock` and `file_time` types.


Repository:
  rCXX libc++

https://reviews.llvm.org/D49774



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


[PATCH] D49771: CodeGen: use non-zero memset when possible for automatic variables

2018-07-24 Thread JF Bastien via Phabricator via cfe-commits
jfb marked an inline comment as done.
jfb added a comment.

Addressed all comments.




Comment at: lib/CodeGen/CGDecl.cpp:956-957
+class BytePattern {
+  uint8_t Val;
+  enum class ValueType { Specific, Any, None } Type;
+  BytePattern(ValueType Type) : Type(Type) {}

bogner wrote:
> Probably makes sense to swap the order of these or give the enum class a 
> smaller underlying type than int.
I defined the enum class' storage type as `uint8_t`.


Repository:
  rC Clang

https://reviews.llvm.org/D49771



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


[PATCH] D49773: Add new file test/support/test_comparisons.h

2018-07-24 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists closed this revision.
mclow.lists added a comment.

Committed as 337885 after changing `constexpr` -> `TEST_CONSTEXPR_CXX14`


https://reviews.llvm.org/D49773



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


[PATCH] D49771: CodeGen: use non-zero memset when possible for automatic variables

2018-07-24 Thread JF Bastien via Phabricator via cfe-commits
jfb updated this revision to Diff 157191.
jfb marked 2 inline comments as done.
jfb added a comment.

- Use short to test padding between array elements.
- Define enum class storage type; swap order of if / else to make it more 
readable.


Repository:
  rC Clang

https://reviews.llvm.org/D49771

Files:
  lib/CodeGen/CGDecl.cpp
  test/CodeGen/init.c

Index: test/CodeGen/init.c
===
--- test/CodeGen/init.c
+++ test/CodeGen/init.c
@@ -140,6 +140,72 @@
   // CHECK: call void @bar
 }
 
+void nonzeroMemseti8() {
+  char arr[33] = { 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, };
+  // CHECK-LABEL: @nonzeroMemseti8(
+  // CHECK-NOT: store
+  // CHECK-NOT: memcpy
+  // CHECK: call void @llvm.memset.p0i8.i32(i8* {{.*}}, i8 42, i32 33, i1 false)
+}
+
+void nonzeroMemseti16() {
+  unsigned short arr[17] = { 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, };
+  // CHECK-LABEL: @nonzeroMemseti16(
+  // CHECK-NOT: store
+  // CHECK-NOT: memcpy
+  // CHECK: call void @llvm.memset.p0i8.i32(i8* {{.*}}, i8 66, i32 34, i1 false)
+}
+
+void nonzeroMemseti32() {
+  unsigned arr[9] = { 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, };
+  // CHECK-LABEL: @nonzeroMemseti32(
+  // CHECK-NOT: store
+  // CHECK-NOT: memcpy
+  // CHECK: call void @llvm.memset.p0i8.i32(i8* {{.*}}, i8 -16, i32 36, i1 false)
+}
+
+void nonzeroMemseti64() {
+  unsigned long long arr[7] = { 0x, 0x, 0x, 0x, 0x,  0x,  0x,  };
+  // CHECK-LABEL: @nonzeroMemseti64(
+  // CHECK-NOT: store
+  // CHECK-NOT: memcpy
+  // CHECK: call void @llvm.memset.p0i8.i32(i8* {{.*}}, i8 -86, i32 56, i1 false)
+}
+
+void nonzeroMemsetf32() {
+  float arr[9] = { 0x1.cacacap+75, 0x1.cacacap+75, 0x1.cacacap+75, 0x1.cacacap+75, 0x1.cacacap+75, 0x1.cacacap+75, 0x1.cacacap+75, 0x1.cacacap+75, 0x1.cacacap+75, };
+  // CHECK-LABEL: @nonzeroMemsetf32(
+  // CHECK-NOT: store
+  // CHECK-NOT: memcpy
+  // CHECK: call void @llvm.memset.p0i8.i32(i8* {{.*}}, i8 101, i32 36, i1 false)
+}
+
+void nonzeroMemsetf64() {
+  double arr[7] = { 0x1.4p+69, 0x1.4p+69, 0x1.4p+69, 0x1.4p+69, 0x1.4p+69, 0x1.4p+69, 0x1.4p+69, };
+  // CHECK-LABEL: @nonzeroMemsetf64(
+  // CHECK-NOT: store
+  // CHECK-NOT: memcpy
+  // CHECK: call void @llvm.memset.p0i8.i32(i8* {{.*}}, i8 68, i32 56, i1 false)
+}
+
+void nonzeroPaddedUnionMemset() {
+  union U { char c; int i; };
+  union U arr[9] = { 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, };
+  // CHECK-LABEL: @nonzeroPaddedUnionMemset(
+  // CHECK-NOT: store
+  // CHECK-NOT: memcpy
+  // CHECK: call void @llvm.memset.p0i8.i32(i8* {{.*}}, i8 -16, i32 36, i1 false)
+}
+
+void nonzeroNestedMemset() {
+  union U { char c; int i; };
+  struct S { union U u; short i; };
+  struct S arr[5] = { { {0xF0}, 0xF0F0 }, { {0xF0}, 0xF0F0 }, { {0xF0}, 0xF0F0 }, { {0xF0}, 0xF0F0 }, { {0xF0}, 0xF0F0 }, };
+  // CHECK-LABEL: @nonzeroNestedMemset(
+  // CHECK-NOT: store
+  // CHECK-NOT: memcpy
+  // CHECK: call void @llvm.memset.p0i8.i32(i8* {{.*}}, i8 -16, i32 40, i1 false)
+}
 
 // PR9257
 struct test11S {
Index: lib/CodeGen/CGDecl.cpp
===
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -948,6 +948,113 @@
  canEmitInitWithFewStoresAfterBZero(Init, StoreBudget);
 }
 
+/// A byte pattern.
+///
+/// Can be "any" pattern if the value was padding or known to be undef.
+/// Can be "none" pattern if a sequence doesn't exist.
+class BytePattern {
+  uint8_t Val;
+  enum class ValueType : uint8_t { Specific, Any, None } Type;
+  BytePattern(ValueType Type) : Type(Type) {}
+
+public:
+  BytePattern(uint8_t Value) : Val(Value), Type(ValueType::Specific) {}
+  static BytePattern Any() { return BytePattern(ValueType::Any); }
+  static BytePattern None() { return BytePattern(ValueType::None); }
+  bool isAny() const { return Type == ValueType::Any; }
+  bool isNone() const { return Type == ValueType::None; }
+  bool isValued() const { return Type == ValueType::Specific; }
+  uint8_t getValue() const {
+assert(isValued());
+return Val;
+  }
+  BytePattern merge(const BytePattern Other) const {
+if (isNone() || Other.isNone())
+  return None();
+if (isAny())
+  return Other;
+if (Other.isAny())
+  return *this;
+if (getValue() == Other.getValue())
+  return *this;
+return None();
+  }
+};
+
+/// Figures out whether the constant can be initialized with memset.
+static BytePattern constantIsRepeatedBytePattern(llvm::Constant *C) {
+  if (isa(C) || isa(C))
+return 

[libcxx] r337885 - New test support for comparisons. Reviewed as https://reviews.llvm.org/D49773

2018-07-24 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Tue Jul 24 21:21:21 2018
New Revision: 337885

URL: http://llvm.org/viewvc/llvm-project?rev=337885=rev
Log:
New test support for comparisons. Reviewed as https://reviews.llvm.org/D49773

Added:
libcxx/trunk/test/support/test_comparisons.h

Added: libcxx/trunk/test/support/test_comparisons.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/test_comparisons.h?rev=337885=auto
==
--- libcxx/trunk/test/support/test_comparisons.h (added)
+++ libcxx/trunk/test/support/test_comparisons.h Tue Jul 24 21:21:21 2018
@@ -0,0 +1,175 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+//  A set of routines for testing the comparison operators of a type
+//
+//  6 tests all six comparison operators
+//  2 tests only op== and op!=
+//
+//  AssertComparisonsXAreNoexcept   static_asserts that the operations 
are all noexcept.
+//  AssertComparisonsXReturnBoolstatic_asserts that the operations 
return bool.
+//  AssertComparisonsXConvertibleToBool static_asserts that the operations 
return something convertible to bool.
+
+
+#ifndef TEST_COMPARISONS_H
+#define TEST_COMPARISONS_H
+
+#include 
+#include "test_macros.h"
+
+//  Test all six comparison operations for sanity
+template 
+TEST_CONSTEXPR_CXX14 bool testComparisons6(const T& t1, const T& t2, bool 
isEqual, bool isLess)
+{
+if (isEqual)
+{
+if (!(t1 == t2)) return false;
+if (!(t2 == t1)) return false;
+if ( (t1 != t2)) return false;
+if ( (t2 != t1)) return false;
+if ( (t1  < t2)) return false;
+if ( (t2  < t1)) return false;
+if (!(t1 <= t2)) return false;
+if (!(t2 <= t1)) return false;
+if ( (t1  > t2)) return false;
+if ( (t2  > t1)) return false;
+if (!(t1 >= t2)) return false;
+if (!(t2 >= t1)) return false;
+}
+else if (isLess)
+{
+if ( (t1 == t2)) return false;
+if ( (t2 == t1)) return false;
+if (!(t1 != t2)) return false;
+if (!(t2 != t1)) return false;
+if (!(t1  < t2)) return false;
+if ( (t2  < t1)) return false;
+if (!(t1 <= t2)) return false;
+if ( (t2 <= t1)) return false;
+if ( (t1  > t2)) return false;
+if (!(t2  > t1)) return false;
+if ( (t1 >= t2)) return false;
+if (!(t2 >= t1)) return false;
+}
+else /* greater */
+{
+if ( (t1 == t2)) return false;
+if ( (t2 == t1)) return false;
+if (!(t1 != t2)) return false;
+if (!(t2 != t1)) return false;
+if ( (t1  < t2)) return false;
+if (!(t2  < t1)) return false;
+if ( (t1 <= t2)) return false;
+if (!(t2 <= t1)) return false;
+if (!(t1  > t2)) return false;
+if ( (t2  > t1)) return false;
+if (!(t1 >= t2)) return false;
+if ( (t2 >= t1)) return false;
+}
+
+return true;
+}
+
+//  Easy call when you can init from something already comparable.
+template 
+TEST_CONSTEXPR_CXX14 bool testComparisons6Values(Param val1, Param val2)
+{
+const bool isEqual = val1 == val2;
+const bool isLess  = val1  < val2;
+
+return testComparisons6(T{val1}, T{val2}, isEqual, isLess);
+}
+
+template 
+void AssertComparisons6AreNoexcept()
+{
+ASSERT_NOEXCEPT(std::declval() == std::declval());
+ASSERT_NOEXCEPT(std::declval() != std::declval());
+ASSERT_NOEXCEPT(std::declval() <  std::declval());
+ASSERT_NOEXCEPT(std::declval() <= std::declval());
+ASSERT_NOEXCEPT(std::declval() >  std::declval());
+ASSERT_NOEXCEPT(std::declval() >= std::declval());
+}
+
+template 
+void AssertComparisons6ReturnBool()
+{
+ASSERT_SAME_TYPE(decltype(std::declval() == std::declval()), bool);
+ASSERT_SAME_TYPE(decltype(std::declval() != std::declval()), bool);
+ASSERT_SAME_TYPE(decltype(std::declval() <  std::declval()), bool);
+ASSERT_SAME_TYPE(decltype(std::declval() <= std::declval()), bool);
+ASSERT_SAME_TYPE(decltype(std::declval() >  std::declval()), bool);
+ASSERT_SAME_TYPE(decltype(std::declval() >= std::declval()), bool);
+}
+
+
+template 
+void AssertComparisons6ConvertibleToBool()
+{
+static_assert((std::is_convertible() == 
std::declval()), bool>::value), "");
+static_assert((std::is_convertible() != 
std::declval()), bool>::value), "");
+static_assert((std::is_convertible() <  
std::declval()), bool>::value), "");
+static_assert((std::is_convertible() <= 
std::declval()), bool>::value), "");
+static_assert((std::is_convertible() >  

[libcxx] r337886 - Fix missing includes in format_string.hpp helper

2018-07-24 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Tue Jul 24 21:21:59 2018
New Revision: 337886

URL: http://llvm.org/viewvc/llvm-project?rev=337886=rev
Log:
Fix missing includes in format_string.hpp helper

Modified:
libcxx/trunk/test/support/format_string.hpp

Modified: libcxx/trunk/test/support/format_string.hpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/format_string.hpp?rev=337886=337885=337886=diff
==
--- libcxx/trunk/test/support/format_string.hpp (original)
+++ libcxx/trunk/test/support/format_string.hpp Tue Jul 24 21:21:59 2018
@@ -5,23 +5,24 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace format_string_detail {
 inline std::string format_string_imp(const char* msg, ...) {
   // we might need a second shot at this, so pre-emptivly make a copy
   struct GuardVAList {
-va_list& target;
+va_list& xtarget;
 bool active;
-GuardVAList(va_list& target) : target(target), active(true) {}
+GuardVAList(va_list& val) : xtarget(val), active(true) {}
 
 void clear() {
   if (active)
-va_end(target);
+va_end(xtarget);
   active = false;
 }
 ~GuardVAList() {
   if (active)
-va_end(target);
+va_end(xtarget);
 }
   };
   va_list args;


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


[PATCH] D49773: Add new file test/support/test_comparisons.h

2018-07-24 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF accepted this revision.
EricWF added a comment.
This revision is now accepted and ready to land.

Otherwise, I'm quite happy with this patch.

The only downside I see is if `testComparisons6` fails, it will report the 
source of the failure as being in the header, and not provide information about 
the callee.
But I think having simpler tests to read and write is more important. Hopefully 
they shouldn't be falling too often anyway :-P


https://reviews.llvm.org/D49773



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


[libcxx] r337884 - Make explicitly require C++11.

2018-07-24 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Tue Jul 24 20:41:31 2018
New Revision: 337884

URL: http://llvm.org/viewvc/llvm-project?rev=337884=rev
Log:
Make  explicitly require C++11.

Previously the  didn't guard its
contents in any dialect. However, the implementation implicitly
requires at least C++11, and the tests have always been marked
unsupported in C++03. This patch puts a header guard around the
contents to avoid exposing them before C++11.

Additionally, it replaces all of the usages of _NOEXCEPT or
_LIBCPP_CONSTEXPR with the keyword directly, since we can
expect the compiler to implement those by now.

Modified:
libcxx/trunk/include/experimental/filesystem
libcxx/trunk/src/experimental/filesystem/filesystem_common.h

libcxx/trunk/test/std/experimental/filesystem/fs.req.macros/feature_macro.pass.cpp

Modified: libcxx/trunk/include/experimental/filesystem
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/filesystem?rev=337884=337883=337884=diff
==
--- libcxx/trunk/include/experimental/filesystem (original)
+++ libcxx/trunk/include/experimental/filesystem Tue Jul 24 20:41:31 2018
@@ -16,15 +16,15 @@
 
 class path;
 
-void swap(path& lhs, path& rhs) _NOEXCEPT;
-size_t hash_value(const path& p) _NOEXCEPT;
+void swap(path& lhs, path& rhs) noexcept;
+size_t hash_value(const path& p) noexcept;
 
-bool operator==(const path& lhs, const path& rhs) _NOEXCEPT;
-bool operator!=(const path& lhs, const path& rhs) _NOEXCEPT;
-bool operator< (const path& lhs, const path& rhs) _NOEXCEPT;
-bool operator<=(const path& lhs, const path& rhs) _NOEXCEPT;
-bool operator> (const path& lhs, const path& rhs) _NOEXCEPT;
-bool operator>=(const path& lhs, const path& rhs) _NOEXCEPT;
+bool operator==(const path& lhs, const path& rhs) noexcept;
+bool operator!=(const path& lhs, const path& rhs) noexcept;
+bool operator< (const path& lhs, const path& rhs) noexcept;
+bool operator<=(const path& lhs, const path& rhs) noexcept;
+bool operator> (const path& lhs, const path& rhs) noexcept;
+bool operator>=(const path& lhs, const path& rhs) noexcept;
 
 path operator/ (const path& lhs, const path& rhs);
 
@@ -96,88 +96,88 @@
 
 void copy_symlink(const path& existing_symlink, const path& new_symlink);
 void copy_symlink(const path& existing_symlink, const path& new_symlink,
-  error_code& ec) _NOEXCEPT;
+  error_code& ec) noexcept;
 
 bool create_directories(const path& p);
 bool create_directories(const path& p, error_code& ec);
 
 bool create_directory(const path& p);
-bool create_directory(const path& p, error_code& ec) _NOEXCEPT;
+bool create_directory(const path& p, error_code& ec) noexcept;
 
 bool create_directory(const path& p, const path& attributes);
 bool create_directory(const path& p, const path& attributes,
-  error_code& ec) _NOEXCEPT;
+  error_code& ec) noexcept;
 
 void create_directory_symlink(const path& to, const path& new_symlink);
 void create_directory_symlink(const path& to, const path& new_symlink,
-  error_code& ec) _NOEXCEPT;
+  error_code& ec) noexcept;
 
 void create_hard_link(const path& to, const path& new_hard_link);
 void create_hard_link(const path& to, const path& new_hard_link,
-  error_code& ec) _NOEXCEPT;
+  error_code& ec) noexcept;
 
 void create_symlink(const path& to, const path& new_symlink);
 void create_symlink(const path& to, const path& new_symlink,
-error_code& ec) _NOEXCEPT;
+error_code& ec) noexcept;
 
 path current_path();
 path current_path(error_code& ec);
 void current_path(const path& p);
-void current_path(const path& p, error_code& ec) _NOEXCEPT;
+void current_path(const path& p, error_code& ec) noexcept;
 
-bool exists(file_status s) _NOEXCEPT;
+bool exists(file_status s) noexcept;
 bool exists(const path& p);
-bool exists(const path& p, error_code& ec) _NOEXCEPT;
+bool exists(const path& p, error_code& ec) noexcept;
 
 bool equivalent(const path& p1, const path& p2);
-bool equivalent(const path& p1, const path& p2, error_code& ec) _NOEXCEPT;
+bool equivalent(const path& p1, const path& p2, error_code& ec) noexcept;
 
 uintmax_tfile_size(const path& p);
-uintmax_tfile_size(const path& p, error_code& ec) _NOEXCEPT;
+uintmax_tfile_size(const path& p, error_code& ec) noexcept;
 
 uintmax_thard_link_count(const path& p);
-uintmax_thard_link_count(const path& p, error_code& ec) _NOEXCEPT;
+uintmax_thard_link_count(const path& p, error_code& 

[libcxx] r337883 - Ensure path::iterator and PathParser share the same enumeration values.

2018-07-24 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Tue Jul 24 20:31:48 2018
New Revision: 337883

URL: http://llvm.org/viewvc/llvm-project?rev=337883=rev
Log:
Ensure path::iterator and PathParser share the same enumeration values.

To avoid exposing implementation details, path::iterator and PathParser
both implicitly used the same set of values to represent the state,
but they were defined twice. This could have lead to a mismatch
occuring.

This patch moves all of the parser state values into the filesystem
header and changes PathParser to use those value to avoid this.

Modified:
libcxx/trunk/include/experimental/filesystem
libcxx/trunk/src/experimental/filesystem/operations.cpp

Modified: libcxx/trunk/include/experimental/filesystem
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/filesystem?rev=337883=337882=337883=diff
==
--- libcxx/trunk/include/experimental/filesystem (original)
+++ libcxx/trunk/include/experimental/filesystem Tue Jul 24 20:31:48 2018
@@ -1037,7 +1037,7 @@ public:
 _LIBCPP_INLINE_VISIBILITY path extension()  const { return 
string_type(__extension()); }
 
 // query
-_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 
+_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
 bool empty() const _NOEXCEPT { return __pn_.empty(); }
 
 _LIBCPP_INLINE_VISIBILITY bool has_root_name()  const { return 
!__root_name().empty(); }
@@ -1170,6 +1170,17 @@ u8path(_InputIt __f, _InputIt __l) {
 class _LIBCPP_TYPE_VIS path::iterator
 {
 public:
+enum _ParserState : unsigned char {
+  _Singular,
+  _BeforeBegin,
+  _InRootName,
+  _InRootDir,
+  _InFilenames,
+  _InTrailingSep,
+  _AtEnd
+};
+
+public:
 typedef bidirectional_iterator_tag iterator_category;
 
 typedef path   value_type;
@@ -1178,10 +1189,11 @@ public:
 typedef const path&reference;
 
 typedef void __stashing_iterator_tag; // See reverse_iterator and 
__is_stashing_iterator
+
 public:
 _LIBCPP_INLINE_VISIBILITY
 iterator() : __stashed_elem_(), __path_ptr_(nullptr),
- __entry_(), __state_(__singular) {}
+ __entry_(), __state_(_Singular) {}
 
 iterator(const iterator&) = default;
 ~iterator() = default;
@@ -1200,9 +1212,9 @@ public:
 
 _LIBCPP_INLINE_VISIBILITY
 iterator& operator++() {
-_LIBCPP_ASSERT(__state_ != __singular,
+_LIBCPP_ASSERT(__state_ != _Singular,
"attempting to increment a singular iterator");
-_LIBCPP_ASSERT(__state_ != __at_end,
+_LIBCPP_ASSERT(__state_ != _AtEnd,
   "attempting to increment the end iterator");
 return __increment();
 }
@@ -1216,7 +1228,7 @@ public:
 
 _LIBCPP_INLINE_VISIBILITY
 iterator& operator--() {
-_LIBCPP_ASSERT(__state_ != __singular,
+_LIBCPP_ASSERT(__state_ != _Singular,
"attempting to decrement a singular iterator");
 _LIBCPP_ASSERT(__entry_.data() != __path_ptr_->native().data(),
"attempting to decrement the begin iterator");
@@ -1233,9 +1245,6 @@ public:
 private:
 friend class path;
 
-static constexpr unsigned char __singular = 0;
-static constexpr unsigned char __at_end = 6;
-
 inline _LIBCPP_INLINE_VISIBILITY
 friend bool operator==(const iterator&, const iterator&);
 
@@ -1245,7 +1254,7 @@ private:
 path __stashed_elem_;
 const path* __path_ptr_;
 path::__string_view __entry_;
-unsigned char __state_;
+_ParserState __state_;
 };
 
 inline _LIBCPP_INLINE_VISIBILITY

Modified: libcxx/trunk/src/experimental/filesystem/operations.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/experimental/filesystem/operations.cpp?rev=337883=337882=337883=diff
==
--- libcxx/trunk/src/experimental/filesystem/operations.cpp (original)
+++ libcxx/trunk/src/experimental/filesystem/operations.cpp Tue Jul 24 20:31:48 
2018
@@ -57,12 +57,12 @@ using PosPtr = path::value_type const*;
 struct PathParser {
   enum ParserState : unsigned char {
 // Zero is a special sentinel value used by default constructed iterators.
-PS_BeforeBegin = 1,
-PS_InRootName,
-PS_InRootDir,
-PS_InFilenames,
-PS_InTrailingSep,
-PS_AtEnd
+PS_BeforeBegin = path::iterator::_BeforeBegin,
+PS_InRootName = path::iterator::_InRootName,
+PS_InRootDir = path::iterator::_InRootDir,
+PS_InFilenames = path::iterator::_InFilenames,
+PS_InTrailingSep = path::iterator::_InTrailingSep,
+PS_AtEnd = path::iterator::_AtEnd
   };
 
   const string_view_t Path;
@@ -1548,7 +1548,7 @@ path::iterator path::begin() const
 auto PP = PathParser::CreateBegin(__pn_);
 iterator it;
 it.__path_ptr_ = this;
-it.__state_ = PP.State;
+it.__state_ 

[PATCH] D49773: Add new file test/support/test_comparisons.h

2018-07-24 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

> Can they be non-constexpr in C++11 and still function?

Sure. I'll fix that.


https://reviews.llvm.org/D49773



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


[PATCH] D49774: [libc++] Use __int128_t to represent file_time_type.

2018-07-24 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

This is the final change I need to land before adding 
``, so I don't plan to let this review linger long.

If you have any strong objections, please speak now or forever hold your peace 
(or at least until the next ABI break, whichever comes first).


Repository:
  rCXX libc++

https://reviews.llvm.org/D49774



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


[PATCH] D49773: Add new file test/support/test_comparisons.h

2018-07-24 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

Some of this stuff is marked `constexpr` despite it requiring C++14 constexpr 
semantics.  Can they be non-constexpr in C++11 and still function? Or should 
the header explicitly require C++14 to be included?


https://reviews.llvm.org/D49773



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


r337881 - [profile] Support profiling runtime on Fuchsia

2018-07-24 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Tue Jul 24 20:01:35 2018
New Revision: 337881

URL: http://llvm.org/viewvc/llvm-project?rev=337881=rev
Log:
[profile] Support profiling runtime on Fuchsia

This ports the profiling runtime on Fuchsia and enables the
instrumentation. Unlike on other platforms, Fuchsia doesn't use
files to dump the instrumentation data since on Fuchsia, filesystem
may not be accessible to the instrumented process. We instead use
the data sink to pass the profiling data to the system the same
sanitizer runtimes do.

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

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

Modified: cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp?rev=337881=337880=337881=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp Tue Jul 24 20:01:35 2018
@@ -109,6 +109,7 @@ void fuchsia::Linker::ConstructJob(Compi
   addSanitizerRuntimes(ToolChain, Args, CmdArgs);
 
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
+  ToolChain.addProfileRTLibs(Args, CmdArgs);
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
 if (Args.hasArg(options::OPT_static))


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


[PATCH] D49774: [libc++] Use __int128_t to represent file_time_type.

2018-07-24 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF created this revision.
EricWF added reviewers: mclow.lists, ldionne, joerg, arthur.j.odwyer.
Herald added subscribers: cfe-commits, christof.

The ``file_time_type`` time point is used to represent the write times for 
files.
Its job is to act as part of a C++ wrapper for less ideal system interfaces. The
underlying filesystem uses the ``timespec`` struct for the same purpose.

However, the initial implementation of ``file_time_type`` could not represent
either the range or resolution of ``timespec``, making it unsuitable. Fixing
this requires an implementation which uses more than 64 bits to store the
time point.

I primarily considered two solutions: Using ``__int128_t`` and using a
arithmetic emulation of ``timespec``. Each has its pros and cons, and both
come with more than one complication.

However, after a lot of consideration, I decided on using `__int128_t`. This 
patch implements that change.

Please see the FileTimeType Design Document 
 for more information.


Repository:
  rCXX libc++

https://reviews.llvm.org/D49774

Files:
  include/experimental/filesystem
  src/chrono.cpp
  src/experimental/filesystem/filesystem_common.h
  src/experimental/filesystem/operations.cpp
  src/include/apple_availability.h
  
test/libcxx/experimental/filesystem/class.directory_entry/directory_entry.mods/last_write_time.sh.cpp
  test/libcxx/experimental/filesystem/convert_file_time.sh.cpp
  
test/std/experimental/filesystem/fs.filesystem.synopsis/file_time_type.pass.cpp
  
test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp

Index: test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
===
--- test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
+++ test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
@@ -30,13 +30,87 @@
 #include 
 #include 
 
+#include 
+#include 
+
 using namespace fs;
 
-struct Times { std::time_t access, write; };
+using TimeSpec = struct ::timespec;
+using StatT = struct ::stat;
+
+using Sec = std::chrono::duration;
+using Hours = std::chrono::hours;
+using Minutes = std::chrono::minutes;
+using MicroSec = std::chrono::duration;
+using NanoSec = std::chrono::duration;
+using std::chrono::duration_cast;
+
+#if defined(__APPLE__)
+TimeSpec extract_mtime(StatT const& st) { return st.st_mtimespec; }
+TimeSpec extract_atime(StatT const& st) { return st.st_atimespec; }
+#else
+TimeSpec extract_mtime(StatT const& st) { return st.st_mtim; }
+TimeSpec extract_atime(StatT const& st) { return st.st_atim; }
+#endif
+
+bool ConvertToTimeSpec(TimeSpec& ts, file_time_type ft) {
+  using SecFieldT = decltype(TimeSpec::tv_sec);
+  using NSecFieldT = decltype(TimeSpec::tv_nsec);
+  using SecLim = std::numeric_limits;
+  using NSecLim = std::numeric_limits;
+
+  auto secs = duration_cast(ft.time_since_epoch());
+  auto nsecs = duration_cast(ft.time_since_epoch() - secs);
+  if (nsecs.count() < 0) {
+if (Sec::min().count() > SecLim::min()) {
+  secs += Sec(1);
+  nsecs -= Sec(1);
+} else {
+  nsecs = NanoSec(0);
+  //return false;
+}
+  }
+  if (SecLim::max() < secs.count() || SecLim::min() > secs.count())
+return false;
+  if (NSecLim::max() < nsecs.count() || NSecLim::min() > nsecs.count())
+return false;
+  ts.tv_sec = secs.count();
+  ts.tv_nsec = nsecs.count();
+  return true;
+}
+
+bool ConvertFromTimeSpec(file_time_type& ft, TimeSpec ts) {
+  auto secs_part = duration_cast(Sec(ts.tv_sec));
+  if (duration_cast(secs_part).count() != ts.tv_sec)
+return false;
+  auto subsecs = duration_cast(NanoSec(ts.tv_nsec));
+  auto dur = secs_part + subsecs;
+  if (dur < secs_part && subsecs.count() >= 0)
+return false;
+  ft = file_time_type(dur);
+  return true;
+}
+
+bool CompareTimeExact(TimeSpec ts, TimeSpec ts2) {
+  return ts2.tv_sec == ts.tv_sec && ts2.tv_nsec == ts.tv_nsec;
+}
+bool CompareTimeExact(file_time_type ft, TimeSpec ts) {
+  TimeSpec ts2 = {};
+  if (!ConvertToTimeSpec(ts2, ft))
+return false;
+  return CompareTimeExact(ts, ts2);
+}
+bool CompareTimeExact(TimeSpec ts, file_time_type ft) {
+  return CompareTimeExact(ft, ts);
+}
+
+struct Times {
+  TimeSpec access, write;
+};
 
 Times GetTimes(path const& p) {
 using Clock = file_time_type::clock;
-struct ::stat st;
+StatT st;
 if (::stat(p.c_str(), ) == -1) {
 std::error_code ec(errno, std::generic_category());
 #ifndef TEST_HAS_NO_EXCEPTIONS
@@ -46,47 +120,29 @@
 std::exit(EXIT_FAILURE);
 #endif
 }
-return {st.st_atime, st.st_mtime};
+return {extract_atime(st), extract_mtime(st)};
 }
 
-std::time_t LastAccessTime(path const& p) {
-return GetTimes(p).access;
-}
+TimeSpec LastAccessTime(path const& p) { return GetTimes(p).access; }
 
-std::time_t LastWriteTime(path const& p) {

[libcxx] r337880 - Add design docs for upcoming file_time_type change.

2018-07-24 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Tue Jul 24 19:53:53 2018
New Revision: 337880

URL: http://llvm.org/viewvc/llvm-project?rev=337880=rev
Log:
Add design docs for upcoming file_time_type change.

In upcoming changes to filesystem I plan to change file_time_type
to use __int128_t as its underlying representation, in order
to allow it to have a range and resolution at least that of
the timespec struct.

There was some pushback against this decision, so I drafted
a document explaining the problems, potential solutions, and
the rational for the decision.

However, it's probably easier to let people read the generated
HTML rather than the raw restructured text. For this reason
I'm commiting the design documents before hand, so they can
be available during any subsequent discussion or code review.

Added:
libcxx/trunk/docs/DesignDocs/FileTimeType.rst
Modified:
libcxx/trunk/docs/Makefile.sphinx
libcxx/trunk/docs/index.rst

Added: libcxx/trunk/docs/DesignDocs/FileTimeType.rst
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/docs/DesignDocs/FileTimeType.rst?rev=337880=auto
==
--- libcxx/trunk/docs/DesignDocs/FileTimeType.rst (added)
+++ libcxx/trunk/docs/DesignDocs/FileTimeType.rst Tue Jul 24 19:53:53 2018
@@ -0,0 +1,493 @@
+==
+File Time Type
+==
+
+.. contents::
+   :local:
+
+.. _file-time-type-motivation:
+
+Motivation
+==
+
+The filesystem library provides interfaces for getting and setting the last
+write time of a file or directory. The interfaces use the ``file_time_type``
+type, which is a specialization of ``chrono::time_point`` for the
+"filesystem clock". According to [fs.filesystem.syn]
+
+  trivial-clock is an implementation-defined type that satisfies the
+  Cpp17TrivialClock requirements ([time.clock.req]) and that is capable of
+  representing and measuring file time values. Implementations should ensure
+  that the resolution and range of file_­time_­type reflect the operating
+  system dependent resolution and range of file time values.
+
+
+On POSIX systems, file times are represented using the ``timespec`` struct,
+which is defined as follows:
+
+.. code-block:: cpp
+
+  struct timespec {
+time_t tv_sec;
+long   tv_nsec;
+  };
+
+To represent the range and resolution of ``timespec``, we need to (A) have
+nanosecond resolution, and (B) use more than 64 bits (assuming a 64 bit 
``time_t``).
+
+As the standard requires us to use the ``chrono`` interface, we have to define
+our own filesystem clock which specifies the period and representation of
+the time points and duration it provides. It will look like this:
+
+.. code-block:: cpp
+
+  struct _FilesystemClock {
+using period = nano;
+using rep = TBD; // What is this?
+
+using duration = chrono::duration;
+using time_point = chrono::time_point<_FilesystemClock>;
+
+// ... //
+  };
+
+  using file_time_type = _FilesystemClock::time_point;
+
+
+To get nanosecond resolution, we simply define ``period`` to be ``std::nano``.
+But what type can we use as the arithmetic representation that is capable
+of representing the range of the ``timespec`` struct?
+
+Problems To Consider
+
+
+Before considering solutions, lets consider the problems they should solve,
+and how important solving those problems are:
+
+
+Having a Smaller Range than ``timespec``
+
+
+One solution to the range problem is to simply reduce the resolution of
+``file_time_type`` to be less than that of nanoseconds. This is what libc++'s
+initial implementation of ``file_time_type`` did; it's also what
+``std::system_clock`` does. As a result, it can represent time points about
+292 thousand years on either side of the epoch, as opposed to only 292 years
+at nanosecond resolution.
+
+``timespec`` can represent time points +/- 292 billion years from the epoch
+(just in case you needed a time point 200 billion years before the big bang,
+and with nanosecond resolution).
+
+To get the same range, we would need to drop our resolution to that of seconds
+to come close to having the same range.
+
+This begs the question, is the range problem "really a problem"? Sane usages
+of file time stamps shouldn't exceed +/- 300, so should we care to support it?
+
+I believe the answer is yes. We're not designing the filesystem time API, we're
+providing glorified C++ wrappers for it. If the underlying API supports
+a value, then we should too. Our wrappers should not place artificial 
restrictions
+on users that are not present in the underlying filesystem.
+
+Additionally, having a smaller range that the underlying filesystem forces the
+implementation to report ``value_too_large`` errors when it encounters a time
+point that it can't represent. This can cause the call to ``last_write_time``
+to throw in cases where the user was confident the call should succeed. (See 
below)
+
+
+.. code-block:: cpp
+
+ 

[PATCH] D49114: [clang-tidy] Add a check for "magic numbers"

2018-07-24 Thread Florin Iucha via Phabricator via cfe-commits
0x8000- updated this revision to Diff 157187.
0x8000- added a comment.

Update links in documentation


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49114

Files:
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/MagicNumbersCheck.cpp
  clang-tidy/readability/MagicNumbersCheck.h
  clang-tidy/readability/ReadabilityTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-avoid-magic-numbers.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-magic-numbers.rst
  test/clang-tidy/readability-magic-numbers.cpp

Index: test/clang-tidy/readability-magic-numbers.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-magic-numbers.cpp
@@ -0,0 +1,192 @@
+// RUN: %check_clang_tidy %s readability-magic-numbers %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: readability-magic-numbers.IgnoredIntegerValues, value: "0;1;2;10;100;"}]}' \
+// RUN: --
+
+template 
+struct ValueBucket {
+  T value[V];
+};
+
+int BadGlobalInt = 5;
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: 5 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+int IntSquarer(int param) {
+  return param * param;
+}
+
+void BuggyFunction() {
+  int BadLocalInt = 6;
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: 6 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+  (void)IntSquarer(7);
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: 7 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+  int LocalArray[8];
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 8 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+  for (int ii = 0; ii < 8; ++ii)
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 8 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+  {
+LocalArray[ii] = 3 * ii;
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 3 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+  }
+
+  ValueBucket Bucket;
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: 4 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+}
+
+class TwoIntContainer {
+public:
+  TwoIntContainer(int val) : anotherMember(val * val), yetAnotherMember(6), anotherConstant(val + val) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:73: warning: 6 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+  int getValue() const;
+
+private:
+  int oneMember = 9;
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 9 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+  int anotherMember;
+
+  int yetAnotherMember;
+
+  const int oneConstant = 2;
+
+  const int anotherConstant;
+};
+
+int ValueArray[] = {3, 5};
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: 3 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+// CHECK-MESSAGES: :[[@LINE-2]]:24: warning: 5 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+float FloatPiVariable = 3.1415926535f;
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 3.1415926535f is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+double DoublePiVariable = 6.283185307;
+// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 6.283185307 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+int getAnswer() {
+  if (ValueArray[0] < ValueArray[1])
+return ValueArray[1];
+
+  return -3; // FILENOTFOUND
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 3 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+}
+
+/*
+ * Clean code
+ */
+
+#define INT_MACRO 5
+
+const int GoodGlobalIntConstant = 42;
+
+constexpr int AlsoGoodGlobalIntConstant = 42;
+
+int InitializedByMacro = INT_MACRO;
+
+void SolidFunction() {
+  const int GoodLocalIntConstant = 43;
+
+  (void)IntSquarer(GoodLocalIntConstant);
+
+  int LocalArray[INT_MACRO];
+
+  ValueBucket Bucket;
+}
+
+const int ConstValueArray[] = {7, 9};
+
+const int ConstValueArray2D[2][2] = {{7, 9}, {13, 15}};
+
+/*
+ * no warnings for ignored values (specified in the configuration above)
+ */
+int GrandfatheredValues[] = {0, 1, 2, 10, 100, -1, -10, -100};
+
+/*
+ * no warnings for enums
+ */
+enum Smorgasbord {
+  STARTER,
+  ALPHA = 3,
+  BETA = 1 << 5,
+};
+
+const float FloatPiConstant = 3.1415926535f;
+const double DoublePiConstant = 6.283185307;
+
+const float Angles[] = {45.0f, 90.0f, 135.0f};
+
+double DoubleZeroIsAccepted = 0.0;
+float FloatZeroIsAccepted = 0.0f;
+
+namespace geometry {
+
+template 
+struct Point {
+  T x;
+  T y;
+
+  explicit Point(T xval, T yval) noexcept : 

[PATCH] D49114: [clang-tidy] Add a check for "magic numbers"

2018-07-24 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: docs/clang-tidy/checks/readability-magic-numbers.rst:56
+By default only `0`, `1` and `-1` integer values are accepted without a 
warning.
+This can be overridden with the 'IgnoredIntegerValues' option.  In addition,
+the `0.0` floating point value is accepted. There is no configuration for

Sorry, almost forgot. Please prefix IgnoredIntegerValues with :option:. You 
still need to use ` for it.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49114



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


[PATCH] D49114: [clang-tidy] Add a check for "magic numbers"

2018-07-24 Thread Florin Iucha via Phabricator via cfe-commits
0x8000- updated this revision to Diff 157186.
0x8000- added a comment.

Fix a few typos


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49114

Files:
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/MagicNumbersCheck.cpp
  clang-tidy/readability/MagicNumbersCheck.h
  clang-tidy/readability/ReadabilityTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-avoid-magic-numbers.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-magic-numbers.rst
  test/clang-tidy/readability-magic-numbers.cpp

Index: test/clang-tidy/readability-magic-numbers.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-magic-numbers.cpp
@@ -0,0 +1,192 @@
+// RUN: %check_clang_tidy %s readability-magic-numbers %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: readability-magic-numbers.IgnoredIntegerValues, value: "0;1;2;10;100;"}]}' \
+// RUN: --
+
+template 
+struct ValueBucket {
+  T value[V];
+};
+
+int BadGlobalInt = 5;
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: 5 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+int IntSquarer(int param) {
+  return param * param;
+}
+
+void BuggyFunction() {
+  int BadLocalInt = 6;
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: 6 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+  (void)IntSquarer(7);
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: 7 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+  int LocalArray[8];
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 8 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+  for (int ii = 0; ii < 8; ++ii)
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 8 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+  {
+LocalArray[ii] = 3 * ii;
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 3 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+  }
+
+  ValueBucket Bucket;
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: 4 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+}
+
+class TwoIntContainer {
+public:
+  TwoIntContainer(int val) : anotherMember(val * val), yetAnotherMember(6), anotherConstant(val + val) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:73: warning: 6 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+  int getValue() const;
+
+private:
+  int oneMember = 9;
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 9 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+  int anotherMember;
+
+  int yetAnotherMember;
+
+  const int oneConstant = 2;
+
+  const int anotherConstant;
+};
+
+int ValueArray[] = {3, 5};
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: 3 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+// CHECK-MESSAGES: :[[@LINE-2]]:24: warning: 5 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+float FloatPiVariable = 3.1415926535f;
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 3.1415926535f is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+double DoublePiVariable = 6.283185307;
+// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 6.283185307 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+int getAnswer() {
+  if (ValueArray[0] < ValueArray[1])
+return ValueArray[1];
+
+  return -3; // FILENOTFOUND
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 3 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+}
+
+/*
+ * Clean code
+ */
+
+#define INT_MACRO 5
+
+const int GoodGlobalIntConstant = 42;
+
+constexpr int AlsoGoodGlobalIntConstant = 42;
+
+int InitializedByMacro = INT_MACRO;
+
+void SolidFunction() {
+  const int GoodLocalIntConstant = 43;
+
+  (void)IntSquarer(GoodLocalIntConstant);
+
+  int LocalArray[INT_MACRO];
+
+  ValueBucket Bucket;
+}
+
+const int ConstValueArray[] = {7, 9};
+
+const int ConstValueArray2D[2][2] = {{7, 9}, {13, 15}};
+
+/*
+ * no warnings for ignored values (specified in the configuration above)
+ */
+int GrandfatheredValues[] = {0, 1, 2, 10, 100, -1, -10, -100};
+
+/*
+ * no warnings for enums
+ */
+enum Smorgasbord {
+  STARTER,
+  ALPHA = 3,
+  BETA = 1 << 5,
+};
+
+const float FloatPiConstant = 3.1415926535f;
+const double DoublePiConstant = 6.283185307;
+
+const float Angles[] = {45.0f, 90.0f, 135.0f};
+
+double DoubleZeroIsAccepted = 0.0;
+float FloatZeroIsAccepted = 0.0f;
+
+namespace geometry {
+
+template 
+struct Point {
+  T x;
+  T y;
+
+  explicit Point(T xval, T yval) noexcept : x{xval}, y{yval} {
+ 

[PATCH] D49773: Add new file test/support/test_comparisons.h

2018-07-24 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

Usage looks like this:

  AssertComparisons6AreNoexcept();
  AssertComparisons6ReturnBool();
  
  static_assert(testComparisons6Values( 5U,  5U), "");
  static_assert(testComparisons6Values( 5U, 10U), "");
  static_assert(testComparisons6Values(10U,  5U), "");


https://reviews.llvm.org/D49773



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


[PATCH] D49773: Add new file test/support/test_comparisons.h

2018-07-24 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists created this revision.
mclow.lists added reviewers: ldionne, EricWF.

As I've been plowing through the `` stuff, I found myself writing tests 
to make sure that the comparisons for a bunch of different types are "sane".

So I factored them out into something that can be used over and over.


https://reviews.llvm.org/D49773

Files:
  test/support/test_comparisons.h

Index: test/support/test_comparisons.h
===
--- test/support/test_comparisons.h
+++ test/support/test_comparisons.h
@@ -0,0 +1,175 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+//  A set of routines for testing the comparison operators of a type
+//
+//  6 tests all six comparison operators
+//  2 tests only op== and op!=
+//
+//  AssertComparisonsXAreNoexcept   static_asserts that the operations are all noexcept.
+//  AssertComparisonsXReturnBoolstatic_asserts that the operations return bool.
+//  AssertComparisonsXConvertibleToBool static_asserts that the operations return something convertible to bool.
+
+
+#ifndef TEST_COMPARISONS_H
+#define TEST_COMPARISONS_H
+
+#include 
+#include "test_macros.h"
+
+//  Test all six comparison operations for sanity
+template 
+constexpr bool testComparisons6(const T& t1, const T& t2, bool isEqual, bool isLess)
+{
+if (isEqual)
+{
+if (!(t1 == t2)) return false;
+if (!(t2 == t1)) return false;
+if ( (t1 != t2)) return false;
+if ( (t2 != t1)) return false;
+if ( (t1  < t2)) return false;
+if ( (t2  < t1)) return false;
+if (!(t1 <= t2)) return false;
+if (!(t2 <= t1)) return false;
+if ( (t1  > t2)) return false;
+if ( (t2  > t1)) return false;
+if (!(t1 >= t2)) return false;
+if (!(t2 >= t1)) return false;
+}
+else if (isLess)
+{
+if ( (t1 == t2)) return false;
+if ( (t2 == t1)) return false;
+if (!(t1 != t2)) return false;
+if (!(t2 != t1)) return false;
+if (!(t1  < t2)) return false;
+if ( (t2  < t1)) return false;
+if (!(t1 <= t2)) return false;
+if ( (t2 <= t1)) return false;
+if ( (t1  > t2)) return false;
+if (!(t2  > t1)) return false;
+if ( (t1 >= t2)) return false;
+if (!(t2 >= t1)) return false;
+}
+else /* greater */
+{
+if ( (t1 == t2)) return false;
+if ( (t2 == t1)) return false;
+if (!(t1 != t2)) return false;
+if (!(t2 != t1)) return false;
+if ( (t1  < t2)) return false;
+if (!(t2  < t1)) return false;
+if ( (t1 <= t2)) return false;
+if (!(t2 <= t1)) return false;
+if (!(t1  > t2)) return false;
+if ( (t2  > t1)) return false;
+if (!(t1 >= t2)) return false;
+if ( (t2 >= t1)) return false;
+}
+
+return true;
+}
+
+//  Easy call when you can init from something already comparable.
+template 
+constexpr bool testComparisons6Values(Param val1, Param val2)
+{
+const bool isEqual = val1 == val2;
+const bool isLess  = val1  < val2;
+
+return testComparisons6(T{val1}, T{val2}, isEqual, isLess);
+}
+
+template 
+void AssertComparisons6AreNoexcept()
+{
+ASSERT_NOEXCEPT(std::declval() == std::declval());
+ASSERT_NOEXCEPT(std::declval() != std::declval());
+ASSERT_NOEXCEPT(std::declval() <  std::declval());
+ASSERT_NOEXCEPT(std::declval() <= std::declval());
+ASSERT_NOEXCEPT(std::declval() >  std::declval());
+ASSERT_NOEXCEPT(std::declval() >= std::declval());
+}
+
+template 
+void AssertComparisons6ReturnBool()
+{
+ASSERT_SAME_TYPE(decltype(std::declval() == std::declval()), bool);
+ASSERT_SAME_TYPE(decltype(std::declval() != std::declval()), bool);
+ASSERT_SAME_TYPE(decltype(std::declval() <  std::declval()), bool);
+ASSERT_SAME_TYPE(decltype(std::declval() <= std::declval()), bool);
+ASSERT_SAME_TYPE(decltype(std::declval() >  std::declval()), bool);
+ASSERT_SAME_TYPE(decltype(std::declval() >= std::declval()), bool);
+}
+
+
+template 
+void AssertComparisons6ConvertibleToBool()
+{
+static_assert((std::is_convertible() == std::declval()), bool>::value), "");
+static_assert((std::is_convertible() != std::declval()), bool>::value), "");
+static_assert((std::is_convertible() <  std::declval()), bool>::value), "");
+static_assert((std::is_convertible() <= std::declval()), bool>::value), "");
+static_assert((std::is_convertible() >  std::declval()), bool>::value), "");
+static_assert((std::is_convertible() >= std::declval()), 

[PATCH] D49114: [clang-tidy] Add a check for "magic numbers"

2018-07-24 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tidy/readability/MagicNumbersCheck.h:42
+return false;
+  };
+  bool isSyntheticValue(const clang::SourceManager *SourceManager,

Unnecessary semicolon. Please also add empty line after.



Comment at: docs/clang-tidy/checks/readability-magic-numbers.rst:55
+
+By default only 0, 1 and -1 integer values are accepted without a warning.
+This can be overriden with the 'IgnoredIntegerValues' option.  In addition,

Please enclose numbers in `. Same for 0.0.



Comment at: docs/clang-tidy/checks/readability-magic-numbers.rst:56
+By default only 0, 1 and -1 integer values are accepted without a warning.
+This can be overriden with the 'IgnoredIntegerValues' option.  In addition,
+the 0.0 floating point value is accepted. There is no configuration for

Please use `.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49114



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


[PATCH] D49114: [clang-tidy] Add a check for "magic numbers"

2018-07-24 Thread Florin Iucha via Phabricator via cfe-commits
0x8000- added a comment.

@aaron.ballman , @JonasToth , @Eugene.Zelenko  - would you be so kind to do one 
more review pass and let me know if there are any blockers or if this is ready 
to merge? I do not have commit privileges, so if it is alright, feel free to 
merge it.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49114



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


[libcxx] r337879 - Mark as complete

2018-07-24 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Tue Jul 24 18:55:25 2018
New Revision: 337879

URL: http://llvm.org/viewvc/llvm-project?rev=337879=rev
Log:
Mark  as complete

Modified:
libcxx/trunk/www/cxx2a_status.html

Modified: libcxx/trunk/www/cxx2a_status.html
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx2a_status.html?rev=337879=337878=337879=diff
==
--- libcxx/trunk/www/cxx2a_status.html (original)
+++ libcxx/trunk/www/cxx2a_status.html Tue Jul 24 18:55:25 2018
@@ -72,7 +72,7 @@
https://wg21.link/P0767R1;>P0767R1CWGDeprecate 
PODAlbuquerqueComplete7.0
https://wg21.link/P0768R1;>P0768R1CWGLibrary 
Support for the Spaceship (Comparison) 
OperatorAlbuquerque
https://wg21.link/P0777R1;>P0777R1LWGTreating 
Unnecessary 
decayAlbuquerqueComplete7.0
-   https://wg21.link/P0122R7;>P0122R7LWGspanJacksonvilleIn
 Progress
+   https://wg21.link/P0122R7;>P0122R7LWGspanJacksonvilleComplete7.0
https://wg21.link/P0355R7;>P0355R7LWGExtending 
chrono to Calendars and Time 
ZonesJacksonville
https://wg21.link/P0551R3;>P0551R3LWGThou Shalt Not 
Specialize std Function 
Templates!Jacksonville
https://wg21.link/P0753R2;>P0753R2LWGManipulators 
for C++ Synchronized Buffered 
OstreamJacksonville
@@ -222,7 +222,7 @@
 
   
 
-  Last Updated: 11-Jun-2018
+  Last Updated: 23-Jul-2018
 
 
 


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


[PATCH] D49628: [CMake] Link static libunwind and libc++abi into libc++ in Fuchsia toolchain

2018-07-24 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL337877: [CMake] Link static libunwind and libc++abi into 
libc++ in Fuchsia toolchain (authored by phosek, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D49628?vs=157182=157183#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D49628

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


Index: cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
===
--- cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
+++ cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
@@ -100,9 +100,15 @@
 set(RUNTIMES_${target}-fuchsia_CMAKE_SYSROOT ${FUCHSIA_${target}_SYSROOT} 
CACHE PATH "")
 set(RUNTIMES_${target}-fuchsia_LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
 set(RUNTIMES_${target}-fuchsia_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia_LIBUNWIND_INSTALL_STATIC_LIBRARY OFF CACHE 
BOOL "")
 set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
 set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL 
"")
+set(RUNTIMES_${target}-fuchsia_LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE 
BOOL "")
+set(RUNTIMES_${target}-fuchsia_LIBCXXABI_INSTALL_STATIC_LIBRARY OFF CACHE 
BOOL "")
+
set(RUNTIMES_${target}-fuchsia_LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY
 OFF CACHE BOOL "")
 set(RUNTIMES_${target}-fuchsia_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia_LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE 
BOOL "")
+
set(RUNTIMES_${target}-fuchsia_LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY OFF 
CACHE BOOL "")
   endforeach()
 
   set(LLVM_RUNTIME_SANITIZERS "Address" CACHE STRING "")


Index: cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
===
--- cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
+++ cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
@@ -100,9 +100,15 @@
 set(RUNTIMES_${target}-fuchsia_CMAKE_SYSROOT ${FUCHSIA_${target}_SYSROOT} CACHE PATH "")
 set(RUNTIMES_${target}-fuchsia_LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
 set(RUNTIMES_${target}-fuchsia_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia_LIBUNWIND_INSTALL_STATIC_LIBRARY OFF CACHE BOOL "")
 set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
 set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia_LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia_LIBCXXABI_INSTALL_STATIC_LIBRARY OFF CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia_LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY OFF CACHE BOOL "")
 set(RUNTIMES_${target}-fuchsia_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia_LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia_LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY OFF CACHE BOOL "")
   endforeach()
 
   set(LLVM_RUNTIME_SANITIZERS "Address" CACHE STRING "")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r337877 - [CMake] Link static libunwind and libc++abi into libc++ in Fuchsia toolchain

2018-07-24 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Tue Jul 24 18:44:22 2018
New Revision: 337877

URL: http://llvm.org/viewvc/llvm-project?rev=337877=rev
Log:
[CMake] Link static libunwind and libc++abi into libc++ in Fuchsia toolchain

When building libc++ for Fuchsia, we want to distribute shared libc++,
libc++abi and libunwind as separate libraries, but for static versions
we would like to link all of them into libc++ so -lc++ flag has the same
effect whether shared or static library is being used.

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

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

Modified: cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/caches/Fuchsia-stage2.cmake?rev=337877=337876=337877=diff
==
--- cfe/trunk/cmake/caches/Fuchsia-stage2.cmake (original)
+++ cfe/trunk/cmake/caches/Fuchsia-stage2.cmake Tue Jul 24 18:44:22 2018
@@ -100,9 +100,15 @@ if(FUCHSIA_SDK)
 set(RUNTIMES_${target}-fuchsia_CMAKE_SYSROOT ${FUCHSIA_${target}_SYSROOT} 
CACHE PATH "")
 set(RUNTIMES_${target}-fuchsia_LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
 set(RUNTIMES_${target}-fuchsia_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia_LIBUNWIND_INSTALL_STATIC_LIBRARY OFF CACHE 
BOOL "")
 set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
 set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL 
"")
+set(RUNTIMES_${target}-fuchsia_LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE 
BOOL "")
+set(RUNTIMES_${target}-fuchsia_LIBCXXABI_INSTALL_STATIC_LIBRARY OFF CACHE 
BOOL "")
+
set(RUNTIMES_${target}-fuchsia_LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY
 OFF CACHE BOOL "")
 set(RUNTIMES_${target}-fuchsia_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia_LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE 
BOOL "")
+
set(RUNTIMES_${target}-fuchsia_LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY OFF 
CACHE BOOL "")
   endforeach()
 
   set(LLVM_RUNTIME_SANITIZERS "Address" CACHE STRING "")


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


[PATCH] D49628: [CMake] Link static libunwind and libc++abi into libc++ in Fuchsia toolchain

2018-07-24 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 157182.

Repository:
  rC Clang

https://reviews.llvm.org/D49628

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -100,9 +100,15 @@
 set(RUNTIMES_${target}-fuchsia_CMAKE_SYSROOT ${FUCHSIA_${target}_SYSROOT} 
CACHE PATH "")
 set(RUNTIMES_${target}-fuchsia_LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
 set(RUNTIMES_${target}-fuchsia_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia_LIBUNWIND_INSTALL_STATIC_LIBRARY OFF CACHE 
BOOL "")
 set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
 set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL 
"")
+set(RUNTIMES_${target}-fuchsia_LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE 
BOOL "")
+set(RUNTIMES_${target}-fuchsia_LIBCXXABI_INSTALL_STATIC_LIBRARY OFF CACHE 
BOOL "")
+
set(RUNTIMES_${target}-fuchsia_LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY
 OFF CACHE BOOL "")
 set(RUNTIMES_${target}-fuchsia_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia_LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE 
BOOL "")
+
set(RUNTIMES_${target}-fuchsia_LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY OFF 
CACHE BOOL "")
   endforeach()
 
   set(LLVM_RUNTIME_SANITIZERS "Address" CACHE STRING "")


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -100,9 +100,15 @@
 set(RUNTIMES_${target}-fuchsia_CMAKE_SYSROOT ${FUCHSIA_${target}_SYSROOT} CACHE PATH "")
 set(RUNTIMES_${target}-fuchsia_LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
 set(RUNTIMES_${target}-fuchsia_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia_LIBUNWIND_INSTALL_STATIC_LIBRARY OFF CACHE BOOL "")
 set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
 set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia_LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia_LIBCXXABI_INSTALL_STATIC_LIBRARY OFF CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia_LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY OFF CACHE BOOL "")
 set(RUNTIMES_${target}-fuchsia_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia_LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
+set(RUNTIMES_${target}-fuchsia_LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY OFF CACHE BOOL "")
   endforeach()
 
   set(LLVM_RUNTIME_SANITIZERS "Address" CACHE STRING "")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49528: [analyzer] Syntactic matcher for leaks associated with run loop and autoreleasepool

2018-07-24 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC337876: [analyzer] Syntactic matcher for leaks associated 
with run loop and… (authored by george.karpenkov, committed by ).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D49528?vs=157180=157181#toc

Repository:
  rC Clang

https://reviews.llvm.org/D49528

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp
  test/Analysis/Checkers/RunLoopAutoreleaseLeakChecker.m
  test/Analysis/Inputs/system-header-simulator-for-objc-dealloc.h

Index: include/clang/StaticAnalyzer/Checkers/Checkers.td
===
--- include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -568,6 +568,10 @@
 
 let ParentPackage = Cocoa in {
 
+def RunLoopAutoreleaseLeakChecker : Checker<"RunLoopAutoreleaseLeak">,
+  HelpText<"Check for leaked memory in autorelease pools that will never be drained">,
+  DescFile<"RunLoopAutoreleaseLeakChecker.cpp">;
+
 def ObjCAtSyncChecker : Checker<"AtSync">,
   HelpText<"Check for nil pointers used as mutexes for @synchronized">,
   DescFile<"ObjCAtSyncChecker.cpp">;
Index: test/Analysis/Checkers/RunLoopAutoreleaseLeakChecker.m
===
--- test/Analysis/Checkers/RunLoopAutoreleaseLeakChecker.m
+++ test/Analysis/Checkers/RunLoopAutoreleaseLeakChecker.m
@@ -0,0 +1,104 @@
+// UNSUPPORTED: system-windows
+// RUN: %clang_analyze_cc1 -fobjc-arc -analyzer-checker=core,osx.cocoa.RunLoopAutoreleaseLeak %s -triple x86_64-darwin -verify
+// RUN: %clang_analyze_cc1 -DEXTRA=1 -DAP1=1 -fobjc-arc -analyzer-checker=core,osx.cocoa.RunLoopAutoreleaseLeak %s -triple x86_64-darwin -verify
+// RUN: %clang_analyze_cc1 -DEXTRA=1 -DAP2=1 -fobjc-arc -analyzer-checker=core,osx.cocoa.RunLoopAutoreleaseLeak %s -triple x86_64-darwin -verify
+// RUN: %clang_analyze_cc1 -DEXTRA=1 -DAP3=1 -fobjc-arc -analyzer-checker=core,osx.cocoa.RunLoopAutoreleaseLeak %s -triple x86_64-darwin -verify
+// RUN: %clang_analyze_cc1 -DEXTRA=1 -DAP4=1 -fobjc-arc -analyzer-checker=core,osx.cocoa.RunLoopAutoreleaseLeak %s -triple x86_64-darwin -verify
+
+#include "../Inputs/system-header-simulator-for-objc-dealloc.h"
+
+#ifndef EXTRA
+
+void just_runloop() { // No warning: no statements in between
+  @autoreleasepool {
+[[NSRunLoop mainRunLoop] run]; // no-warning
+  }
+}
+
+void just_xpcmain() { // No warning: no statements in between
+  @autoreleasepool {
+xpc_main(); // no-warning
+  }
+}
+
+void runloop_init_before() { // Warning: object created before the loop.
+  @autoreleasepool {
+NSObject *object = [[NSObject alloc] init]; // expected-warning{{Temporary objects allocated in the autorelease pool followed by the launch of main run loop may never get released; consider moving them to a separate autorelease pool}}
+(void) object;
+[[NSRunLoop mainRunLoop] run]; 
+  }
+}
+
+void xpcmain_init_before() { // Warning: object created before the loop.
+  @autoreleasepool {
+NSObject *object = [[NSObject alloc] init]; // expected-warning{{Temporary objects allocated in the autorelease pool followed by the launch of xpc_main may never get released; consider moving them to a separate autorelease pool}}
+(void) object;
+xpc_main(); 
+  }
+}
+
+void runloop_init_before_two_objects() { // Warning: object created before the loop.
+  @autoreleasepool {
+NSObject *object = [[NSObject alloc] init]; // expected-warning{{Temporary objects allocated in the autorelease pool followed by the launch of main run loop may never get released; consider moving them to a separate autorelease pool}}
+NSObject *object2 = [[NSObject alloc] init]; // no-warning, warning on the first one is enough.
+(void) object;
+(void) object2;
+[[NSRunLoop mainRunLoop] run]; 
+  }
+}
+
+void runloop_no_autoreleasepool() {
+  NSObject *object = [[NSObject alloc] init]; // no-warning
+  (void)object;
+  [[NSRunLoop mainRunLoop] run];
+}
+
+void runloop_init_after() { // No warning: objects created after the loop
+  @autoreleasepool {
+[[NSRunLoop mainRunLoop] run]; 
+NSObject *object = [[NSObject alloc] init]; // no-warning
+(void) object;
+  }
+}
+
+#endif
+
+#ifdef AP1
+int main() {
+NSObject *object = [[NSObject alloc] init]; // expected-warning{{Temporary objects allocated in the autorelease pool of last resort followed by the launch of main run loop may never get released; consider moving them to a separate autorelease pool}}
+(void) object;
+[[NSRunLoop mainRunLoop] run]; 
+return 0;
+}
+#endif
+
+#ifdef AP2
+// expected-no-diagnostics
+int main() {
+  NSObject *object = [[NSObject alloc] init]; // no-warning
+  (void) object;
+  @autoreleasepool {
+[[NSRunLoop mainRunLoop] run]; 
+  }
+  return 0;

r337876 - [analyzer] Syntactic matcher for leaks associated with run loop and autoreleasepool

2018-07-24 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Tue Jul 24 18:27:15 2018
New Revision: 337876

URL: http://llvm.org/viewvc/llvm-project?rev=337876=rev
Log:
[analyzer] Syntactic matcher for leaks associated with run loop and 
autoreleasepool

A checker for detecting leaks resulting from allocating temporary
autoreleasing objects before starting the main run loop.

Checks for two antipatterns:

1. ObjCMessageExpr followed by [[NARunLoop mainRunLoop] run] in the same
autorelease pool.

2. ObjCMessageExpr followed by [[NARunLoop mainRunLoop] run] in no
autorelease pool.

Happens-before relationship is modeled purely syntactically.

rdar://39299145

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

Added:
cfe/trunk/lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp
cfe/trunk/test/Analysis/Checkers/
cfe/trunk/test/Analysis/Checkers/RunLoopAutoreleaseLeakChecker.m
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
cfe/trunk/test/Analysis/Inputs/system-header-simulator-for-objc-dealloc.h

Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td?rev=337876=337875=337876=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Tue Jul 24 
18:27:15 2018
@@ -568,6 +568,10 @@ def ObjCPropertyChecker : Checker<"ObjCP
 
 let ParentPackage = Cocoa in {
 
+def RunLoopAutoreleaseLeakChecker : Checker<"RunLoopAutoreleaseLeak">,
+  HelpText<"Check for leaked memory in autorelease pools that will never be 
drained">,
+  DescFile<"RunLoopAutoreleaseLeakChecker.cpp">;
+
 def ObjCAtSyncChecker : Checker<"AtSync">,
   HelpText<"Check for nil pointers used as mutexes for @synchronized">,
   DescFile<"ObjCAtSyncChecker.cpp">;

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt?rev=337876=337875=337876=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt Tue Jul 24 18:27:15 
2018
@@ -79,6 +79,7 @@ add_clang_library(clangStaticAnalyzerChe
   RetainCountChecker.cpp
   ReturnPointerRangeChecker.cpp
   ReturnUndefChecker.cpp
+  RunLoopAutoreleaseLeakChecker.cpp
   SimpleStreamChecker.cpp
   StackAddrEscapeChecker.cpp
   StdLibraryFunctionsChecker.cpp

Added: cfe/trunk/lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp?rev=337876=auto
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp 
(added)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp Tue 
Jul 24 18:27:15 2018
@@ -0,0 +1,217 @@
+//=- RunLoopAutoreleaseLeakChecker.cpp --*- C++ -*-==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//
+//===--===//
+//
+// A checker for detecting leaks resulting from allocating temporary
+// autoreleased objects before starting the main run loop.
+//
+// Checks for two antipatterns:
+// 1. ObjCMessageExpr followed by [[NSRunLoop mainRunLoop] run] in the same
+// autorelease pool.
+// 2. ObjCMessageExpr followed by [[NSRunLoop mainRunLoop] run] in no
+// autorelease pool.
+//
+// Any temporary objects autoreleased in code called in those expressions
+// will not be deallocated until the program exits, and are effectively leaks.
+//
+//===--===//
+//
+
+#include "ClangSACheckers.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclObjC.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
+
+using namespace clang;
+using namespace ento;
+using namespace ast_matchers;
+
+namespace {
+
+const char * RunLoopBind = "NSRunLoopM";
+const char * RunLoopRunBind = "RunLoopRunM";
+const char * OtherMsgBind = "OtherMessageSentM";
+const char * AutoreleasePoolBind = 

[PATCH] D49518: [VFS] Emit an error when a file isn't located in any directory.

2018-07-24 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

In https://reviews.llvm.org/D49518#1168038, @bruno wrote:

> Hi Volodymyr, thanks for improving this.
>
> > Need to double check what tests we have when using relative path names at 
> > the root level.
>
> Another interesting place to look at is 
> `unittests/Basic/VirtualFileSystemTest.cpp`


Thanks for the pointer. Probably I'll move the added test there as it doesn't 
need full file system interaction and doesn't need to execute entire clang_cc1.

>> I'd like to make the behavior consistent because a file name is a specific 
>> case of relative paths. So far there are no assertions and no errors but 
>> file lookup doesn't seem to be working.
> 
> Makes sense. My general impression is that relative paths don't make sense 
> here either, but you can address that in a follow up patch (giving time for 
> any potential counterexample on this).

Based on the code, relative paths won't work for file lookup. That is so 
because in `RedirectingFileSystem::lookupPath` we convert paths to absolute

  if (std::error_code EC = makeAbsolute(Path))
return EC;
  // ...
  sys::path::const_iterator Start = sys::path::begin(Path);
  sys::path::const_iterator End = sys::path::end(Path);

and textually compare them with VFS entry name 
.

Having an error for relative paths makes the change cleaner, so I'll include it 
in this patch.


https://reviews.llvm.org/D49518



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


[PATCH] D49771: CodeGen: use non-zero memset when possible for automatic variables

2018-07-24 Thread Justin Bogner via Phabricator via cfe-commits
bogner accepted this revision.
bogner added a comment.
This revision is now accepted and ready to land.

Seems straightforward and correct to me.




Comment at: lib/CodeGen/CGDecl.cpp:956-957
+class BytePattern {
+  uint8_t Val;
+  enum class ValueType { Specific, Any, None } Type;
+  BytePattern(ValueType Type) : Type(Type) {}

Probably makes sense to swap the order of these or give the enum class a 
smaller underlying type than int.



Comment at: lib/CodeGen/CGDecl.cpp:996-998
+if (!Value.isSplat(8))
+  return BytePattern::None();
+return BytePattern(Value.getLoBits(8).getLimitedValue());

Very much a nitpick, but this would be slightly easier to follow written in the 
order without a negation.


Repository:
  rC Clang

https://reviews.llvm.org/D49771



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


[PATCH] D49526: Updated llvm-proto-fuzzer to execute the compiled code

2018-07-24 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added inline comments.



Comment at: clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:190
+  builder.setMCJITMemoryManager(
+  std::unique_ptr(RTDyldMM));
+  builder.setOptLevel(OLvl);

emmettneyman wrote:
> morehouse wrote:
> > These 3 lines can be combined to `builder.setMCJITMemoryManager(new 
> > SectionMemoryManager())`
> I use RTDyldMM on line 208. Should I just keep these lines as they are?
Ah, missed that.  In that case, you can probably simplify this line to
`builder.setMCJITMemoryManager(RTDyldMM)`.


Repository:
  rC Clang

https://reviews.llvm.org/D49526



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


[PATCH] D49771: CodeGen: use non-zero memset when possible for automatic variables

2018-07-24 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: test/CodeGen/init.c:202
+  union U { char c; int i; };
+  struct S { union U u; int i; };
+  struct S arr[5] = { { {0xF0}, 0xF0F0F0F0 }, { {0xF0}, 0xF0F0F0F0 }, { 
{0xF0}, 0xF0F0F0F0 }, { {0xF0}, 0xF0F0F0F0 }, { {0xF0}, 0xF0F0F0F0 }, };

Drive-by suggestion: If you make this `struct S { union U u; short s; };` then 
you'll also be testing the case of "padding between struct fields", which is 
otherwise untested here.


Repository:
  rC Clang

https://reviews.llvm.org/D49771



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


[PATCH] D49526: Updated llvm-proto-fuzzer to execute the compiled code

2018-07-24 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman added inline comments.



Comment at: clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:190
+  builder.setMCJITMemoryManager(
+  std::unique_ptr(RTDyldMM));
+  builder.setOptLevel(OLvl);

morehouse wrote:
> These 3 lines can be combined to `builder.setMCJITMemoryManager(new 
> SectionMemoryManager())`
I use RTDyldMM on line 208. Should I just keep these lines as they are?


Repository:
  rC Clang

https://reviews.llvm.org/D49526



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


[PATCH] D49771: CodeGen: use non-zero memset when possible for automatic variables

2018-07-24 Thread JF Bastien via Phabricator via cfe-commits
jfb created this revision.
jfb added a reviewer: dexonsmith.
Herald added a subscriber: cfe-commits.

Right now automatic variables are either initialized with bzero followed by a 
few stores, or memcpy'd from a synthesized global. We end up encountering a 
fair amount of code where memcpy of non-zero byte patterns would be better than 
memcpy from a global because it touches less memory and generates a smaller 
binary. The optimizer could reason about this, but it's not really worth it 
when clang already knows.

This code could definitely be more clever but I'm not sure it's worth it. In 
particular we could track a histogram of bytes seen and figure out (as we do 
with bzero) if a memset could be followed by a handful of stores. Similarly, we 
could tune the heuristics for GlobalSize, but using the same as for bzero seems 
conservatively OK for now.

rdar://problem/42563091


Repository:
  rC Clang

https://reviews.llvm.org/D49771

Files:
  lib/CodeGen/CGDecl.cpp
  test/CodeGen/init.c

Index: test/CodeGen/init.c
===
--- test/CodeGen/init.c
+++ test/CodeGen/init.c
@@ -140,6 +140,72 @@
   // CHECK: call void @bar
 }
 
+void nonzeroMemseti8() {
+  char arr[33] = { 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, };
+  // CHECK-LABEL: @nonzeroMemseti8(
+  // CHECK-NOT: store
+  // CHECK-NOT: memcpy
+  // CHECK: call void @llvm.memset.p0i8.i32(i8* {{.*}}, i8 42, i32 33, i1 false)
+}
+
+void nonzeroMemseti16() {
+  unsigned short arr[17] = { 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, };
+  // CHECK-LABEL: @nonzeroMemseti16(
+  // CHECK-NOT: store
+  // CHECK-NOT: memcpy
+  // CHECK: call void @llvm.memset.p0i8.i32(i8* {{.*}}, i8 66, i32 34, i1 false)
+}
+
+void nonzeroMemseti32() {
+  unsigned arr[9] = { 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, };
+  // CHECK-LABEL: @nonzeroMemseti32(
+  // CHECK-NOT: store
+  // CHECK-NOT: memcpy
+  // CHECK: call void @llvm.memset.p0i8.i32(i8* {{.*}}, i8 -16, i32 36, i1 false)
+}
+
+void nonzeroMemseti64() {
+  unsigned long long arr[7] = { 0x, 0x, 0x, 0x, 0x,  0x,  0x,  };
+  // CHECK-LABEL: @nonzeroMemseti64(
+  // CHECK-NOT: store
+  // CHECK-NOT: memcpy
+  // CHECK: call void @llvm.memset.p0i8.i32(i8* {{.*}}, i8 -86, i32 56, i1 false)
+}
+
+void nonzeroMemsetf32() {
+  float arr[9] = { 0x1.cacacap+75, 0x1.cacacap+75, 0x1.cacacap+75, 0x1.cacacap+75, 0x1.cacacap+75, 0x1.cacacap+75, 0x1.cacacap+75, 0x1.cacacap+75, 0x1.cacacap+75, };
+  // CHECK-LABEL: @nonzeroMemsetf32(
+  // CHECK-NOT: store
+  // CHECK-NOT: memcpy
+  // CHECK: call void @llvm.memset.p0i8.i32(i8* {{.*}}, i8 101, i32 36, i1 false)
+}
+
+void nonzeroMemsetf64() {
+  double arr[7] = { 0x1.4p+69, 0x1.4p+69, 0x1.4p+69, 0x1.4p+69, 0x1.4p+69, 0x1.4p+69, 0x1.4p+69, };
+  // CHECK-LABEL: @nonzeroMemsetf64(
+  // CHECK-NOT: store
+  // CHECK-NOT: memcpy
+  // CHECK: call void @llvm.memset.p0i8.i32(i8* {{.*}}, i8 68, i32 56, i1 false)
+}
+
+void nonzeroPaddedUnionMemset() {
+  union U { char c; int i; };
+  union U arr[9] = { 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, };
+  // CHECK-LABEL: @nonzeroPaddedUnionMemset(
+  // CHECK-NOT: store
+  // CHECK-NOT: memcpy
+  // CHECK: call void @llvm.memset.p0i8.i32(i8* {{.*}}, i8 -16, i32 36, i1 false)
+}
+
+void nonzeroNestedMemset() {
+  union U { char c; int i; };
+  struct S { union U u; int i; };
+  struct S arr[5] = { { {0xF0}, 0xF0F0F0F0 }, { {0xF0}, 0xF0F0F0F0 }, { {0xF0}, 0xF0F0F0F0 }, { {0xF0}, 0xF0F0F0F0 }, { {0xF0}, 0xF0F0F0F0 }, };
+  // CHECK-LABEL: @nonzeroNestedMemset(
+  // CHECK-NOT: store
+  // CHECK-NOT: memcpy
+  // CHECK: call void @llvm.memset.p0i8.i32(i8* {{.*}}, i8 -16, i32 40, i1 false)
+}
 
 // PR9257
 struct test11S {
Index: lib/CodeGen/CGDecl.cpp
===
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -948,6 +948,113 @@
  canEmitInitWithFewStoresAfterBZero(Init, StoreBudget);
 }
 
+/// A byte pattern.
+///
+/// Can be "any" pattern if the value was padding or known to be undef.
+/// Can be "none" pattern if a sequence doesn't exist.
+class BytePattern {
+  uint8_t Val;
+  enum class ValueType { Specific, Any, None } Type;
+  BytePattern(ValueType Type) : Type(Type) {}
+
+public:
+  BytePattern(uint8_t Value) : Val(Value), Type(ValueType::Specific) {}
+  static BytePattern Any() { return BytePattern(ValueType::Any); }
+  static BytePattern None() { return BytePattern(ValueType::None); }
+  bool isAny() const { return Type == ValueType::Any; }
+  bool isNone() const { 

[PATCH] D49763: [CUDA] Call atexit() for CUDA destructor early on.

2018-07-24 Thread Artem Belevich via Phabricator via cfe-commits
tra planned changes to this revision.
tra added a comment.

Ugh. Apparently moving this code up just disabled module destructor. :-( That 
explains why we no longer crash.


https://reviews.llvm.org/D49763



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


[PATCH] D49736: [Basic] Emit warning flag suggestion only in case there's existing flag *similar* to the unknown one

2018-07-24 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Thanks for working on this!
It looks like we only have one client of `getNearestOption`. Wouldn't it make 
sense to fold the check into the function itself?


Repository:
  rC Clang

https://reviews.llvm.org/D49736



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


[libunwind] r337868 - [CMake] Include CMakeDependentOption in libunwind

2018-07-24 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Tue Jul 24 16:42:51 2018
New Revision: 337868

URL: http://llvm.org/viewvc/llvm-project?rev=337868=rev
Log:
[CMake] Include CMakeDependentOption in libunwind

This should resolve the breakage introduced in r337867 which introduced
the use of cmake_dependent_option without include the necessary file.

Modified:
libunwind/trunk/CMakeLists.txt

Modified: libunwind/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/CMakeLists.txt?rev=337868=337867=337868=diff
==
--- libunwind/trunk/CMakeLists.txt (original)
+++ libunwind/trunk/CMakeLists.txt Tue Jul 24 16:42:51 2018
@@ -119,6 +119,7 @@ endif()
 
#===
 # Setup CMake Options
 
#===
+include(CMakeDependentOption)
 include(HandleCompilerRT)
 
 # Define options.


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


[PATCH] D49770: [ARM64] [Windows] Follow MS X86_64 C++ ABI when passing structs

2018-07-24 Thread Sanjin Sijaric via Phabricator via cfe-commits
ssijaric created this revision.
ssijaric added reviewers: rnk, mstorsjo, TomTan, haripul.
Herald added a reviewer: javed.absar.
Herald added subscribers: cfe-commits, chrib, kristof.beyls.

Microsoft's C++ object model for ARM64 is the same as that for X86_64.  For 
example, small structs with non-trivial copy constructors or virtual function 
tables are passed indirectly.  Currently, they are passed in registers when 
compiled with clang.


Repository:
  rC Clang

https://reviews.llvm.org/D49770

Files:
  lib/CodeGen/MicrosoftCXXABI.cpp
  test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp


Index: test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
===
--- test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
+++ test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=i386-pc-win32 
-mconstructor-aliases -fno-rtti | FileCheck -check-prefix WIN32 %s
 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=thumb-pc-win32 
-mconstructor-aliases -fno-rtti | FileCheck -check-prefix WOA %s
 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=x86_64-pc-win32 
-mconstructor-aliases -fno-rtti | FileCheck -check-prefix WIN64 %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=aarch64-windows-msvc 
-mconstructor-aliases -fno-rtti | FileCheck -check-prefix WOA64 %s
 
 struct Empty {};
 
@@ -227,12 +228,14 @@
 // LINUX-LABEL: define void 
@_Z22small_arg_with_vftable16SmallWithVftable(%struct.SmallWithVftable* %s)
 // WIN32: define dso_local void 
@"?small_arg_with_vftable@@YAXUSmallWithVftable@@@Z"(<{ 
%struct.SmallWithVftable }>* inalloca)
 // WIN64: define dso_local void 
@"?small_arg_with_vftable@@YAXUSmallWithVftable@@@Z"(%struct.SmallWithVftable* 
%s)
+// WOA64: define dso_local void 
@"?small_arg_with_vftable@@YAXUSmallWithVftable@@@Z"(%struct.SmallWithVftable* 
%s)
 
 void medium_arg_with_copy_ctor(MediumWithCopyCtor s) {}
 // LINUX-LABEL: define void 
@_Z25medium_arg_with_copy_ctor18MediumWithCopyCtor(%struct.MediumWithCopyCtor* 
%s)
 // WIN32: define dso_local void 
@"?medium_arg_with_copy_ctor@@YAXUMediumWithCopyCtor@@@Z"(<{ 
%struct.MediumWithCopyCtor }>* inalloca)
 // WIN64: define dso_local void 
@"?medium_arg_with_copy_ctor@@YAXUMediumWithCopyCtor@@@Z"(%struct.MediumWithCopyCtor*
 %s)
 // WOA: define dso_local arm_aapcs_vfpcc void 
@"?medium_arg_with_copy_ctor@@YAXUMediumWithCopyCtor@@@Z"(%struct.MediumWithCopyCtor*
 %s)
+// WOA64: define dso_local void 
@"?medium_arg_with_copy_ctor@@YAXUMediumWithCopyCtor@@@Z"(%struct.MediumWithCopyCtor*
 %s)
 
 void big_arg(Big s) {}
 // LINUX-LABEL: define void @_Z7big_arg3Big(%struct.Big* byval align 4 %s)
Index: lib/CodeGen/MicrosoftCXXABI.cpp
===
--- lib/CodeGen/MicrosoftCXXABI.cpp
+++ lib/CodeGen/MicrosoftCXXABI.cpp
@@ -827,6 +827,7 @@
 return RAA_Default;
 
   case llvm::Triple::x86_64:
+  case llvm::Triple::aarch64:
 return !canCopyArgument(RD) ? RAA_Indirect : RAA_Default;
   }
 


Index: test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
===
--- test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
+++ test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=i386-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WIN32 %s
 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=thumb-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WOA %s
 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=x86_64-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WIN64 %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=aarch64-windows-msvc -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WOA64 %s
 
 struct Empty {};
 
@@ -227,12 +228,14 @@
 // LINUX-LABEL: define void @_Z22small_arg_with_vftable16SmallWithVftable(%struct.SmallWithVftable* %s)
 // WIN32: define dso_local void @"?small_arg_with_vftable@@YAXUSmallWithVftable@@@Z"(<{ %struct.SmallWithVftable }>* inalloca)
 // WIN64: define dso_local void @"?small_arg_with_vftable@@YAXUSmallWithVftable@@@Z"(%struct.SmallWithVftable* %s)
+// WOA64: define dso_local void @"?small_arg_with_vftable@@YAXUSmallWithVftable@@@Z"(%struct.SmallWithVftable* %s)
 
 void medium_arg_with_copy_ctor(MediumWithCopyCtor s) {}
 // LINUX-LABEL: define void @_Z25medium_arg_with_copy_ctor18MediumWithCopyCtor(%struct.MediumWithCopyCtor* %s)
 // WIN32: define dso_local void @"?medium_arg_with_copy_ctor@@YAXUMediumWithCopyCtor@@@Z"(<{ %struct.MediumWithCopyCtor }>* inalloca)
 // WIN64: define dso_local void @"?medium_arg_with_copy_ctor@@YAXUMediumWithCopyCtor@@@Z"(%struct.MediumWithCopyCtor* %s)
 // WOA: define dso_local arm_aapcs_vfpcc void @"?medium_arg_with_copy_ctor@@YAXUMediumWithCopyCtor@@@Z"(%struct.MediumWithCopyCtor* %s)
+// WOA64: define 

[PATCH] D49573: [CMake] Option to control whether shared/static library is installed

2018-07-24 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCXX337867: [CMake] Option to control whether shared/static 
library is installed (authored by phosek, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D49573?vs=156382=157170#toc

Repository:
  rCXX libc++

https://reviews.llvm.org/D49573

Files:
  CMakeLists.txt
  lib/CMakeLists.txt


Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -93,6 +93,12 @@
 "Define suffix of library directory name (32/64)")
 option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON)
 option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON)
+cmake_dependent_option(LIBCXX_INSTALL_STATIC_LIBRARY
+  "Install the static libc++ library." ON
+  "LIBCXX_ENABLE_STATIC;LIBCXX_INSTALL_LIBRARY" OFF)
+cmake_dependent_option(LIBCXX_INSTALL_SHARED_LIBRARY
+  "Install the shared libc++ library." ON
+  "LIBCXX_ENABLE_SHARED;LIBCXX_INSTALL_LIBRARY" OFF)
 option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON)
 cmake_dependent_option(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY
 "Install libc++experimental.a" ON
Index: lib/CMakeLists.txt
===
--- lib/CMakeLists.txt
+++ lib/CMakeLists.txt
@@ -220,8 +220,6 @@
 COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
 )
 
-set(LIBCXX_TARGETS)
-
 # Build the shared library.
 if (LIBCXX_ENABLE_SHARED)
   add_library(cxx_shared SHARED $)
@@ -236,7 +234,10 @@
   VERSION   "${LIBCXX_ABI_VERSION}.0"
   SOVERSION "${LIBCXX_ABI_VERSION}"
   )
-  list(APPEND LIBCXX_TARGETS "cxx_shared")
+  list(APPEND LIBCXX_BUILD_TARGETS "cxx_shared")
+  if (LIBCXX_INSTALL_SHARED_LIBRARY)
+list(APPEND LIBCXX_INSTALL_TARGETS "cxx_shared")
+  endif()
   if(WIN32 AND NOT MINGW AND NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL 
"Windows")
 # Since we most likely do not have a mt.exe replacement, disable the
 # manifest bundling.  This allows a normal cmake invocation to pass which
@@ -256,8 +257,10 @@
   LINK_FLAGS"${LIBCXX_LINK_FLAGS}"
   OUTPUT_NAME   "c++"
   )
-
-  list(APPEND LIBCXX_TARGETS "cxx_static")
+  list(APPEND LIBCXX_BUILD_TARGETS "cxx_static")
+  if (LIBCXX_INSTALL_STATIC_LIBRARY)
+list(APPEND LIBCXX_INSTALL_TARGETS "cxx_static")
+  endif()
   # Attempt to merge the libc++.a archive and the ABI library archive into one.
   if (LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY)
 set(MERGE_ARCHIVES_SEARCH_PATHS "")
@@ -286,7 +289,7 @@
 endif()
 
 # Add a meta-target for both libraries.
-add_custom_target(cxx DEPENDS cxx-headers ${LIBCXX_TARGETS})
+add_custom_target(cxx DEPENDS cxx-headers ${LIBCXX_BUILD_TARGETS})
 
 if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY)
   file(GLOB LIBCXX_EXPERIMENTAL_SOURCES ../src/experimental/*.cpp)
@@ -362,7 +365,7 @@
   if (LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY)
 set(experimental_lib cxx_experimental)
   endif()
-  install(TARGETS ${LIBCXX_TARGETS} ${experimental_lib}
+  install(TARGETS ${LIBCXX_INSTALL_TARGETS} ${experimental_lib}
 LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} 
COMPONENT cxx
 ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} 
COMPONENT cxx
 )


Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -93,6 +93,12 @@
 "Define suffix of library directory name (32/64)")
 option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON)
 option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON)
+cmake_dependent_option(LIBCXX_INSTALL_STATIC_LIBRARY
+  "Install the static libc++ library." ON
+  "LIBCXX_ENABLE_STATIC;LIBCXX_INSTALL_LIBRARY" OFF)
+cmake_dependent_option(LIBCXX_INSTALL_SHARED_LIBRARY
+  "Install the shared libc++ library." ON
+  "LIBCXX_ENABLE_SHARED;LIBCXX_INSTALL_LIBRARY" OFF)
 option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON)
 cmake_dependent_option(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY
 "Install libc++experimental.a" ON
Index: lib/CMakeLists.txt
===
--- lib/CMakeLists.txt
+++ lib/CMakeLists.txt
@@ -220,8 +220,6 @@
 COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
 )
 
-set(LIBCXX_TARGETS)
-
 # Build the shared library.
 if (LIBCXX_ENABLE_SHARED)
   add_library(cxx_shared SHARED $)
@@ -236,7 +234,10 @@
   VERSION   "${LIBCXX_ABI_VERSION}.0"
   SOVERSION "${LIBCXX_ABI_VERSION}"
   )
-  list(APPEND LIBCXX_TARGETS "cxx_shared")
+  list(APPEND LIBCXX_BUILD_TARGETS "cxx_shared")
+  if (LIBCXX_INSTALL_SHARED_LIBRARY)
+list(APPEND LIBCXX_INSTALL_TARGETS "cxx_shared")
+  endif()
   if(WIN32 AND NOT MINGW AND NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
 # Since we most likely do not have a mt.exe replacement, disable the
 # manifest bundling.  This allows a normal cmake invocation to pass which
@@ 

[libcxx] r337867 - [CMake] Option to control whether shared/static library is installed

2018-07-24 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Tue Jul 24 16:27:51 2018
New Revision: 337867

URL: http://llvm.org/viewvc/llvm-project?rev=337867=rev
Log:
[CMake] Option to control whether shared/static library is installed

Currently it's only possible to control whether shared or static library
build of libc++, libc++abi and libunwind is enabled or disabled and
whether to install everything we've built or not. However, it'd be
useful to have more fine grained control, e.g. when static libraries are
merged together into libc++.a we don't need to install libc++abi.a and
libunwind.a. This change adds this option.

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

Modified:
libcxx/trunk/CMakeLists.txt
libcxx/trunk/lib/CMakeLists.txt

Modified: libcxx/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/CMakeLists.txt?rev=337867=337866=337867=diff
==
--- libcxx/trunk/CMakeLists.txt (original)
+++ libcxx/trunk/CMakeLists.txt Tue Jul 24 16:27:51 2018
@@ -93,6 +93,12 @@ set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_
 "Define suffix of library directory name (32/64)")
 option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON)
 option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON)
+cmake_dependent_option(LIBCXX_INSTALL_STATIC_LIBRARY
+  "Install the static libc++ library." ON
+  "LIBCXX_ENABLE_STATIC;LIBCXX_INSTALL_LIBRARY" OFF)
+cmake_dependent_option(LIBCXX_INSTALL_SHARED_LIBRARY
+  "Install the shared libc++ library." ON
+  "LIBCXX_ENABLE_SHARED;LIBCXX_INSTALL_LIBRARY" OFF)
 option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON)
 cmake_dependent_option(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY
 "Install libc++experimental.a" ON

Modified: libcxx/trunk/lib/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/lib/CMakeLists.txt?rev=337867=337866=337867=diff
==
--- libcxx/trunk/lib/CMakeLists.txt (original)
+++ libcxx/trunk/lib/CMakeLists.txt Tue Jul 24 16:27:51 2018
@@ -220,8 +220,6 @@ set_target_properties(cxx_objects
 COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
 )
 
-set(LIBCXX_TARGETS)
-
 # Build the shared library.
 if (LIBCXX_ENABLE_SHARED)
   add_library(cxx_shared SHARED $)
@@ -236,7 +234,10 @@ if (LIBCXX_ENABLE_SHARED)
   VERSION   "${LIBCXX_ABI_VERSION}.0"
   SOVERSION "${LIBCXX_ABI_VERSION}"
   )
-  list(APPEND LIBCXX_TARGETS "cxx_shared")
+  list(APPEND LIBCXX_BUILD_TARGETS "cxx_shared")
+  if (LIBCXX_INSTALL_SHARED_LIBRARY)
+list(APPEND LIBCXX_INSTALL_TARGETS "cxx_shared")
+  endif()
   if(WIN32 AND NOT MINGW AND NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL 
"Windows")
 # Since we most likely do not have a mt.exe replacement, disable the
 # manifest bundling.  This allows a normal cmake invocation to pass which
@@ -256,8 +257,10 @@ if (LIBCXX_ENABLE_STATIC)
   LINK_FLAGS"${LIBCXX_LINK_FLAGS}"
   OUTPUT_NAME   "c++"
   )
-
-  list(APPEND LIBCXX_TARGETS "cxx_static")
+  list(APPEND LIBCXX_BUILD_TARGETS "cxx_static")
+  if (LIBCXX_INSTALL_STATIC_LIBRARY)
+list(APPEND LIBCXX_INSTALL_TARGETS "cxx_static")
+  endif()
   # Attempt to merge the libc++.a archive and the ABI library archive into one.
   if (LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY)
 set(MERGE_ARCHIVES_SEARCH_PATHS "")
@@ -286,7 +289,7 @@ if (LIBCXX_ENABLE_STATIC)
 endif()
 
 # Add a meta-target for both libraries.
-add_custom_target(cxx DEPENDS cxx-headers ${LIBCXX_TARGETS})
+add_custom_target(cxx DEPENDS cxx-headers ${LIBCXX_BUILD_TARGETS})
 
 if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY)
   file(GLOB LIBCXX_EXPERIMENTAL_SOURCES ../src/experimental/*.cpp)
@@ -362,7 +365,7 @@ if (LIBCXX_INSTALL_LIBRARY)
   if (LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY)
 set(experimental_lib cxx_experimental)
   endif()
-  install(TARGETS ${LIBCXX_TARGETS} ${experimental_lib}
+  install(TARGETS ${LIBCXX_INSTALL_TARGETS} ${experimental_lib}
 LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} 
COMPONENT cxx
 ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} 
COMPONENT cxx
 )


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


[libunwind] r337867 - [CMake] Option to control whether shared/static library is installed

2018-07-24 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Tue Jul 24 16:27:51 2018
New Revision: 337867

URL: http://llvm.org/viewvc/llvm-project?rev=337867=rev
Log:
[CMake] Option to control whether shared/static library is installed

Currently it's only possible to control whether shared or static library
build of libc++, libc++abi and libunwind is enabled or disabled and
whether to install everything we've built or not. However, it'd be
useful to have more fine grained control, e.g. when static libraries are
merged together into libc++.a we don't need to install libc++abi.a and
libunwind.a. This change adds this option.

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

Modified:
libunwind/trunk/CMakeLists.txt
libunwind/trunk/src/CMakeLists.txt

Modified: libunwind/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/CMakeLists.txt?rev=337867=337866=337867=diff
==
--- libunwind/trunk/CMakeLists.txt (original)
+++ libunwind/trunk/CMakeLists.txt Tue Jul 24 16:27:51 2018
@@ -137,6 +137,12 @@ option(LIBUNWIND_INCLUDE_DOCS "Build the
 set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
 "Define suffix of library directory name (32/64)")
 option(LIBUNWIND_INSTALL_LIBRARY "Install the libunwind library." ON)
+cmake_dependent_option(LIBUNWIND_INSTALL_STATIC_LIBRARY
+  "Install the static libunwind library." ON
+  "LIBUNWIND_ENABLE_STATIC;LIBUNWIND_INSTALL_LIBRARY" OFF)
+cmake_dependent_option(LIBUNWIND_INSTALL_SHARED_LIBRARY
+  "Install the shared libunwind library." ON
+  "LIBUNWIND_ENABLE_SHARED;LIBUNWIND_INSTALL_LIBRARY" OFF)
 set(LIBUNWIND_TARGET_TRIPLE "" CACHE STRING "Target triple for cross 
compiling.")
 set(LIBUNWIND_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
 set(LIBUNWIND_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")

Modified: libunwind/trunk/src/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/CMakeLists.txt?rev=337867=337866=337867=diff
==
--- libunwind/trunk/src/CMakeLists.txt (original)
+++ libunwind/trunk/src/CMakeLists.txt Tue Jul 24 16:27:51 2018
@@ -103,8 +103,6 @@ set_target_properties(unwind_objects
 COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
 POSITION_INDEPENDENT_CODE ON)
 
-set(LIBUNWIND_TARGETS)
-
 # Build the shared library.
 if (LIBUNWIND_ENABLE_SHARED)
   add_library(unwind_shared SHARED $)
@@ -118,7 +116,10 @@ if (LIBUNWIND_ENABLE_SHARED)
   OUTPUT_NAME   "unwind"
   VERSION   "1.0"
   SOVERSION "1")
-  list(APPEND LIBUNWIND_TARGETS "unwind_shared")
+  list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared")
+  if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
+list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
+  endif()
 endif()
 
 # Build the static library.
@@ -129,14 +130,17 @@ if (LIBUNWIND_ENABLE_STATIC)
 PROPERTIES
   LINK_FLAGS"${LIBUNWIND_LINK_FLAGS}"
   OUTPUT_NAME   "unwind")
-  list(APPEND LIBUNWIND_TARGETS "unwind_static")
+  list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static")
+  if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
+list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
+  endif()
 endif()
 
 # Add a meta-target for both libraries.
-add_custom_target(unwind DEPENDS ${LIBUNWIND_TARGETS})
+add_custom_target(unwind DEPENDS ${LIBUNWIND_BUILD_TARGETS})
 
 if (LIBUNWIND_INSTALL_LIBRARY)
-  install(TARGETS ${LIBUNWIND_TARGETS}
+  install(TARGETS ${LIBUNWIND_INSTALL_TARGETS}
 LIBRARY DESTINATION 
${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind
 ARCHIVE DESTINATION 
${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind)
 endif()


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


[libcxxabi] r337867 - [CMake] Option to control whether shared/static library is installed

2018-07-24 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Tue Jul 24 16:27:51 2018
New Revision: 337867

URL: http://llvm.org/viewvc/llvm-project?rev=337867=rev
Log:
[CMake] Option to control whether shared/static library is installed

Currently it's only possible to control whether shared or static library
build of libc++, libc++abi and libunwind is enabled or disabled and
whether to install everything we've built or not. However, it'd be
useful to have more fine grained control, e.g. when static libraries are
merged together into libc++.a we don't need to install libc++abi.a and
libunwind.a. This change adds this option.

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

Modified:
libcxxabi/trunk/CMakeLists.txt
libcxxabi/trunk/src/CMakeLists.txt

Modified: libcxxabi/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/CMakeLists.txt?rev=337867=337866=337867=diff
==
--- libcxxabi/trunk/CMakeLists.txt (original)
+++ libcxxabi/trunk/CMakeLists.txt Tue Jul 24 16:27:51 2018
@@ -75,6 +75,13 @@ set(LIBCXXABI_GCC_TOOLCHAIN "" CACHE PAT
 set(LIBCXXABI_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")
 set(LIBCXXABI_LIBCXX_LIBRARY_PATH "" CACHE PATH "The path to libc++ library.")
 
+cmake_dependent_option(LIBCXXABI_INSTALL_STATIC_LIBRARY
+  "Install the static libc++abi library." ON
+  "LIBCXXABI_ENABLE_STATIC;LIBCXXABI_INSTALL_LIBRARY" OFF)
+cmake_dependent_option(LIBCXXABI_INSTALL_SHARED_LIBRARY
+  "Install the shared libc++abi library." ON
+  "LIBCXXABI_ENABLE_SHARED;LIBCXXABI_INSTALL_LIBRARY" OFF)
+
 # Default to building a shared library so that the default options still test
 # the libc++abi that is being built. There are two problems with testing a
 # static libc++abi. In the case of a standalone build, the tests will link the

Modified: libcxxabi/trunk/src/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/CMakeLists.txt?rev=337867=337866=337867=diff
==
--- libcxxabi/trunk/src/CMakeLists.txt (original)
+++ libcxxabi/trunk/src/CMakeLists.txt Tue Jul 24 16:27:51 2018
@@ -129,8 +129,6 @@ set_target_properties(cxxabi_objects
 POSITION_INDEPENDENT_CODE
   ON)
 
-set(LIBCXXABI_TARGETS)
-
 # Build the shared library.
 if (LIBCXXABI_ENABLE_SHARED)
   add_library(cxxabi_shared SHARED $)
@@ -156,7 +154,10 @@ if (LIBCXXABI_ENABLE_SHARED)
 "1"
   VERSION
 "1.0")
-  list(APPEND LIBCXXABI_TARGETS "cxxabi_shared")
+  list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_shared")
+  if (LIBCXXABI_INSTALL_SHARED_LIBRARY)
+list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_shared")
+  endif()
 endif()
 
 # Build the static library.
@@ -183,14 +184,17 @@ if (LIBCXXABI_ENABLE_STATIC)
 "c++abi"
   POSITION_INDEPENDENT_CODE
 ON)
-  list(APPEND LIBCXXABI_TARGETS "cxxabi_static")
+  list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_static")
+  if (LIBCXXABI_INSTALL_STATIC_LIBRARY)
+list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_static")
+  endif()
 endif()
 
 # Add a meta-target for both libraries.
-add_custom_target(cxxabi DEPENDS ${LIBCXXABI_TARGETS})
+add_custom_target(cxxabi DEPENDS ${LIBCXXABI_BUILD_TARGETS})
 
 if (LIBCXXABI_INSTALL_LIBRARY)
-  install(TARGETS ${LIBCXXABI_TARGETS}
+  install(TARGETS ${LIBCXXABI_INSTALL_TARGETS}
 LIBRARY DESTINATION 
${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi
 ARCHIVE DESTINATION 
${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi
 )


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


[PATCH] D49763: [CUDA] Call atexit() for CUDA destructor early on.

2018-07-24 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

Depends a bit on the platform, __cxa_atexit on most modern ELF systems, 
fallback to atexit. If the global dtor is run too late, it smells like a 
missing library dependency. They are executed in topological order after all.


https://reviews.llvm.org/D49763



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


r337866 - Revert "[analyzer] Extend NoStoreFuncVisitor to insert a note on IVars"

2018-07-24 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Tue Jul 24 16:23:33 2018
New Revision: 337866

URL: http://llvm.org/viewvc/llvm-project?rev=337866=rev
Log:
Revert "[analyzer] Extend NoStoreFuncVisitor to insert a note on IVars"

This reverts commit a9e21bd727112cd69eabc1af648c5da6b773d06e.
Reverted because the dependency has not landed yet.

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp
cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=337866=337865=337866=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Tue Jul 24 
16:23:33 2018
@@ -22,7 +22,6 @@
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/Type.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Analysis/AnalysisDeclContext.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Analysis/CFGStmtMap.h"
@@ -307,26 +306,15 @@ public:
 
 CallEventRef<> Call =
 BRC.getStateManager().getCallEventManager().getCaller(SCtx, State);
+
 const PrintingPolicy  = BRC.getASTContext().getPrintingPolicy();
 const SourceManager  = BRC.getSourceManager();
-
-// Region of interest corresponds to an IVar, exiting a method
-// which could have written into that IVar, but did not.
-if (const auto *MC = dyn_cast(Call))
-  if (const auto *IvarR = dyn_cast(RegionOfInterest))
-if (potentiallyWritesIntoIvar(Call->getRuntimeDefinition().getDecl(),
-  IvarR->getDecl()) &&
-!isRegionOfInterestModifiedInFrame(N))
-  return notModifiedMemberDiagnostics(
-  Ctx, SM, PP, *CallExitLoc, Call,
-  MC->getReceiverSVal().getAsRegion());
-
 if (const auto *CCall = dyn_cast(Call)) {
   const MemRegion *ThisRegion = CCall->getCXXThisVal().getAsRegion();
   if (RegionOfInterest->isSubRegionOf(ThisRegion)
   && !CCall->getDecl()->isImplicit()
   && !isRegionOfInterestModifiedInFrame(N))
-return notModifiedMemberDiagnostics(Ctx, SM, PP, *CallExitLoc,
+return notModifiedInConstructorDiagnostics(Ctx, SM, PP, *CallExitLoc,
CCall, ThisRegion);
 }
 
@@ -343,7 +331,7 @@ public:
   if (isRegionOfInterestModifiedInFrame(N))
 return nullptr;
 
-  return notModifiedParameterDiagnostics(
+  return notModifiedDiagnostics(
   Ctx, SM, PP, *CallExitLoc, Call, PVD, R, IndirectionLevel);
 }
 QualType PT = T->getPointeeType();
@@ -358,22 +346,6 @@ public:
   }
 
 private:
-
-  /// \return Whether the method declaration \p Parent
-  /// syntactically has a binary operation writing into the ivar \p Ivar.
-  bool potentiallyWritesIntoIvar(const Decl *Parent,
- const ObjCIvarDecl *Ivar) {
-using namespace ast_matchers;
-if (!Parent)
-  return false;
-StatementMatcher WriteIntoIvarM = binaryOperator(
-hasOperatorName("="), hasLHS(ignoringParenImpCasts(objcIvarRefExpr(
-  hasDeclaration(equalsNode(Ivar));
-StatementMatcher ParentM = stmt(hasDescendant(WriteIntoIvarM));
-auto Matches = match(ParentM, *Parent->getBody(), Parent->getASTContext());
-return !Matches.empty();
-  }
-
   /// Check and lazily calculate whether the region of interest is
   /// modified in the stack frame to which \p N belongs.
   /// The calculation is cached in FramesModifyingRegion.
@@ -442,21 +414,19 @@ private:
Ty->getPointeeType().getCanonicalType().isConstQualified();
   }
 
-  /// \return Diagnostics piece for the member field not modified
-  /// in a given function.
-  std::shared_ptr notModifiedMemberDiagnostics(
+  std::shared_ptr notModifiedInConstructorDiagnostics(
   const LocationContext *Ctx,
   const SourceManager ,
   const PrintingPolicy ,
   CallExitBegin ,
-  CallEventRef<> Call,
+  const CXXConstructorCall *Call,
   const MemRegion *ArgRegion) {
-const char *TopRegionName = isa(Call) ? "self" : "this";
 SmallString<256> sbuf;
 llvm::raw_svector_ostream os(sbuf);
 os << DiagnosticsMsg;
-bool out = prettyPrintRegionName(TopRegionName, "->", /*IsReference=*/true,
- /*IndirectionLevel=*/1, ArgRegion, os, 
PP);
+bool out = prettyPrintRegionName(
+"this", "->", /*IsReference=*/true,
+/*IndirectionLevel=*/1, ArgRegion, os, PP);
 
 // Return nothing if we have failed to pretty-print.
 if (!out)
@@ -464,16 +434,14 @@ private:
 
 os << "'";
 

r337864 - [analyzer] Extend NoStoreFuncVisitor to insert a note on IVars

2018-07-24 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Tue Jul 24 16:14:29 2018
New Revision: 337864

URL: http://llvm.org/viewvc/llvm-project?rev=337864=rev
Log:
[analyzer] Extend NoStoreFuncVisitor to insert a note on IVars

The note is added in the following situation:

 - We are throwing a nullability-related warning on an IVar
 - The path goes through a method which *could have* (syntactically
 determined) written into that IVar, but did not

rdar://4260

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp
cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=337864=337863=337864=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Tue Jul 24 
16:14:29 2018
@@ -22,6 +22,7 @@
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Analysis/AnalysisDeclContext.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Analysis/CFGStmtMap.h"
@@ -306,15 +307,26 @@ public:
 
 CallEventRef<> Call =
 BRC.getStateManager().getCallEventManager().getCaller(SCtx, State);
-
 const PrintingPolicy  = BRC.getASTContext().getPrintingPolicy();
 const SourceManager  = BRC.getSourceManager();
+
+// Region of interest corresponds to an IVar, exiting a method
+// which could have written into that IVar, but did not.
+if (const auto *MC = dyn_cast(Call))
+  if (const auto *IvarR = dyn_cast(RegionOfInterest))
+if (potentiallyWritesIntoIvar(Call->getRuntimeDefinition().getDecl(),
+  IvarR->getDecl()) &&
+!isRegionOfInterestModifiedInFrame(N))
+  return notModifiedMemberDiagnostics(
+  Ctx, SM, PP, *CallExitLoc, Call,
+  MC->getReceiverSVal().getAsRegion());
+
 if (const auto *CCall = dyn_cast(Call)) {
   const MemRegion *ThisRegion = CCall->getCXXThisVal().getAsRegion();
   if (RegionOfInterest->isSubRegionOf(ThisRegion)
   && !CCall->getDecl()->isImplicit()
   && !isRegionOfInterestModifiedInFrame(N))
-return notModifiedInConstructorDiagnostics(Ctx, SM, PP, *CallExitLoc,
+return notModifiedMemberDiagnostics(Ctx, SM, PP, *CallExitLoc,
CCall, ThisRegion);
 }
 
@@ -331,7 +343,7 @@ public:
   if (isRegionOfInterestModifiedInFrame(N))
 return nullptr;
 
-  return notModifiedDiagnostics(
+  return notModifiedParameterDiagnostics(
   Ctx, SM, PP, *CallExitLoc, Call, PVD, R, IndirectionLevel);
 }
 QualType PT = T->getPointeeType();
@@ -346,6 +358,22 @@ public:
   }
 
 private:
+
+  /// \return Whether the method declaration \p Parent
+  /// syntactically has a binary operation writing into the ivar \p Ivar.
+  bool potentiallyWritesIntoIvar(const Decl *Parent,
+ const ObjCIvarDecl *Ivar) {
+using namespace ast_matchers;
+if (!Parent)
+  return false;
+StatementMatcher WriteIntoIvarM = binaryOperator(
+hasOperatorName("="), hasLHS(ignoringParenImpCasts(objcIvarRefExpr(
+  hasDeclaration(equalsNode(Ivar));
+StatementMatcher ParentM = stmt(hasDescendant(WriteIntoIvarM));
+auto Matches = match(ParentM, *Parent->getBody(), Parent->getASTContext());
+return !Matches.empty();
+  }
+
   /// Check and lazily calculate whether the region of interest is
   /// modified in the stack frame to which \p N belongs.
   /// The calculation is cached in FramesModifyingRegion.
@@ -414,19 +442,21 @@ private:
Ty->getPointeeType().getCanonicalType().isConstQualified();
   }
 
-  std::shared_ptr notModifiedInConstructorDiagnostics(
+  /// \return Diagnostics piece for the member field not modified
+  /// in a given function.
+  std::shared_ptr notModifiedMemberDiagnostics(
   const LocationContext *Ctx,
   const SourceManager ,
   const PrintingPolicy ,
   CallExitBegin ,
-  const CXXConstructorCall *Call,
+  CallEventRef<> Call,
   const MemRegion *ArgRegion) {
+const char *TopRegionName = isa(Call) ? "self" : "this";
 SmallString<256> sbuf;
 llvm::raw_svector_ostream os(sbuf);
 os << DiagnosticsMsg;
-bool out = prettyPrintRegionName(
-"this", "->", /*IsReference=*/true,
-/*IndirectionLevel=*/1, ArgRegion, os, PP);
+bool out = prettyPrintRegionName(TopRegionName, "->", /*IsReference=*/true,
+ 

[PATCH] D49763: [CUDA] Call atexit() for CUDA destructor early on.

2018-07-24 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In https://reviews.llvm.org/D49763#1174283, @joerg wrote:

> Can this ever end up in a shared library? If yes, please use the normal logic 
> for creating a global destructor. atexit is not very friendly to dlopen...


Yes, it can end up in a shared library. What would be the normal logic in this 
case?

We used to use regular global destructor, but has even worse issues. Alas, 
NVIDIA provides no documentation to how compiler-generated glue is expected to 
interact with CUDA runtime, so we need to guess what it wants.
NVCC-generated glue generates call to atexit(). If we use global destructors, 
then by the time they are executed, nvidia's runtime has already been 
deinitialized and our attempt to call it causes the crash.
Deregistering fatbin from atexit() works better, but apparently we still race 
with the runtime. calling atexit() before we register the fatbin appears to 
work for all combinations of {static/dynamic, kernel/runtime}.


https://reviews.llvm.org/D49763



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


[PATCH] D49766: Fix a crash when an error occurs in Template and the initializer is a nullptr for C++17

2018-07-24 Thread Balaji Iyer via Phabricator via cfe-commits
bviyer created this revision.
bviyer added reviewers: arphaman, erik.pilkington, dexonsmith.
Herald added a subscriber: cfe-commits.

When the error has occurred for one of the variables inside a template, the Loc 
function will try to find the end-location of the final item. If this variable 
is default initialized to nullptr, then the templateArgumentLoc function is 
invoked. It has an assert to see if the Argument's kind is Expression. If the 
default initializer is a nullptr, then the argument's kind will be NullPtr, not 
Expression. This will cause a compiler crash. This patch will allow NullPtr as 
a possibility for expression's kind.


Repository:
  rC Clang

https://reviews.llvm.org/D49766

Files:
  include/clang/AST/TemplateBase.h
  test/SemaObjCXX/class-templ-error-null-init.mm


Index: test/SemaObjCXX/class-templ-error-null-init.mm
===
--- /dev/null
+++ test/SemaObjCXX/class-templ-error-null-init.mm
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17  -verify %s
+
+template  // expected-error {{unknown 
type name 'd'}}
+class e {
+  public:
+e(a,b) {}
+};
+  e c([]{} ,[]{} );
Index: include/clang/AST/TemplateBase.h
===
--- include/clang/AST/TemplateBase.h
+++ include/clang/AST/TemplateBase.h
@@ -465,7 +465,14 @@
 
   TemplateArgumentLoc(const TemplateArgument , Expr *E)
   : Argument(Argument), LocInfo(E) {
-assert(Argument.getKind() == TemplateArgument::Expression);
+
+/* When an error occurs in a template value that is defaulted to
+   nullptr then the nullptr is left as-is and this function will
+   take in an argument that is of type NullPtr when compiled using
+   C++17 standard.  This is to make sure the compiler does not crash
+   and proceeds through.  */
+assert(Argument.getKind() == TemplateArgument::NullPtr ||
+   Argument.getKind() == TemplateArgument::Expression);
   }
 
   TemplateArgumentLoc(const TemplateArgument , 


Index: test/SemaObjCXX/class-templ-error-null-init.mm
===
--- /dev/null
+++ test/SemaObjCXX/class-templ-error-null-init.mm
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17  -verify %s
+
+template  // expected-error {{unknown type name 'd'}}
+class e {
+  public:
+e(a,b) {}
+};
+  e c([]{} ,[]{} );
Index: include/clang/AST/TemplateBase.h
===
--- include/clang/AST/TemplateBase.h
+++ include/clang/AST/TemplateBase.h
@@ -465,7 +465,14 @@
 
   TemplateArgumentLoc(const TemplateArgument , Expr *E)
   : Argument(Argument), LocInfo(E) {
-assert(Argument.getKind() == TemplateArgument::Expression);
+
+/* When an error occurs in a template value that is defaulted to
+   nullptr then the nullptr is left as-is and this function will
+   take in an argument that is of type NullPtr when compiled using
+   C++17 standard.  This is to make sure the compiler does not crash
+   and proceeds through.  */
+assert(Argument.getKind() == TemplateArgument::NullPtr ||
+   Argument.getKind() == TemplateArgument::Expression);
   }
 
   TemplateArgumentLoc(const TemplateArgument , 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49526: Updated llvm-proto-fuzzer to execute the compiled code

2018-07-24 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added inline comments.



Comment at: clang/tools/clang-fuzzer/handle-llvm/CMakeLists.txt:17
 
-# Depend on LLVM IR intrinsic generation.
+# Depend on LLVM IR instrinsic generation.
 set(handle_llvm_deps intrinsics_gen)

Typo introduced here.



Comment at: clang/tools/clang-fuzzer/handle-llvm/CMakeLists.txt:25
   handle_llvm.cpp
-
+  
   DEPENDS

Please don't add whitespace to a previously empty line.



Comment at: clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:10
 //
-// Implements HandleLLVM for use by the Clang fuzzers. Mimics the llc tool to
-// compile an LLVM IR file to X86_64 assembly.
+// Implements HandleLLVM for use by the Clang fuzzers. First runs an loop
+// vectorizer optimization pass over the given IR code. Then mimics lli on both

an -> a



Comment at: clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:112
+// Mimics the opt tool to run an optimization pass over the provided IR
+std::string OptLLVM(const std::string IR, CodeGenOpt::Level ) {
+  InitEverything();

Maybe this should be `const std::string ` or `StringRef`.



Comment at: clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:113
+std::string OptLLVM(const std::string IR, CodeGenOpt::Level ) {
+  InitEverything();
+ 

Does this need to be called every time we get a new input?  Can we call this 
from `LLVMFuzzerInitialize()`?



Comment at: clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:123
+  args[1] = arg1.c_str();
+  cl::ParseCommandLineOptions(2, args);
 

This shouldn't be required.  You should be able to directly add the passes you 
want.  See `llvm/lib/Passes/PassBuilder.cpp`.



Comment at: clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:132
+
+  Triple ModuleTriple(M->getTargetTriple());
+  TargetOptions Options = InitTargetOptionsFromCodeGenFlags();

Move this closer to where it's used.



Comment at: clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:133
+  Triple ModuleTriple(M->getTargetTriple());
+  TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
+  std::string CPUStr;

`Options` is never used.



Comment at: clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:136
+  std::string FeaturesStr;
+  std::unique_ptr TM(nullptr);
+  setFunctionAttributes(CPUStr, FeaturesStr, *M);

`TM` is never used.



Comment at: clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:137
+  std::unique_ptr TM(nullptr);
+  setFunctionAttributes(CPUStr, FeaturesStr, *M);
+  

Does this do anything since `CPUStr` and `FeaturesStr` are empty?



Comment at: clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:145
+  std::unique_ptr FPasses;
+  FPasses.reset(new legacy::FunctionPassManager(M.get()));
+  FPasses->add(createTargetTransformInfoWrapperPass(TargetIRAnalysis()));

Can we just make `FPasses` on stack instead?



Comment at: clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:190
+  builder.setMCJITMemoryManager(
+  std::unique_ptr(RTDyldMM));
+  builder.setOptLevel(OLvl);

These 3 lines can be combined to `builder.setMCJITMemoryManager(new 
SectionMemoryManager())`


Repository:
  rC Clang

https://reviews.llvm.org/D49526



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


[PATCH] D49765: [CMake] Use LIBCXXABI_LIBDIR_SUFFIX in libc++abi build

2018-07-24 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
phosek added reviewers: mgorny, EricWF.
Herald added subscribers: cfe-commits, ldionne, christof.

This was changed unintentionally in r335809.


Repository:
  rCXXA libc++abi

https://reviews.llvm.org/D49765

Files:
  libcxxabi/CMakeLists.txt


Index: libcxxabi/CMakeLists.txt
===
--- libcxxabi/CMakeLists.txt
+++ libcxxabi/CMakeLists.txt
@@ -172,7 +172,7 @@
 elseif(LLVM_LIBRARY_OUTPUT_INTDIR)
   set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
 else()
-  set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
+  set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX})
 endif()
 
 set(LIBCXXABI_INSTALL_PREFIX ${DEFAULT_INSTALL_PREFIX} CACHE STRING


Index: libcxxabi/CMakeLists.txt
===
--- libcxxabi/CMakeLists.txt
+++ libcxxabi/CMakeLists.txt
@@ -172,7 +172,7 @@
 elseif(LLVM_LIBRARY_OUTPUT_INTDIR)
   set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
 else()
-  set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
+  set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX})
 endif()
 
 set(LIBCXXABI_INSTALL_PREFIX ${DEFAULT_INSTALL_PREFIX} CACHE STRING
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49763: [CUDA] Call atexit() for CUDA destructor early on.

2018-07-24 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

Can this ever end up in a shared library? If yes, please use the normal logic 
for creating a global destructor. atexit is not very friendly to dlopen...


https://reviews.llvm.org/D49763



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


[PATCH] D49718: [CodeGen][ObjC] Make block copy/dispose helper function exception-safe.

2018-07-24 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 157149.
ahatanak added a comment.

Merge pushBlockObjectRelease and enterByrefCleanup.

In https://reviews.llvm.org/D49718#1174113, @rjmccall wrote:

> Heh, okay.  It looks like the runtime doesn't do anything different, but I 
> think it's probably more correct to always pass `BLOCK_FIELD_IS_WEAK` when 
> destroying a `__weak` block in GC modes.


I tried passing `BLOCK_FIELD_IS_WEAK | BLOCK_FIELD_IS_BYREF` to the call to 
enterByrefCleanup in EmitAutoVarCleanups, but it looks like 
test/CodeGenObjC/blocks.m fails if I do so. The test was committed in r125823 
and there is a comment that says " We're not supposed to pass 
BLOCK_FIELD_IS_WEAK here".

http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20110214/038996.html

Should we change the check in the test?


Repository:
  rC Clang

https://reviews.llvm.org/D49718

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGenObjCXX/arc-blocks.mm

Index: test/CodeGenObjCXX/arc-blocks.mm
===
--- test/CodeGenObjCXX/arc-blocks.mm
+++ test/CodeGenObjCXX/arc-blocks.mm
@@ -1,6 +1,9 @@
-// RUN: %clang_cc1 -std=gnu++98 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-runtime-has-weak -fblocks -fobjc-arc -o - %s | FileCheck %s
+// RUN: %clang_cc1 -std=gnu++98 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-runtime-has-weak -fblocks -fobjc-arc -fexceptions -fobjc-arc-exceptions -o - %s | FileCheck -check-prefix CHECK %s
+// RUN: %clang_cc1 -std=gnu++98 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-runtime-has-weak -fblocks -fobjc-arc -fexceptions -fobjc-arc-exceptions -O1 -o - %s | FileCheck -check-prefix CHECK-O1 %s
 
 // CHECK: [[A:.*]] = type { i64, [10 x i8*] }
+// CHECK: %[[STRUCT_TEST1_S0:.*]] = type { i32 }
+// CHECK: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 }
 
 // CHECK: [[LAYOUT0:@.*]] = private unnamed_addr constant [3 x i8] c" 9\00"
 
@@ -47,3 +50,133 @@
   // CHECK-NEXT: call void @_ZN5test01AD1Ev([[A]]* [[T1]])
   // CHECK-NEXT: ret void
 }
+
+namespace test1 {
+
+// Check that copy/dispose helper functions are exception safe.
+
+// CHECK-LABEL: define internal void @__copy_helper_block_(
+// CHECK: %[[BLOCK_SOURCE:.*]] = bitcast i8* %{{.*}} to <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>*
+// CHECK: %[[BLOCK_DEST:.*]] = bitcast i8* %{{.*}} to <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>*
+
+// CHECK: %[[V4:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>* %[[BLOCK_SOURCE]], i32 0, i32 6
+// CHECK: %[[V5:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>* %[[BLOCK_DEST]], i32 0, i32 6
+// CHECK: %[[BLOCKCOPY_SRC:.*]] = load i8*, i8** %[[V4]], align 8
+// CHECK: %[[V6:.*]] = bitcast i8** %[[V5]] to i8*
+// CHECK: call void @_Block_object_assign(i8* %[[V6]], i8* %[[BLOCKCOPY_SRC]], i32 8)
+
+// CHECK: %[[V7:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>* %[[BLOCK_SOURCE]], i32 0, i32 7
+// CHECK: %[[V8:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>* %[[BLOCK_DEST]], i32 0, i32 7
+// CHECK: call void @objc_copyWeak(i8** %[[V8]], i8** %[[V7]])
+
+// CHECK: %[[V9:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>* %[[BLOCK_SOURCE]], i32 0, i32 5
+// CHECK: %[[V10:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>* %[[BLOCK_DEST]], i32 0, i32 5
+// CHECK: %[[BLOCKCOPY_SRC2:.*]] = load i8*, i8** %[[V9]], align 8
+// CHECK: store i8* null, i8** %[[V10]], align 8
+// CHECK: call void @objc_storeStrong(i8** %[[V10]], i8* %[[BLOCKCOPY_SRC2]])
+
+// CHECK: %[[V11:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, 

r337862 - [Sema] Destroy tokens in DeclaratorChunk params

2018-07-24 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Tue Jul 24 15:47:16 2018
New Revision: 337862

URL: http://llvm.org/viewvc/llvm-project?rev=337862=rev
Log:
[Sema] Destroy tokens in DeclaratorChunk params

Otherwise this leaks in some edge cases.

Modified:
cfe/trunk/include/clang/Sema/DeclSpec.h

Modified: cfe/trunk/include/clang/Sema/DeclSpec.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/DeclSpec.h?rev=337862=337861=337862=diff
==
--- cfe/trunk/include/clang/Sema/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Sema/DeclSpec.h Tue Jul 24 15:47:16 2018
@@ -1355,8 +1355,7 @@ struct DeclaratorChunk {
 }
 
 void destroy() {
-  if (DeleteParams)
-delete[] Params;
+  freeParams();
   switch (getExceptionSpecType()) {
   default:
 break;


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


[PATCH] D49763: [CUDA] Call atexit() for CUDA destructor early on.

2018-07-24 Thread Justin Lebar via Phabricator via cfe-commits
jlebar accepted this revision.
jlebar added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/CodeGen/CGCUDANV.cpp:379
+  // Create destructor and register it with atexit() the way NVCC does it. 
Doing
+  // it during regular destructor phase worked in CUDA before 9.2 but results 
in
+  // double-free in 9.2.

the regular destructor phase



Comment at: clang/lib/CodeGen/CGCUDANV.cpp:380
+  // it during regular destructor phase worked in CUDA before 9.2 but results 
in
+  // double-free in 9.2.
+  if (llvm::Function *CleanupFn = makeModuleDtorFunction()) {

a double-free


https://reviews.llvm.org/D49763



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


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-07-24 Thread Mike Rice via Phabricator via cfe-commits
mikerice added a comment.

In https://reviews.llvm.org/D46652#1164010, @thakis wrote:

> Also, were you planning on also adding support for the (filename-less version 
> of) hdrstop pragma? After this change, that should probably be fairly 
> straightforward.


Thanks for taking a look.  I'll be going through our PCH tests at some point 
soon and will likely add support for this and any other interesting issues that 
remain.

In https://reviews.llvm.org/D46652#1166317, @thakis wrote:

> In https://reviews.llvm.org/D46652#1164016, @thakis wrote:
>
> > And finally (sorry about all the mails), this should probably be mentioned 
> > in the release notes (docs/ReleaseNotes.rst in the clang repo) since it's a 
> > notable new feature :-)
>
>
> I added this to releasenotes in r337381.


Thanks!


Repository:
  rC Clang

https://reviews.llvm.org/D46652



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


[PATCH] D49763: [CUDA] Call atexit() for CUDA destructor early on.

2018-07-24 Thread Artem Belevich via Phabricator via cfe-commits
tra created this revision.
tra added reviewers: jlebar, timshen.
Herald added subscribers: bixia, sanjoy.

There's apparently a race between fatbin destructors registered by us
and some internal calls registered by CUDA runtime from cudaRegisterFatbin.
Moving fatbin de-registration to atexit() was not sufficient to avoid crash in 
CUDA runtime on exit when the runtime was linked statically, but CUDA
kernel was launched from a shared library.

Moving atexit() call to before we call cudaRegisterFatbin appears to work
with both statically and dynamically linked CUDA TUs.


https://reviews.llvm.org/D49763

Files:
  clang/lib/CodeGen/CGCUDANV.cpp


Index: clang/lib/CodeGen/CGCUDANV.cpp
===
--- clang/lib/CodeGen/CGCUDANV.cpp
+++ clang/lib/CodeGen/CGCUDANV.cpp
@@ -375,6 +375,19 @@
 
   CtorBuilder.SetInsertPoint(CtorEntryBB);
 
+  // Create destructor and register it with atexit() the way NVCC does it. 
Doing
+  // it during regular destructor phase worked in CUDA before 9.2 but results 
in
+  // double-free in 9.2.
+  if (llvm::Function *CleanupFn = makeModuleDtorFunction()) {
+// extern "C" int atexit(void (*f)(void));
+llvm::FunctionType *AtExitTy =
+llvm::FunctionType::get(IntTy, CleanupFn->getType(), false);
+llvm::Constant *AtExitFunc =
+CGM.CreateRuntimeFunction(AtExitTy, "atexit", llvm::AttributeList(),
+  /*Local=*/true);
+CtorBuilder.CreateCall(AtExitFunc, CleanupFn);
+  }
+
   const char *FatbinConstantName;
   const char *FatbinSectionName;
   const char *ModuleIDSectionName;
@@ -530,19 +543,6 @@
 CtorBuilder.CreateCall(RegisterLinkedBinaryFunc, Args);
   }
 
-  // Create destructor and register it with atexit() the way NVCC does it. 
Doing
-  // it during regular destructor phase worked in CUDA before 9.2 but results 
in
-  // double-free in 9.2.
-  if (llvm::Function *CleanupFn = makeModuleDtorFunction()) {
-// extern "C" int atexit(void (*f)(void));
-llvm::FunctionType *AtExitTy =
-llvm::FunctionType::get(IntTy, CleanupFn->getType(), false);
-llvm::Constant *AtExitFunc =
-CGM.CreateRuntimeFunction(AtExitTy, "atexit", llvm::AttributeList(),
-  /*Local=*/true);
-CtorBuilder.CreateCall(AtExitFunc, CleanupFn);
-  }
-
   CtorBuilder.CreateRetVoid();
   return ModuleCtorFunc;
 }


Index: clang/lib/CodeGen/CGCUDANV.cpp
===
--- clang/lib/CodeGen/CGCUDANV.cpp
+++ clang/lib/CodeGen/CGCUDANV.cpp
@@ -375,6 +375,19 @@
 
   CtorBuilder.SetInsertPoint(CtorEntryBB);
 
+  // Create destructor and register it with atexit() the way NVCC does it. Doing
+  // it during regular destructor phase worked in CUDA before 9.2 but results in
+  // double-free in 9.2.
+  if (llvm::Function *CleanupFn = makeModuleDtorFunction()) {
+// extern "C" int atexit(void (*f)(void));
+llvm::FunctionType *AtExitTy =
+llvm::FunctionType::get(IntTy, CleanupFn->getType(), false);
+llvm::Constant *AtExitFunc =
+CGM.CreateRuntimeFunction(AtExitTy, "atexit", llvm::AttributeList(),
+  /*Local=*/true);
+CtorBuilder.CreateCall(AtExitFunc, CleanupFn);
+  }
+
   const char *FatbinConstantName;
   const char *FatbinSectionName;
   const char *ModuleIDSectionName;
@@ -530,19 +543,6 @@
 CtorBuilder.CreateCall(RegisterLinkedBinaryFunc, Args);
   }
 
-  // Create destructor and register it with atexit() the way NVCC does it. Doing
-  // it during regular destructor phase worked in CUDA before 9.2 but results in
-  // double-free in 9.2.
-  if (llvm::Function *CleanupFn = makeModuleDtorFunction()) {
-// extern "C" int atexit(void (*f)(void));
-llvm::FunctionType *AtExitTy =
-llvm::FunctionType::get(IntTy, CleanupFn->getType(), false);
-llvm::Constant *AtExitFunc =
-CGM.CreateRuntimeFunction(AtExitTy, "atexit", llvm::AttributeList(),
-  /*Local=*/true);
-CtorBuilder.CreateCall(AtExitFunc, CleanupFn);
-  }
-
   CtorBuilder.CreateRetVoid();
   return ModuleCtorFunc;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49589: [UBSan] Strengthen pointer checks in 'new' expressions

2018-07-24 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added inline comments.



Comment at: lib/CodeGen/CodeGenFunction.h:380
+  /// True if sanitizer checks for current pointer value are generated.
+  bool PointerChecksAreEmitted = false;
+

rjmccall wrote:
> sepavloff wrote:
> > rjmccall wrote:
> > > I don't think this is a good way of doing this.  Using global state makes 
> > > this unnecessarily difficult to reason about and can have unintended 
> > > effects.  For example, you are unintentionally suppressing any checks 
> > > that would be done as part of e.g. evaluating default arguments to the 
> > > default constructor.
> > > 
> > > You should pass a parameter down that says whether checks are necessary.  
> > > You can also use that parameter to e.g. suppress checks when constructing 
> > > local variables and temporaries, although you may already have an 
> > > alternative mechanism for doing that.
> > Passing parameter that inctructs whether to generate checks or not hardly 
> > can be directly implemented. This information is used in 
> > `EmitCXXConstructorCall` and it is formed during processing of `new` 
> > expression. The distance between these points can be 10 call frames, in 
> > some of them (`StmtVisitor` interface of `AggExprEmitter`) we cannot change 
> > function parameters.
> > The case of `new` expression in default arguments indeed handled 
> > incorrectly, thank you for the catch.  The updated version must process 
> > this case correctly.
> I'm not going to accept a patch based on global state here.  `AggValueSlot` 
> already propagates a bunch of flags about the slot into which we're emitting 
> an expression; I don't think it would be difficult to propagate some sort of 
> "alignment is statically known or already checked" flag along with that.
+ 1. @rjmccall offered similar advice in D25448, which led us to find a few 
more bugs / missed opportunities we otherwise wouldn't have.


Repository:
  rC Clang

https://reviews.llvm.org/D49589



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


[PATCH] D49752: [CMake] Don't install c++abi headers in standalone libc++ build

2018-07-24 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

With this change, only one copy of the c++abi headers gets copied - into 
`include/c++/v1/`.
LGTM.


Repository:
  rCXX libc++

https://reviews.llvm.org/D49752



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


[PATCH] D49526: Updated llvm-proto-fuzzer to execute the compiled code

2018-07-24 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 157138.
emmettneyman added a comment.

Cleaned up code

Tried to get rid of ParseCommandLineOptions() call but could not figure out
how to initialize a PassInfo object without it.


Repository:
  rC Clang

https://reviews.llvm.org/D49526

Files:
  clang/tools/clang-fuzzer/handle-llvm/CMakeLists.txt
  clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp

Index: clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
===
--- clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
+++ clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
@@ -7,33 +7,50 @@
 //
 //===--===//
 //
-// Implements HandleLLVM for use by the Clang fuzzers. Mimics the llc tool to
-// compile an LLVM IR file to X86_64 assembly.
+// Implements HandleLLVM for use by the Clang fuzzers. First runs an loop
+// vectorizer optimization pass over the given IR code. Then mimics lli on both
+// versions to JIT the generated code and execute it. Currently, functions are 
+// executed on dummy inputs.
 //
 //===--===//
 
 #include "handle_llvm.h"
 
 #include "llvm/ADT/Triple.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
+#include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/CodeGen/CommandFlags.inc"
 #include "llvm/CodeGen/MachineModuleInfo.h"
+#include "llvm/CodeGen/TargetPassConfig.h"
+#include "llvm/ExecutionEngine/JITEventListener.h"
+#include "llvm/ExecutionEngine/JITSymbol.h"
+#include "llvm/ExecutionEngine/MCJIT.h"
+#include "llvm/ExecutionEngine/ObjectCache.h"
+#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
+#include "llvm/ExecutionEngine/SectionMemoryManager.h"
+#include "llvm/IR/IRPrintingPasses.h"
 #include "llvm/IR/LegacyPassManager.h"
+#include "llvm/IR/LegacyPassNameParser.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Verifier.h"
 #include "llvm/IRReader/IRReader.h"
+#include "llvm/Pass.h"
 #include "llvm/PassRegistry.h"
-#include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/TargetRegistry.h"
+#include "llvm/Support/TargetSelect.h"
 #include "llvm/Target/TargetMachine.h"
-
-#include 
+#include "llvm/Transforms/IPO/PassManagerBuilder.h"
+#include "llvm/Transforms/IPO.h"
 
 using namespace llvm;
 
+static cl::list
+PassList(cl::desc("Optimizations available:"));
+
+// Helper function to parse command line args and find the optimization level
 static void getOptLevel(const std::vector ,
   CodeGenOpt::Level ) {
   // Find the optimization level from the command line args
@@ -53,59 +70,164 @@
   }
 }
 
-void clang_fuzzer::HandleLLVM(const std::string ,
-  const std::vector ) {
-  // Parse ExtraArgs to set the optimization level
-  CodeGenOpt::Level OLvl;
-  getOptLevel(ExtraArgs, OLvl);
+// Helper function to call pass initialization functions
+void InitEverything() {
+  PassRegistry  = *PassRegistry::getPassRegistry();
+  initializeCore(Registry);
+  initializeScalarOpts(Registry);
+  initializeVectorization(Registry);
+  initializeIPO(Registry);
+  initializeAnalysis(Registry);
+  initializeTransformUtils(Registry);
+  initializeInstCombine(Registry);
+  initializeAggressiveInstCombine(Registry);
+  initializeInstrumentation(Registry);
+  initializeTarget(Registry);
+}
+
+void ErrorAndExit(std::string message) {
+  errs()<< "ERROR: " << message << "\n";
+  std::exit(1);
+}
+
+// Helper function to add optimization passes to the TargetMachine at the 
+// specified optimization level, OptLevel
+static void AddOptimizationPasses(legacy::PassManagerBase ,
+  legacy::FunctionPassManager ,
+  unsigned OptLevel, unsigned SizeLevel) {
+  // Verify that input is correct by adding a verifier pass
+  FPM.add(createVerifierPass());
+
+  // Create and initializa a PassManagerBuilder
+  PassManagerBuilder Builder;
+  Builder.OptLevel = OptLevel;
+  Builder.SizeLevel = SizeLevel;
+  Builder.Inliner = createFunctionInliningPass(OptLevel, SizeLevel, false);
+  Builder.LoopVectorize = true;
+  Builder.populateFunctionPassManager(FPM);
+  Builder.populateModulePassManager(MPM);
+}
+
+// Mimics the opt tool to run an optimization pass over the provided IR
+std::string OptLLVM(const std::string IR, CodeGenOpt::Level ) {
+  InitEverything();
+ 
+  // Mimic argc and argv and pass them to ParseCommandLineOptions to initilize
+  // PassList, ie which optimizations we want to run on the IR
+  // TODO: Find a better way of doing this
+  const char *args[2];
+  std::string arg0 = "llvm-proto-fuzzer";
+  std::string arg1 = "-loop-vectorize";
+  args[0] = arg0.c_str();
+  args[1] = arg1.c_str();
+  cl::ParseCommandLineOptions(2, args);
 
-  // Set the Module to include the the 

[PATCH] D49760: [clang:sema] de-duplicate getDepthAndIndex helpers

2018-07-24 Thread Vedant Kumar via Phabricator via cfe-commits
vsk accepted this revision.
vsk added a comment.
This revision is now accepted and ready to land.

In https://reviews.llvm.org/D49760#1174141, @nickdesaulniers wrote:

> Thanks for the review. Today is my first day committing to clang!


Welcome :).

LGTM. Feel free to commit this yourself once you obtain commit access 
(https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access). I'd also 
be happy to commit this on your behalf.


Repository:
  rC Clang

https://reviews.llvm.org/D49760



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


[clang-tools-extra] r337860 - [clangd] Guard fuzzer against empty inputs.

2018-07-24 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Tue Jul 24 14:50:06 2018
New Revision: 337860

URL: http://llvm.org/viewvc/llvm-project?rev=337860=rev
Log:
[clangd] Guard fuzzer against empty inputs.

Modified:
clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp

Modified: clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp?rev=337860=337859=337860=diff
==
--- clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp (original)
+++ clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp Tue Jul 24 14:50:06 
2018
@@ -20,6 +20,9 @@
 #include 
 
 extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
+  if (size == 0)
+return 0;
+
   clang::clangd::JSONOutput Out(llvm::nulls(), llvm::nulls(),
 clang::clangd::Logger::Error, nullptr);
   clang::clangd::CodeCompleteOptions CCOpts;


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


[PATCH] D49760: [clang:sema] de-duplicate getDepthAndIndex helpers

2018-07-24 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 157134.
nickdesaulniers added a comment.

- prefer auto when type is specified on RHS of assignment.


Repository:
  rC Clang

https://reviews.llvm.org/D49760

Files:
  include/clang/Sema/SemaInternal.h
  lib/Sema/SemaTemplateDeduction.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/SemaTemplateVariadic.cpp

Index: lib/Sema/SemaTemplateVariadic.cpp
===
--- lib/Sema/SemaTemplateVariadic.cpp
+++ lib/Sema/SemaTemplateVariadic.cpp
@@ -26,19 +26,6 @@
 // Visitor that collects unexpanded parameter packs
 //
 
-/// Retrieve the depth and index of a parameter pack.
-static std::pair 
-getDepthAndIndex(NamedDecl *ND) {
-  if (TemplateTypeParmDecl *TTP = dyn_cast(ND))
-return std::make_pair(TTP->getDepth(), TTP->getIndex());
-  
-  if (NonTypeTemplateParmDecl *NTTP = dyn_cast(ND))
-return std::make_pair(NTTP->getDepth(), NTTP->getIndex());
-  
-  TemplateTemplateParmDecl *TTP = cast(ND);
-  return std::make_pair(TTP->getDepth(), TTP->getIndex());
-}
-
 namespace {
   /// A class that collects unexpanded parameter packs.
   class CollectUnexpandedParameterPacksVisitor :
Index: lib/Sema/SemaTemplateInstantiate.cpp
===
--- lib/Sema/SemaTemplateInstantiate.cpp
+++ lib/Sema/SemaTemplateInstantiate.cpp
@@ -708,19 +708,6 @@
   return None;
 }
 
-/// Retrieve the depth and index of a parameter pack.
-static std::pair 
-getDepthAndIndex(NamedDecl *ND) {
-  if (TemplateTypeParmDecl *TTP = dyn_cast(ND))
-return std::make_pair(TTP->getDepth(), TTP->getIndex());
-  
-  if (NonTypeTemplateParmDecl *NTTP = dyn_cast(ND))
-return std::make_pair(NTTP->getDepth(), NTTP->getIndex());
-  
-  TemplateTemplateParmDecl *TTP = cast(ND);
-  return std::make_pair(TTP->getDepth(), TTP->getIndex());
-}
-
 //===--===/
 // Template Instantiation for Types
 //===--===/
Index: lib/Sema/SemaTemplateDeduction.cpp
===
--- lib/Sema/SemaTemplateDeduction.cpp
+++ lib/Sema/SemaTemplateDeduction.cpp
@@ -628,29 +628,6 @@
   }
 }
 
-/// Retrieve the depth and index of a template parameter.
-static std::pair
-getDepthAndIndex(NamedDecl *ND) {
-  if (TemplateTypeParmDecl *TTP = dyn_cast(ND))
-return std::make_pair(TTP->getDepth(), TTP->getIndex());
-
-  if (NonTypeTemplateParmDecl *NTTP = dyn_cast(ND))
-return std::make_pair(NTTP->getDepth(), NTTP->getIndex());
-
-  TemplateTemplateParmDecl *TTP = cast(ND);
-  return std::make_pair(TTP->getDepth(), TTP->getIndex());
-}
-
-/// Retrieve the depth and index of an unexpanded parameter pack.
-static std::pair
-getDepthAndIndex(UnexpandedParameterPack UPP) {
-  if (const TemplateTypeParmType *TTP
-  = UPP.first.dyn_cast())
-return std::make_pair(TTP->getDepth(), TTP->getIndex());
-
-  return getDepthAndIndex(UPP.first.get());
-}
-
 /// Helper function to build a TemplateParameter when we don't
 /// know its type statically.
 static TemplateParameter makeTemplateParameter(Decl *D) {
Index: include/clang/Sema/SemaInternal.h
===
--- include/clang/Sema/SemaInternal.h
+++ include/clang/Sema/SemaInternal.h
@@ -101,6 +101,27 @@
   return nullptr;
 }
 
+/// Retrieve the depth and index of a template parameter.
+inline std::pair getDepthAndIndex(NamedDecl *ND) {
+  if (const auto *TTP = dyn_cast(ND))
+return std::make_pair(TTP->getDepth(), TTP->getIndex());
+
+  if (const auto *NTTP = dyn_cast(ND))
+return std::make_pair(NTTP->getDepth(), NTTP->getIndex());
+
+  const auto *TTP = cast(ND);
+  return std::make_pair(TTP->getDepth(), TTP->getIndex());
+}
+
+/// Retrieve the depth and index of an unexpanded parameter pack.
+inline std::pair
+getDepthAndIndex(UnexpandedParameterPack UPP) {
+  if (const auto *TTP = UPP.first.dyn_cast())
+return std::make_pair(TTP->getDepth(), TTP->getIndex());
+
+  return getDepthAndIndex(UPP.first.get());
+}
+
 class TypoCorrectionConsumer : public VisibleDeclConsumer {
   typedef SmallVector TypoResultList;
   typedef llvm::StringMap TypoResultsMap;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49760: [clang:sema] de-duplicate getDepthAndIndex helpers

2018-07-24 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers marked an inline comment as done.
nickdesaulniers added a comment.

Thanks for the review. Today is my first day committing to clang!


Repository:
  rC Clang

https://reviews.llvm.org/D49760



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


LLVM buildmaster will be restarted tonight

2018-07-24 Thread Galina Kistanova via cfe-commits
 Hello everyone,

LLVM buildmaster will be updated and restarted after 6PM Pacific time today.

Thanks

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


[PATCH] D49760: [clang:sema] de-duplicate getDepthAndIndex helpers

2018-07-24 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

Thanks for doing this!




Comment at: include/clang/Sema/SemaInternal.h:120
+  if (const TemplateTypeParmType *TTP =
+  UPP.first.dyn_cast())
+return std::make_pair(TTP->getDepth(), TTP->getIndex());

Perhaps 'const auto *TTP = ...' would read better here, given that the expected 
type appears once already in the r.h.s of the expression? I have the same 
comment re: the three other casts above.


Repository:
  rC Clang

https://reviews.llvm.org/D49760



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


[PATCH] D49760: [clang:sema] de-duplicate getDepthAndIndex helpers

2018-07-24 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers created this revision.
nickdesaulniers added reviewers: srhines, pirama.
Herald added a subscriber: cfe-commits.

Continuing off of:
https://reviews.llvm.org/D38382

Fixes:
https://bugs.llvm.org/show_bug.cgi?id=12176


Repository:
  rC Clang

https://reviews.llvm.org/D49760

Files:
  include/clang/Sema/SemaInternal.h
  lib/Sema/SemaTemplateDeduction.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/SemaTemplateVariadic.cpp

Index: lib/Sema/SemaTemplateVariadic.cpp
===
--- lib/Sema/SemaTemplateVariadic.cpp
+++ lib/Sema/SemaTemplateVariadic.cpp
@@ -26,19 +26,6 @@
 // Visitor that collects unexpanded parameter packs
 //
 
-/// Retrieve the depth and index of a parameter pack.
-static std::pair 
-getDepthAndIndex(NamedDecl *ND) {
-  if (TemplateTypeParmDecl *TTP = dyn_cast(ND))
-return std::make_pair(TTP->getDepth(), TTP->getIndex());
-  
-  if (NonTypeTemplateParmDecl *NTTP = dyn_cast(ND))
-return std::make_pair(NTTP->getDepth(), NTTP->getIndex());
-  
-  TemplateTemplateParmDecl *TTP = cast(ND);
-  return std::make_pair(TTP->getDepth(), TTP->getIndex());
-}
-
 namespace {
   /// A class that collects unexpanded parameter packs.
   class CollectUnexpandedParameterPacksVisitor :
Index: lib/Sema/SemaTemplateInstantiate.cpp
===
--- lib/Sema/SemaTemplateInstantiate.cpp
+++ lib/Sema/SemaTemplateInstantiate.cpp
@@ -708,19 +708,6 @@
   return None;
 }
 
-/// Retrieve the depth and index of a parameter pack.
-static std::pair 
-getDepthAndIndex(NamedDecl *ND) {
-  if (TemplateTypeParmDecl *TTP = dyn_cast(ND))
-return std::make_pair(TTP->getDepth(), TTP->getIndex());
-  
-  if (NonTypeTemplateParmDecl *NTTP = dyn_cast(ND))
-return std::make_pair(NTTP->getDepth(), NTTP->getIndex());
-  
-  TemplateTemplateParmDecl *TTP = cast(ND);
-  return std::make_pair(TTP->getDepth(), TTP->getIndex());
-}
-
 //===--===/
 // Template Instantiation for Types
 //===--===/
Index: lib/Sema/SemaTemplateDeduction.cpp
===
--- lib/Sema/SemaTemplateDeduction.cpp
+++ lib/Sema/SemaTemplateDeduction.cpp
@@ -628,29 +628,6 @@
   }
 }
 
-/// Retrieve the depth and index of a template parameter.
-static std::pair
-getDepthAndIndex(NamedDecl *ND) {
-  if (TemplateTypeParmDecl *TTP = dyn_cast(ND))
-return std::make_pair(TTP->getDepth(), TTP->getIndex());
-
-  if (NonTypeTemplateParmDecl *NTTP = dyn_cast(ND))
-return std::make_pair(NTTP->getDepth(), NTTP->getIndex());
-
-  TemplateTemplateParmDecl *TTP = cast(ND);
-  return std::make_pair(TTP->getDepth(), TTP->getIndex());
-}
-
-/// Retrieve the depth and index of an unexpanded parameter pack.
-static std::pair
-getDepthAndIndex(UnexpandedParameterPack UPP) {
-  if (const TemplateTypeParmType *TTP
-  = UPP.first.dyn_cast())
-return std::make_pair(TTP->getDepth(), TTP->getIndex());
-
-  return getDepthAndIndex(UPP.first.get());
-}
-
 /// Helper function to build a TemplateParameter when we don't
 /// know its type statically.
 static TemplateParameter makeTemplateParameter(Decl *D) {
Index: include/clang/Sema/SemaInternal.h
===
--- include/clang/Sema/SemaInternal.h
+++ include/clang/Sema/SemaInternal.h
@@ -101,6 +101,28 @@
   return nullptr;
 }
 
+/// Retrieve the depth and index of a template parameter.
+inline std::pair getDepthAndIndex(NamedDecl *ND) {
+  if (TemplateTypeParmDecl *TTP = dyn_cast(ND))
+return std::make_pair(TTP->getDepth(), TTP->getIndex());
+
+  if (NonTypeTemplateParmDecl *NTTP = dyn_cast(ND))
+return std::make_pair(NTTP->getDepth(), NTTP->getIndex());
+
+  TemplateTemplateParmDecl *TTP = cast(ND);
+  return std::make_pair(TTP->getDepth(), TTP->getIndex());
+}
+
+/// Retrieve the depth and index of an unexpanded parameter pack.
+inline std::pair
+getDepthAndIndex(UnexpandedParameterPack UPP) {
+  if (const TemplateTypeParmType *TTP =
+  UPP.first.dyn_cast())
+return std::make_pair(TTP->getDepth(), TTP->getIndex());
+
+  return getDepthAndIndex(UPP.first.get());
+}
+
 class TypoCorrectionConsumer : public VisibleDeclConsumer {
   typedef SmallVector TypoResultList;
   typedef llvm::StringMap TypoResultsMap;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49718: [CodeGen][ObjC] Make block copy/dispose helper function exception-safe.

2018-07-24 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In https://reviews.llvm.org/D49718#1173883, @ahatanak wrote:

> Address review comments.
>
> I think I should be able to merge pushBlockObjectRelease and 
> enterByrefCleanup, but the BlockFieldFlags that are passed are different. We 
> set BLOCK_FIELD_IS_WEAK in addition to BLOCK_FIELD_IS_BYREF when 
> isObjCGCWeak() returns true and we are emitting the copy/dispose helper 
> functions, but when enterByrefCleanup is called from EmitAutoVarCleanups, 
> only BLOCK_FIELD_IS_BYREF is set.


Heh, okay.  It looks like the runtime doesn't do anything different, but I 
think it's probably more correct to always pass `BLOCK_FIELD_IS_WEAK` when 
destroying a `__weak` block in GC modes.

> In https://reviews.llvm.org/D49718#1173068, @rjmccall wrote:
> 
>> I don't think it makes any difference because we shouldn't be emitting 
>> cleanup paths when exceptions are disabled.  I don't think there's an 
>> intended difference in semantics between those two destructor-cleanup paths, 
>> at least.
> 
> 
> OK, I see.
> 
> If it doesn't make any difference, I think I can push NormalAndEHCleanup 
> unconditionally when copying a BlockObject capture instead of pushing 
> NormalCleanup when EH is disabled. I made that change in the updated patch.

Ok.  Thanks, I like how it looks now.


Repository:
  rC Clang

https://reviews.llvm.org/D49718



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


r337857 - Don't lifetime-extend or track lifetime problems through the LHS of '->*'.

2018-07-24 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Jul 24 14:18:30 2018
New Revision: 337857

URL: http://llvm.org/viewvc/llvm-project?rev=337857=rev
Log:
Don't lifetime-extend or track lifetime problems through the LHS of '->*'.

Fixes a false-positive warning found by selfhost.

Modified:
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/test/SemaCXX/return-stack-addr.cpp

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=337857=337856=337857=diff
==
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Tue Jul 24 14:18:30 2018
@@ -108,7 +108,7 @@ const Expr *Expr::skipRValueSubobjectAdj
 }
   }
 } else if (const BinaryOperator *BO = dyn_cast(E)) {
-  if (BO->isPtrMemOp()) {
+  if (BO->getOpcode() == BO_PtrMemD) {
 assert(BO->getRHS()->isRValue());
 E = BO->getLHS();
 const MemberPointerType *MPT =

Modified: cfe/trunk/test/SemaCXX/return-stack-addr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/return-stack-addr.cpp?rev=337857=337856=337857=diff
==
--- cfe/trunk/test/SemaCXX/return-stack-addr.cpp (original)
+++ cfe/trunk/test/SemaCXX/return-stack-addr.cpp Tue Jul 24 14:18:30 2018
@@ -157,3 +157,9 @@ void ret_from_lambda() {
   (void) [&]() -> int& { int  = b; return a; };
   (void) [=]() mutable -> int& { int  = b; return a; };
 }
+
+namespace mem_ptr {
+  struct X {};
+  int X::*f();
+  int (X *p) { return p->*f(); }
+}


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


[PATCH] D49589: [UBSan] Strengthen pointer checks in 'new' expressions

2018-07-24 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CodeGenFunction.h:380
+  /// True if sanitizer checks for current pointer value are generated.
+  bool PointerChecksAreEmitted = false;
+

sepavloff wrote:
> rjmccall wrote:
> > I don't think this is a good way of doing this.  Using global state makes 
> > this unnecessarily difficult to reason about and can have unintended 
> > effects.  For example, you are unintentionally suppressing any checks that 
> > would be done as part of e.g. evaluating default arguments to the default 
> > constructor.
> > 
> > You should pass a parameter down that says whether checks are necessary.  
> > You can also use that parameter to e.g. suppress checks when constructing 
> > local variables and temporaries, although you may already have an 
> > alternative mechanism for doing that.
> Passing parameter that inctructs whether to generate checks or not hardly can 
> be directly implemented. This information is used in `EmitCXXConstructorCall` 
> and it is formed during processing of `new` expression. The distance between 
> these points can be 10 call frames, in some of them (`StmtVisitor` interface 
> of `AggExprEmitter`) we cannot change function parameters.
> The case of `new` expression in default arguments indeed handled incorrectly, 
> thank you for the catch.  The updated version must process this case 
> correctly.
I'm not going to accept a patch based on global state here.  `AggValueSlot` 
already propagates a bunch of flags about the slot into which we're emitting an 
expression; I don't think it would be difficult to propagate some sort of 
"alignment is statically known or already checked" flag along with that.


Repository:
  rC Clang

https://reviews.llvm.org/D49589



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


[PATCH] D49523: [clangd] Add support for per-file override compilation command

2018-07-24 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

In https://reviews.llvm.org/D49523#1171484, @ilya-biryukov wrote:

> The extensions itself seems like a reasonable way to provide compile commands 
> for the individual files. In case didChangeConfiguration does not work for 
> you for some reason, happy to take a look at this change too.
>  One drawback of using didChangeConfiguration for compile commands is that it 
> forces global invalidation, which may be a bad thing if your client tracks 
> compile commands on a smaller scale and can send requests to invalidate 
> individual files. However, if you're happy with it, we might get away with 
> not adding yet another mechanism to pass compile commands to clangd, which is 
> definitely a good thing!


We actually need both mechanisms. I posted the didChangeConfiguration extension 
to https://reviews.llvm.org/D49758.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49523



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


[PATCH] D49758: [clangd] allow clients to pass in compilationDatabaseChanges in the 'workspace/didChangeConfiguration' request

2018-07-24 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.
arphaman added reviewers: malaperle-ericsson, ilya-biryukov, sammccall, jkorous.
arphaman added a project: clang-tools-extra.
Herald added subscribers: dexonsmith, MaskRay, ioeric.

This patch is based on https://reviews.llvm.org/D49523.

It extends the 'workspace/didChangeConfiguration' request to allow us to pass 
in a compilation database subset that we would like to update in the workspace.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49758

Files:
  clangd/ClangdLSPServer.cpp
  clangd/Protocol.cpp
  clangd/Protocol.h
  test/clangd/did-change-configuration-params.test

Index: test/clangd/did-change-configuration-params.test
===
--- /dev/null
+++ test/clangd/did-change-configuration-params.test
@@ -0,0 +1,50 @@
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.c","languageId":"c","version":1,"text":"int main() { int i; return i; }"}}}
+#  CHECK:  "method": "textDocument/publishDiagnostics",
+# CHECK-NEXT:  "params": {
+# CHECK-NEXT:"diagnostics": [],
+# CHECK-NEXT:"uri": "file://{{.*}}/foo.c"
+# CHECK-NEXT:  }
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///bar.c","languageId":"c","version":1,"text":"int main() { int i; return i; }"}}}
+#  CHECK:  "method": "textDocument/publishDiagnostics",
+# CHECK-NEXT:  "params": {
+# CHECK-NEXT:"diagnostics": [],
+# CHECK-NEXT:"uri": "file://{{.*}}/bar.c"
+# CHECK-NEXT:  }
+---
+{"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":{"compilationDatabaseChanges":{"/clangd-test/foo.c": ["clang", "-c", "foo.c", "-Wall", "-Werror"]
+#  CHECK:  "method": "textDocument/publishDiagnostics",
+# CHECK-NEXT:  "params": {
+# CHECK-NEXT:"diagnostics": [
+# CHECK-NEXT:  {
+# CHECK-NEXT:"message": "variable 'i' is uninitialized when used here",
+# CHECK-NEXT:"range": {
+# CHECK-NEXT:  "end": {
+# CHECK-NEXT:"character": 28,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "start": {
+# CHECK-NEXT:"character": 27,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  }
+# CHECK-NEXT:},
+# CHECK-NEXT:"severity": 1
+# CHECK-NEXT:  }
+# CHECK-NEXT:],
+# CHECK-NEXT:"uri": "file://{{.*}}/foo.c"
+# CHECK-NEXT:  }
+
+#  CHECK:  "method": "textDocument/publishDiagnostics",
+# CHECK-NEXT:  "params": {
+# CHECK-NEXT:"diagnostics": [],
+# CHECK-NEXT:"uri": "file://{{.*}}/bar.c"
+# CHECK-NEXT:  }
+---
+{"jsonrpc":"2.0","id":5,"method":"shutdown"}
+---
+{"jsonrpc":"2.0":"method":"exit"}
+
+
Index: clangd/Protocol.h
===
--- clangd/Protocol.h
+++ clangd/Protocol.h
@@ -424,6 +424,10 @@
 /// since the data received is described as 'any' type in LSP.
 struct ClangdConfigurationParamsChange {
   llvm::Optional compilationDatabasePath;
+
+  // The changes that happened to the compilation database.
+  llvm::Optional>>
+  compilationDatabaseChanges;
 };
 bool fromJSON(const llvm::json::Value &, ClangdConfigurationParamsChange &);
 
Index: clangd/Protocol.cpp
===
--- clangd/Protocol.cpp
+++ clangd/Protocol.cpp
@@ -595,7 +595,8 @@
 bool fromJSON(const json::Value ,
   ClangdConfigurationParamsChange ) {
   json::ObjectMapper O(Params);
-  return O && O.map("compilationDatabasePath", CCPC.compilationDatabasePath);
+  return O && O.map("compilationDatabasePath", CCPC.compilationDatabasePath) &&
+ O.map("compilationDatabaseChanges", CCPC.compilationDatabaseChanges);
 }
 
 } // namespace clangd
Index: clangd/ClangdLSPServer.cpp
===
--- clangd/ClangdLSPServer.cpp
+++ clangd/ClangdLSPServer.cpp
@@ -418,6 +418,18 @@
 
 reparseOpenedFiles();
   }
+
+  // Update to the compilation database.
+  if (Settings.compilationDatabaseChanges) {
+const auto  = *Settings.compilationDatabaseChanges;
+for (const auto  : CompileCommandUpdates) {
+  NonCachedCDB.overrideCompilationCommandForFile(Entry.first,
+ std::move(Entry.second));
+}
+CDB.clear();
+
+reparseOpenedFiles();
+  }
 }
 
 ClangdLSPServer::ClangdLSPServer(JSONOutput ,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49100: Avoid returning an invalid end source loc

2018-07-24 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 157116.
steveire retitled this revision from "Inline DeclarationNameInfo::getLocEnd 
into callers" to "Avoid returning an invalid end source loc".
steveire edited the summary of this revision.

Repository:
  rC Clang

https://reviews.llvm.org/D49100

Files:
  include/clang/AST/DeclarationName.h
  lib/AST/DeclarationName.cpp


Index: lib/AST/DeclarationName.cpp
===
--- lib/AST/DeclarationName.cpp
+++ lib/AST/DeclarationName.cpp
@@ -689,7 +689,7 @@
   llvm_unreachable("Unexpected declaration name kind");
 }
 
-SourceLocation DeclarationNameInfo::getEndLoc() const {
+SourceLocation DeclarationNameInfo::getEndLocPrivate() const {
   switch (Name.getNameKind()) {
   case DeclarationName::Identifier:
   case DeclarationName::CXXDeductionGuideName:
Index: include/clang/AST/DeclarationName.h
===
--- include/clang/AST/DeclarationName.h
+++ include/clang/AST/DeclarationName.h
@@ -558,7 +558,7 @@
   SourceLocation getBeginLoc() const { return NameLoc; }
 
   /// getEndLoc - Retrieve the location of the last token.
-  SourceLocation getEndLoc() const;
+  SourceLocation getEndLoc() const { return getLocEnd(); }
 
   /// getSourceRange - The range of the declaration name.
   SourceRange getSourceRange() const LLVM_READONLY {
@@ -570,9 +570,11 @@
   }
 
   SourceLocation getLocEnd() const LLVM_READONLY {
-SourceLocation EndLoc = getEndLoc();
+SourceLocation EndLoc = getEndLocPrivate();
 return EndLoc.isValid() ? EndLoc : getLocStart();
   }
+private:
+  SourceLocation getEndLocPrivate() const;
 };
 
 /// Insertion operator for diagnostics.  This allows sending DeclarationName's


Index: lib/AST/DeclarationName.cpp
===
--- lib/AST/DeclarationName.cpp
+++ lib/AST/DeclarationName.cpp
@@ -689,7 +689,7 @@
   llvm_unreachable("Unexpected declaration name kind");
 }
 
-SourceLocation DeclarationNameInfo::getEndLoc() const {
+SourceLocation DeclarationNameInfo::getEndLocPrivate() const {
   switch (Name.getNameKind()) {
   case DeclarationName::Identifier:
   case DeclarationName::CXXDeductionGuideName:
Index: include/clang/AST/DeclarationName.h
===
--- include/clang/AST/DeclarationName.h
+++ include/clang/AST/DeclarationName.h
@@ -558,7 +558,7 @@
   SourceLocation getBeginLoc() const { return NameLoc; }
 
   /// getEndLoc - Retrieve the location of the last token.
-  SourceLocation getEndLoc() const;
+  SourceLocation getEndLoc() const { return getLocEnd(); }
 
   /// getSourceRange - The range of the declaration name.
   SourceRange getSourceRange() const LLVM_READONLY {
@@ -570,9 +570,11 @@
   }
 
   SourceLocation getLocEnd() const LLVM_READONLY {
-SourceLocation EndLoc = getEndLoc();
+SourceLocation EndLoc = getEndLocPrivate();
 return EndLoc.isValid() ? EndLoc : getLocStart();
   }
+private:
+  SourceLocation getEndLocPrivate() const;
 };
 
 /// Insertion operator for diagnostics.  This allows sending DeclarationName's
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r337850 - Revert "[VFS] Cleanups to VFS interfaces."

2018-07-24 Thread Jordan Rupprecht via cfe-commits
Author: rupprecht
Date: Tue Jul 24 13:28:07 2018
New Revision: 337850

URL: http://llvm.org/viewvc/llvm-project?rev=337850=rev
Log:
Revert "[VFS] Cleanups to VFS interfaces."

This reverts commit r337834 due to test failures.

Modified:
cfe/trunk/include/clang/Basic/VirtualFileSystem.h
cfe/trunk/lib/Basic/FileManager.cpp
cfe/trunk/lib/Basic/VirtualFileSystem.cpp

Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/VirtualFileSystem.h?rev=337850=337849=337850=diff
==
--- cfe/trunk/include/clang/Basic/VirtualFileSystem.h (original)
+++ cfe/trunk/include/clang/Basic/VirtualFileSystem.h Tue Jul 24 13:28:07 2018
@@ -45,8 +45,7 @@ class MemoryBuffer;
 namespace clang {
 namespace vfs {
 
-/// File information from a \p File::status() operation.
-/// This is roughly equivalent to a `struct stat` plus a file path.
+/// The result of a \p status operation.
 class Status {
   std::string Name;
   llvm::sys::fs::UniqueID UID;
@@ -67,14 +66,13 @@ public:
  llvm::sys::TimePoint<> MTime, uint32_t User, uint32_t Group,
  uint64_t Size, llvm::sys::fs::file_type Type,
  llvm::sys::fs::perms Perms);
-  Status(const llvm::sys::fs::file_status , StringRef Name);
 
-  /// Get a copy of a this Status with a different name.
-  Status copyWithNewName(StringRef NewName);
+  /// Get a copy of a Status with a different name.
+  static Status copyWithNewName(const Status , StringRef NewName);
+  static Status copyWithNewName(const llvm::sys::fs::file_status ,
+StringRef NewName);
 
   /// Returns the name that should be used for this file or directory.
-  /// This is usually the path that the file was opened as, without resolving
-  /// relative paths or symlinks.
   StringRef getName() const { return Name; }
 
   /// @name Status interface from llvm::sys::fs
@@ -109,16 +107,15 @@ public:
   virtual ~File();
 
   /// Get the status of the file.
-  /// This may access the filesystem (e.g. `stat()`), or return a cached value.
   virtual llvm::ErrorOr status() = 0;
 
-  /// Get the "real name" of the file, if available.
-  /// This should be absolute, and typically has symlinks resolved.
-  ///
-  /// Only some VFS implementations provide this, and only sometimes.
-  /// FIXME: these maybe-available semantics are not very useful. It would be
-  /// nice if this was more consistent with FileSystem::getRealPath().
-  virtual llvm::Optional getRealPath() { return llvm::None; }
+  /// Get the name of the file
+  virtual llvm::ErrorOr getName() {
+if (auto Status = status())
+  return Status->getName().str();
+else
+  return Status.getError();
+  }
 
   /// Get the contents of the file as a \p MemoryBuffer.
   virtual llvm::ErrorOr>

Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=337850=337849=337850=diff
==
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Tue Jul 24 13:28:07 2018
@@ -316,7 +316,7 @@ const FileEntry *FileManager::getFile(St
   UFE.File = std::move(F);
   UFE.IsValid = true;
   if (UFE.File)
-if (auto RealPathName = UFE.File->getRealPath())
+if (auto RealPathName = UFE.File->getName())
   UFE.RealPathName = *RealPathName;
   return 
 }

Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=337850=337849=337850=diff
==
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Tue Jul 24 13:28:07 2018
@@ -73,14 +73,16 @@ Status::Status(StringRef Name, UniqueID
 : Name(Name), UID(UID), MTime(MTime), User(User), Group(Group), Size(Size),
   Type(Type), Perms(Perms) {}
 
-Status::Status(const file_status , StringRef NewName)
-: Status(NewName, In.getUniqueID(), In.getLastModificationTime(),
- In.getUser(), In.getGroup(), In.getSize(), In.type(),
- In.permissions()) {}
-
-Status Status::copyWithNewName(StringRef NewName) {
-  return Status(NewName, getUniqueID(), getLastModificationTime(), getUser(),
-getGroup(), getSize(), getType(), getPermissions());
+Status Status::copyWithNewName(const Status , StringRef NewName) {
+  return Status(NewName, In.getUniqueID(), In.getLastModificationTime(),
+In.getUser(), In.getGroup(), In.getSize(), In.getType(),
+In.getPermissions());
+}
+
+Status Status::copyWithNewName(const file_status , StringRef NewName) {
+  return Status(NewName, In.getUniqueID(), In.getLastModificationTime(),
+In.getUser(), In.getGroup(), In.getSize(), In.type(),
+

[PATCH] D49754: Add -m(no-)spe, and e500 CPU definitions and support to clang

2018-07-24 Thread Justin Hibbits via Phabricator via cfe-commits
jhibbits created this revision.
Herald added subscribers: cfe-commits, kbarton, nemanjai.

r337347 added support for the Signal Processing Engine (SPE) to LLVM.
This follows that up with the clang side.


Repository:
  rC Clang

https://reviews.llvm.org/D49754

Files:
  include/clang/Driver/Options.td
  lib/Basic/Targets/PPC.cpp
  lib/Basic/Targets/PPC.h
  test/Driver/ppc-features.cpp
  test/Misc/target-invalid-cpu-note.c
  test/Preprocessor/init.c

Index: test/Preprocessor/init.c
===
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -6980,6 +6980,10 @@
 //
 // PPC32-LINUX-NOT: _CALL_LINUX
 //
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-unknown-linux-gnu -target-feature +spe < /dev/null | FileCheck -match-full-lines -check-prefix PPC32-SPE %s
+//
+// PPC32-SPE:#define __SPE__ 1
+//
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-apple-darwin8 < /dev/null | FileCheck -match-full-lines -check-prefix PPC-DARWIN %s
 //
 // PPC-DARWIN:#define _ARCH_PPC 1
Index: test/Misc/target-invalid-cpu-note.c
===
--- test/Misc/target-invalid-cpu-note.c
+++ test/Misc/target-invalid-cpu-note.c
@@ -79,7 +79,7 @@
 // PPC: error: unknown target CPU 'not-a-cpu'
 // PPC: note: valid target CPU values are: generic, 440, 450, 601, 602, 603,
 // PPC-SAME: 603e, 603ev, 604, 604e, 620, 630, g3, 7400, g4, 7450, g4+, 750,
-// PPC-SAME: 970, g5, a2, a2q, e500mc, e5500, power3, pwr3, power4, pwr4,
+// PPC-SAME: 970, g5, a2, a2q, e500, e500mc, e5500, power3, pwr3, power4, pwr4,
 // PPC-SAME: power5, pwr5, power5x, pwr5x, power6, pwr6, power6x, pwr6x, power7,
 // PPC-SAME: pwr7, power8, pwr8, power9, pwr9, powerpc, ppc, powerpc64, ppc64,
 // PPC-SAME: powerpc64le, ppc64le
Index: test/Driver/ppc-features.cpp
===
--- test/Driver/ppc-features.cpp
+++ test/Driver/ppc-features.cpp
@@ -168,6 +168,9 @@
 // RUN: %clang -target powerpc64-unknown-linux-gnu %s -mno-invariant-function-descriptors -minvariant-function-descriptors -### -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-INVFUNCDESC %s
 // CHECK-INVFUNCDESC: "-target-feature" "+invariant-function-descriptors"
 
+// RUN: %clang -target powerpc-unknown-linux-gnu %s -mno-spe -mspe -### -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-SPE %s
+// CHECK-SPE: "-target-feature" "+spe"
+
 // Assembler features
 // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o -no-integrated-as 2>&1 | FileCheck -check-prefix=CHECK_BE_AS_ARGS %s
 // CHECK_BE_AS_ARGS: "-mppc64"
Index: lib/Basic/Targets/PPC.h
===
--- lib/Basic/Targets/PPC.h
+++ lib/Basic/Targets/PPC.h
@@ -45,7 +45,8 @@
 ArchDefinePwr8 = 1 << 12,
 ArchDefinePwr9 = 1 << 13,
 ArchDefineA2 = 1 << 14,
-ArchDefineA2q = 1 << 15
+ArchDefineA2q = 1 << 15,
+ArchDefine500v2 = 1 << 16
   } ArchDefineTypes;
 
 
@@ -66,6 +67,7 @@
   bool HasBPERMD = false;
   bool HasExtDiv = false;
   bool HasP9Vector = false;
+  bool HasSPE = false;
 
 protected:
   std::string ABI;
@@ -145,6 +147,8 @@
 ArchDefinePwr6x | ArchDefinePwr6 | ArchDefinePwr5x |
 ArchDefinePwr5 | ArchDefinePwr4 | ArchDefinePpcgr |
 ArchDefinePpcsq)
+  .Cases("e500", "e500v2",
+ArchDefineName | ArchDefine500v2)
   .Default(ArchDefineNone);
 }
 return CPUKnown;
Index: lib/Basic/Targets/PPC.cpp
===
--- lib/Basic/Targets/PPC.cpp
+++ lib/Basic/Targets/PPC.cpp
@@ -54,6 +54,8 @@
   HasFloat128 = true;
 } else if (Feature == "+power9-vector") {
   HasP9Vector = true;
+} else if (Feature == "+spe") {
+  HasSPE = true;
 }
 // TODO: Finish this list and add an assert that we've handled them
 // all.
@@ -161,6 +163,8 @@
 Builder.defineMacro("__VEC__", "10206");
 Builder.defineMacro("__ALTIVEC__");
   }
+  if (HasSPE)
+Builder.defineMacro("__SPE__");
   if (HasVSX)
 Builder.defineMacro("__VSX__");
   if (HasP8Vector)
@@ -334,6 +338,7 @@
   .Case("extdiv", HasExtDiv)
   .Case("float128", HasFloat128)
   .Case("power9-vector", HasP9Vector)
+  .Case("spe", HasSPE)
   .Default(false);
 }
 
@@ -413,16 +418,16 @@
 }
 
 static constexpr llvm::StringLiteral ValidCPUNames[] = {
-{"generic"}, {"440"}, {"450"}, {"601"},{"602"},
-{"603"}, {"603e"},{"603ev"},   {"604"},{"604e"},
-{"620"}, {"630"}, {"g3"},  {"7400"},   {"g4"},
-{"7450"},{"g4+"}, {"750"}, {"970"},{"g5"},
-{"a2"},  {"a2q"}, {"e500mc"},  {"e5500"},  {"power3"},
-{"pwr3"},{"power4"},  {"pwr4"},{"power5"}, {"pwr5"},
-{"power5x"}, {"pwr5x"},   {"power6"},  {"pwr6"},   {"power6x"},

[PATCH] D49724: [VFS] Cleanups to VFS interfaces.

2018-07-24 Thread Jordan Rupprecht via Phabricator via cfe-commits
rupprecht added a comment.

Looks like this caused some test failures 
(http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick/builds/14441/steps/ninja%20check%201),
 e.g.:

  [ RUN  ] GoToInclude.All
  
/home/buildslave/buildslave/clang-cmake-aarch64-quick/llvm/tools/clang/tools/extra/unittests/clangd/XRefsTests.cpp:953:
 Failure
  Value of: *Locations
  Expected: has 1 element that is equal to 0:0-0:0@file:///clangd-test/foo.h
Actual: {}

I'm not familiar with this patch, but reverting it locally seems to get tests 
passing again, so I'd like to revert this change temporarily.


Repository:
  rL LLVM

https://reviews.llvm.org/D49724



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


[PATCH] D49752: [CMake] Don't install c++abi headers in standalone libc++ build

2018-07-24 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

This was pointed out by @mclow.lists on IRC in our discussion related to 
https://reviews.llvm.org/D49711, I believe this change should resolve that 
issue.


Repository:
  rCXX libc++

https://reviews.llvm.org/D49752



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


[PATCH] D49752: [CMake] Don't install c++abi headers in standalone libc++ build

2018-07-24 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
phosek added reviewers: mclow.lists, EricWF, ldionne.
Herald added subscribers: cfe-commits, christof, mgorny.

This is a refinement on r337833. Previously we were installing two
copies of c++abi headers in libc++ build directory, one in
include/c++build and another one in include/c++/v1. However, the
second copy is unnecessary when building libc++ standalone.


Repository:
  rCXX libc++

https://reviews.llvm.org/D49752

Files:
  libcxx/CMakeLists.txt
  libcxx/cmake/Modules/HandleLibCXXABI.cmake
  libcxx/include/CMakeLists.txt


Index: libcxx/include/CMakeLists.txt
===
--- libcxx/include/CMakeLists.txt
+++ libcxx/include/CMakeLists.txt
@@ -205,7 +205,7 @@
 )
 endif()
 
-if(NOT LIBCXX_USING_INSTALLED_LLVM AND LLVM_BINARY_DIR)
+if(NOT LIBCXX_USING_INSTALLED_LLVM AND LIBCXX_HEADER_DIR)
   set(output_dir ${LIBCXX_HEADER_DIR}/include/c++/v1)
 
   set(out_files)
Index: libcxx/cmake/Modules/HandleLibCXXABI.cmake
===
--- libcxx/cmake/Modules/HandleLibCXXABI.cmake
+++ libcxx/cmake/Modules/HandleLibCXXABI.cmake
@@ -48,7 +48,7 @@
 COMMENT "Copying C++ ABI header ${fpath}...")
 list(APPEND abilib_headers "${dst}")
 
-if (NOT LIBCXX_USING_INSTALLED_LLVM)
+if (NOT LIBCXX_USING_INSTALLED_LLVM AND LIBCXX_HEADER_DIR)
   set(dst "${LIBCXX_HEADER_DIR}/include/c++/v1/${dstdir}/${fpath}")
   add_custom_command(OUTPUT ${dst}
   DEPENDS ${src}
Index: libcxx/CMakeLists.txt
===
--- libcxx/CMakeLists.txt
+++ libcxx/CMakeLists.txt
@@ -401,7 +401,6 @@
   set(LIBCXX_HEADER_DIR  ${LLVM_BINARY_DIR})
 else()
   set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
-  set(LIBCXX_HEADER_DIR  ${CMAKE_BINARY_DIR})
 endif()
 
 file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}")


Index: libcxx/include/CMakeLists.txt
===
--- libcxx/include/CMakeLists.txt
+++ libcxx/include/CMakeLists.txt
@@ -205,7 +205,7 @@
 )
 endif()
 
-if(NOT LIBCXX_USING_INSTALLED_LLVM AND LLVM_BINARY_DIR)
+if(NOT LIBCXX_USING_INSTALLED_LLVM AND LIBCXX_HEADER_DIR)
   set(output_dir ${LIBCXX_HEADER_DIR}/include/c++/v1)
 
   set(out_files)
Index: libcxx/cmake/Modules/HandleLibCXXABI.cmake
===
--- libcxx/cmake/Modules/HandleLibCXXABI.cmake
+++ libcxx/cmake/Modules/HandleLibCXXABI.cmake
@@ -48,7 +48,7 @@
 COMMENT "Copying C++ ABI header ${fpath}...")
 list(APPEND abilib_headers "${dst}")
 
-if (NOT LIBCXX_USING_INSTALLED_LLVM)
+if (NOT LIBCXX_USING_INSTALLED_LLVM AND LIBCXX_HEADER_DIR)
   set(dst "${LIBCXX_HEADER_DIR}/include/c++/v1/${dstdir}/${fpath}")
   add_custom_command(OUTPUT ${dst}
   DEPENDS ${src}
Index: libcxx/CMakeLists.txt
===
--- libcxx/CMakeLists.txt
+++ libcxx/CMakeLists.txt
@@ -401,7 +401,6 @@
   set(LIBCXX_HEADER_DIR  ${LLVM_BINARY_DIR})
 else()
   set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
-  set(LIBCXX_HEADER_DIR  ${CMAKE_BINARY_DIR})
 endif()
 
 file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49749: [analyzer] Admit that we can't simplify the newly produced mixed Loc/NonLoc expressions.

2018-07-24 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov requested changes to this revision.
george.karpenkov added inline comments.
This revision now requires changes to proceed.



Comment at: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:1300
+  Loc::isLocType(S->getRHS()->getType())) {
+SVal V = SVB.makeSymbolVal(S);
+Cached[S] = V;

could we eliminate the code duplication with lines 1308-1310?


Repository:
  rC Clang

https://reviews.llvm.org/D49749



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


[PATCH] D48862: [OpenEmbedded] Fix lib paths for OpenEmbedded targets

2018-07-24 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang updated this revision to Diff 157106.
mgrang added a comment.

Thanks @rsmith. I have addressed your comments.


https://reviews.llvm.org/D48862

Files:
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/ToolChains/Linux.cpp
  
test/Driver/Inputs/openembedded_aarch64_linux_tree/usr/include/c++/6.3.0/backward/.keep
  
test/Driver/Inputs/openembedded_aarch64_linux_tree/usr/lib64/aarch64-oe-linux/6.3.0/crtbegin.o
  
test/Driver/Inputs/openembedded_aarch64_linux_tree/usr/lib64/aarch64-oe-linux/6.3.0/crtend.o
  test/Driver/Inputs/openembedded_aarch64_linux_tree/usr/lib64/crt1.o
  test/Driver/Inputs/openembedded_aarch64_linux_tree/usr/lib64/crti.o
  test/Driver/Inputs/openembedded_aarch64_linux_tree/usr/lib64/crtn.o
  
test/Driver/Inputs/openembedded_arm_linux_tree/usr/include/c++/6.3.0/backward/.keep
  
test/Driver/Inputs/openembedded_arm_linux_tree/usr/lib/arm-oe-linux-gnueabi/6.3.0/crtbegin.o
  
test/Driver/Inputs/openembedded_arm_linux_tree/usr/lib/arm-oe-linux-gnueabi/6.3.0/crtend.o
  test/Driver/Inputs/openembedded_arm_linux_tree/usr/lib/crt1.o
  test/Driver/Inputs/openembedded_arm_linux_tree/usr/lib/crti.o
  test/Driver/Inputs/openembedded_arm_linux_tree/usr/lib/crtn.o
  test/Driver/linux-header-search.cpp
  test/Driver/linux-ld.c

Index: test/Driver/linux-ld.c
===
--- test/Driver/linux-ld.c
+++ test/Driver/linux-ld.c
@@ -1792,3 +1792,38 @@
 // CHECK-LD-RHLE7-DTS: Selected GCC installation: [[GCC_INSTALL:[[SYSROOT]]/lib/gcc/x86_64-redhat-linux/7]]
 // CHECK-LD-RHEL7-DTS-NOT: /usr/bin/ld
 // CHECK-LD-RHLE7-DTS: [[GCC_INSTALL]/../../../bin/ld
+
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=arm-oe-linux-gnueabi \
+// RUN: --sysroot=%S/Inputs/openembedded_arm_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-OE-ARM %s
+
+// CHECK-OE-ARM: "-cc1" "-triple" "armv4t-oe-linux-gnueabi"
+// CHECK-OE-ARM: ld{{.*}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-OE-ARM: "-m" "armelf_linux_eabi" "-dynamic-linker"
+// CHECK-OE-ARM: "[[SYSROOT]]/usr/lib/arm-oe-linux-gnueabi/6.3.0/../../../lib/crt1.o"
+// CHECK-OE-ARM: "[[SYSROOT]]/usr/lib/arm-oe-linux-gnueabi/6.3.0/../../../lib/crti.o"
+// CHECK-OE-ARM: "[[SYSROOT]]/usr/lib/arm-oe-linux-gnueabi/6.3.0/crtbegin.o"
+// CHECK-OE-ARM: "-L[[SYSROOT]]/usr/lib/arm-oe-linux-gnueabi/6.3.0"
+// CHECK-OE-ARM: "-L[[SYSROOT]]/usr/lib/arm-oe-linux-gnueabi"
+// CHECK-OE-ARM: "-L[[SYSROOT]]/usr/lib"
+// CHECK-OE-ARM: "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed"
+// CHECK-OE-ARM: "[[SYSROOT]]/usr/lib/arm-oe-linux-gnueabi/6.3.0/crtend.o"
+// CHECK-OE-ARM: "[[SYSROOT]]/usr/lib/arm-oe-linux-gnueabi/6.3.0/../../../lib/crtn.o"
+
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=aarch64-oe-linux \
+// RUN: --sysroot=%S/Inputs/openembedded_aarch64_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-OE-AARCH64 %s
+
+// CHECK-OE-AARCH64: "-cc1" "-triple" "aarch64-oe-linux"
+// CHECK-OE-AARCH64: ld{{.*}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-OE-AARCH64: "-m" "aarch64linux" "-dynamic-linker"
+// CHECK-OE-AARCH64: "[[SYSROOT]]/usr/lib64/aarch64-oe-linux/6.3.0/../../../lib64/crt1.o"
+// CHECK-OE-AARCH64: "[[SYSROOT]]/usr/lib64/aarch64-oe-linux/6.3.0/../../../lib64/crti.o"
+// CHECK-OE-AARCH64: "[[SYSROOT]]/usr/lib64/aarch64-oe-linux/6.3.0/crtbegin.o"
+// CHECK-OE-AARCH64: "-L[[SYSROOT]]/usr/lib64/aarch64-oe-linux/6.3.0"
+// CHECK-OE-AARCH64: "-L[[SYSROOT]]/usr/lib64"
+// CHECK-OE-AARCH64: "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed"
+// CHECK-OE-AARCH64: "[[SYSROOT]]/usr/lib64/aarch64-oe-linux/6.3.0/crtend.o"
+// CHECK-OE-AARCH64: "[[SYSROOT]]/usr/lib64/aarch64-oe-linux/6.3.0/../../../lib64/crtn.o"
Index: test/Driver/linux-header-search.cpp
===
--- test/Driver/linux-header-search.cpp
+++ test/Driver/linux-header-search.cpp
@@ -493,3 +493,25 @@
 // CHECK-DEBIAN-SPARC64: "-internal-externc-isystem" "[[SYSROOT]]/usr/include/sparc64-linux-gnu"
 // CHECK-DEBIAN-SPARC64: "-internal-externc-isystem" "[[SYSROOT]]/include"
 // CHECK-DEBIAN-SPARC64: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
+
+// Check header search on ARM OpenEmbedded.
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -target arm-oe-linux-gnueabi \
+// RUN: --sysroot=%S/Inputs/openembedded_arm_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-OE-ARM %s
+
+// CHECK-OE-ARM: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
+// CHECK-OE-ARM: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-OE-ARM: "-internal-isystem" "[[SYSROOT]]/usr/lib/arm-oe-linux-gnueabi/6.3.0/../../../include/c++/6.3.0"
+// CHECK-OE-ARM: "-internal-isystem" "[[SYSROOT]]/usr/lib/arm-oe-linux-gnueabi/6.3.0/../../../include/c++/6.3.0/backward"
+
+// Check header search on AArch64 OpenEmbedded.
+// RUN: %clang 

[PATCH] D49589: [UBSan] Strengthen pointer checks in 'new' expressions

2018-07-24 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added inline comments.



Comment at: lib/CodeGen/CodeGenFunction.h:380
+  /// True if sanitizer checks for current pointer value are generated.
+  bool PointerChecksAreEmitted = false;
+

rjmccall wrote:
> I don't think this is a good way of doing this.  Using global state makes 
> this unnecessarily difficult to reason about and can have unintended effects. 
>  For example, you are unintentionally suppressing any checks that would be 
> done as part of e.g. evaluating default arguments to the default constructor.
> 
> You should pass a parameter down that says whether checks are necessary.  You 
> can also use that parameter to e.g. suppress checks when constructing local 
> variables and temporaries, although you may already have an alternative 
> mechanism for doing that.
Passing parameter that inctructs whether to generate checks or not hardly can 
be directly implemented. This information is used in `EmitCXXConstructorCall` 
and it is formed during processing of `new` expression. The distance between 
these points can be 10 call frames, in some of them (`StmtVisitor` interface of 
`AggExprEmitter`) we cannot change function parameters.
The case of `new` expression in default arguments indeed handled incorrectly, 
thank you for the catch.  The updated version must process this case correctly.


Repository:
  rC Clang

https://reviews.llvm.org/D49589



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


[PATCH] D48958: [clang][ubsan] Implicit Cast Sanitizer - integer truncation - clang part

2018-07-24 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In https://reviews.llvm.org/D48958#1173860, @vsk wrote:

> LGTM, although I think it'd be helpful to have another +1 just to be safe.


Thank you for the review!
It would indeed be great if someone else could take a look, especially since we 
are **so** close to the branching point.

In https://reviews.llvm.org/D48958#1173860, @vsk wrote:

> ...




In https://reviews.llvm.org/D48958#1173860, @vsk wrote:

> These four at least don't look like false positives:
>
> - Maybe we should consider special-casing assignments of "-1" to unsigned 
> values? This seems somewhat idiomatic.


I **personally** would use `~0U` there.
One more datapoint: the `implicit-sign-change` will/should still complain about 
that case.
So **personally** i'd like to keep it.

> - At least a few of these are due to not being explicit about dropping the 
> high bits of hash_combine()'s result. Given that this check is opt-in, that 
> that seems like a legitimate diagnostic (lost entropy).
> - The TargetLoweringBase.cpp diagnostic looks a bit scary.




Repository:
  rC Clang

https://reviews.llvm.org/D48958



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


[PATCH] D49749: [analyzer] Admit that we can't simplify the newly produced mixed Loc/NonLoc expressions.

2018-07-24 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet, 
rnkovacs, mikhail.ramalho.
Herald added subscribers: cfe-commits, baloghadamsoftware.

Add one more defensive check to prevent crashes on trying to simplify a 
`SymSymExpr` with different `Loc`-ness of operands. This fix is similar to 
https://reviews.llvm.org/D49703 and addresses a regression caused by 
https://reviews.llvm.org/D48650.

When an operation between a `nonloc::LocAsInteger` and a non-pointer symbol is 
performed, the `LocAsInteger`-specific part of information is lost. When the 
non-pointer symbol is collapsing into a constant, we cannot easily re-evaluate 
the result, because we need to recover the missing g`LocAsInteger`-specific 
information (eg., integer type, or the very fact that this pointer was at some 
point converted to an integer).


Repository:
  rC Clang

https://reviews.llvm.org/D49749

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


Index: test/Analysis/casts.c
===
--- test/Analysis/casts.c
+++ test/Analysis/casts.c
@@ -175,3 +175,10 @@
 void testLocNonLocSymbolAssume(int a, int *b) {
   if ((int)b < a) {}
 }
+
+void testLocNonLocSymbolRemainder(int a, int *b) {
+  int c = ((int)b) % a;
+  if (a == 1) {
+c += 1;
+  }
+}
Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -1291,6 +1291,17 @@
   if (I != Cached.end())
 return I->second;
 
+  // For now don't try to simplify mixed Loc/NonLoc expressions
+  // because they often appear from LocAsInteger operations
+  // and we don't know how to combine a LocAsInteger
+  // with a concrete value.
+  if (Loc::isLocType(S->getLHS()->getType()) !=
+  Loc::isLocType(S->getRHS()->getType())) {
+SVal V = SVB.makeSymbolVal(S);
+Cached[S] = V;
+return V;
+  }
+
   SVal LHS = Visit(S->getLHS());
   SVal RHS = Visit(S->getRHS());
   if (isUnchanged(S->getLHS(), LHS) && isUnchanged(S->getRHS(), RHS)) {


Index: test/Analysis/casts.c
===
--- test/Analysis/casts.c
+++ test/Analysis/casts.c
@@ -175,3 +175,10 @@
 void testLocNonLocSymbolAssume(int a, int *b) {
   if ((int)b < a) {}
 }
+
+void testLocNonLocSymbolRemainder(int a, int *b) {
+  int c = ((int)b) % a;
+  if (a == 1) {
+c += 1;
+  }
+}
Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -1291,6 +1291,17 @@
   if (I != Cached.end())
 return I->second;
 
+  // For now don't try to simplify mixed Loc/NonLoc expressions
+  // because they often appear from LocAsInteger operations
+  // and we don't know how to combine a LocAsInteger
+  // with a concrete value.
+  if (Loc::isLocType(S->getLHS()->getType()) !=
+  Loc::isLocType(S->getRHS()->getType())) {
+SVal V = SVB.makeSymbolVal(S);
+Cached[S] = V;
+return V;
+  }
+
   SVal LHS = Visit(S->getLHS());
   SVal RHS = Visit(S->getRHS());
   if (isUnchanged(S->getLHS(), LHS) && isUnchanged(S->getRHS(), RHS)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49589: [UBSan] Strengthen pointer checks in 'new' expressions

2018-07-24 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 157102.
sepavloff added a comment.

Updated patch

- Modified check generation. Now for each 'new' expression compiler tries to

generate the checks. It solves problem of 'nested' new expressions, which
appear when 'new' is used in default arguments.

- Field and RAII class names are made more specific.
- Added new tests including that with inplace new operator.


Repository:
  rC Clang

https://reviews.llvm.org/D49589

Files:
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CGExprCXX.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGenCXX/ubsan-new-checks.cpp

Index: test/CodeGenCXX/ubsan-new-checks.cpp
===
--- /dev/null
+++ test/CodeGenCXX/ubsan-new-checks.cpp
@@ -0,0 +1,114 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -S -emit-llvm -fsanitize=alignment %s -o - | FileCheck %s
+
+struct alignas(32) S1 {
+  int x;
+  S1();
+};
+
+struct alignas(32) S2 {
+  int x;
+};
+
+struct alignas(32) S3 {
+  int x;
+  S3(int *p = new int[4]);
+};
+
+typedef __attribute__((ext_vector_type(2), aligned(32))) float float32x2_t;
+
+
+void *operator new (unsigned long, void *p) { return p; }
+void *operator new[] (unsigned long, void *p) { return p; }
+
+S1 *func_01() {
+  // CHECK-LABEL: define {{.*}} @_Z7func_01v
+  // CHECK:   and i64 %{{.*}}, 31, !nosanitize
+  // CHECK:   icmp eq i64 %{{.*}}, 0, !nosanitize
+  // CHECK:   call void @_ZN2S1C1Ev(
+  // CHECK-NOT:   and i64 %{{.*}}, 31, !nosanitize
+  // CHECK-NOT:   icmp eq i64 %{{.*}}, 0, !nosanitize
+  return new S1[20];
+}
+
+S2 *func_02() {
+  // CHECK-LABEL: define {{.*}} @_Z7func_02v
+  // CHECK:   and i64 %{{.*}}, 31, !nosanitize
+  // CHECK:   icmp eq i64 %{{.*}}, 0, !nosanitize
+  return new S2;
+}
+
+S2 *func_03() {
+  // CHECK-LABEL: define {{.*}} @_Z7func_03v
+  // CHECK:   and i64 %{{.*}}, 31, !nosanitize
+  // CHECK:   icmp eq i64 %{{.*}}, 0, !nosanitize
+  // CHECK-NOT:   and i64 %{{.*}}, 31, !nosanitize
+  // CHECK-NOT:   icmp eq i64 %{{.*}}, 0, !nosanitize
+  return new S2[20];
+}
+
+float32x2_t *func_04() {
+  // CHECK-LABEL: define {{.*}} @_Z7func_04v
+  // CHECK:   and i64 %{{.*}}, 31, !nosanitize
+  // CHECK:   icmp eq i64 %{{.*}}, 0, !nosanitize
+  return new float32x2_t;
+}
+
+float32x2_t *func_05() {
+  // CHECK-LABEL: define {{.*}} @_Z7func_05v
+  // CHECK:   and i64 %{{.*}}, 31, !nosanitize
+  // CHECK:   icmp eq i64 %{{.*}}, 0, !nosanitize
+  // CHECK-NOT:   and i64 %{{.*}}, 31, !nosanitize
+  // CHECK-NOT:   icmp eq i64 %{{.*}}, 0, !nosanitize
+  return new float32x2_t[20];
+}
+
+S3 *func_07() {
+  // CHECK-LABEL: define {{.*}} @_Z7func_07v
+  // CHECK:   and i64 %{{.*}}, 31, !nosanitize
+  // CHECK:   icmp eq i64 %{{.*}}, 0, !nosanitize
+  // CHECK:   and i64 %{{.*}}, 3, !nosanitize
+  // CHECK:   icmp eq i64 %{{.*}}, 0, !nosanitize
+  return new S3;
+}
+
+S3 *func_08() {
+  // CHECK-LABEL: define {{.*}} @_Z7func_08v
+  // CHECK:   and i64 %{{.*}}, 31, !nosanitize
+  // CHECK:   icmp eq i64 %{{.*}}, 0, !nosanitize
+  // CHECK:   and i64 %{{.*}}, 3, !nosanitize
+  // CHECK:   icmp eq i64 %{{.*}}, 0, !nosanitize
+  return new S3[10];
+}
+
+
+S2 *func_10(void *p) {
+  // CHECK-LABEL: define {{.*}} @_Z7func_10Pv
+  // CHECK:   and i64 %{{.*}}, 31, !nosanitize
+  // CHECK:   icmp eq i64 %{{.*}}, 0, !nosanitize
+  return new(p) S2;
+}
+
+S2 *func_11(void *p) {
+  // CHECK-LABEL: define {{.*}} @_Z7func_11Pv
+  // CHECK:   and i64 %{{.*}}, 31, !nosanitize
+  // CHECK:   icmp eq i64 %{{.*}}, 0, !nosanitize
+  // CHECK-NOT:   and i64 %{{.*}}, 31, !nosanitize
+  // CHECK-NOT:   icmp eq i64 %{{.*}}, 0, !nosanitize
+  return new(p) S2[10];
+}
+
+float32x2_t *func_12() {
+  // CHECK-LABEL: define {{.*}} @_Z7func_12v
+  // CHECK:   and i64 %{{.*}}, 31, !nosanitize
+  // CHECK:   icmp eq i64 %{{.*}}, 0, !nosanitize
+  return new float32x2_t;
+}
+
+float32x2_t *func_13() {
+  // CHECK-LABEL: define {{.*}} @_Z7func_13v
+  // CHECK:   and i64 %{{.*}}, 31, !nosanitize
+  // CHECK:   icmp eq i64 %{{.*}}, 0, !nosanitize
+  // CHECK-NOT:   and i64 %{{.*}}, 31, !nosanitize
+  // CHECK-NOT:   icmp eq i64 %{{.*}}, 0, !nosanitize
+  return new float32x2_t[20];
+}
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -458,6 +458,23 @@
 ~SanitizerScope();
   };
 
+  /// True if sanitizer checks for the pointer returned by 'new' are generated.
+  bool NewPointerChecksAreEmitted = false;
+
+  /// RAII object to track generation of sanitizer checks for result of 'new'.
+  class NewPointerChecksRAII {
+CodeGenFunction *CGF;
+bool PrevValue;
+  public:
+NewPointerChecksRAII(CodeGenFunction *CGF)
+: CGF(CGF), PrevValue(CGF->NewPointerChecksAreEmitted) {
+  CGF->NewPointerChecksAreEmitted = true;
+}
+

[PATCH] D49715: [analyzer] CallEvent: Add partially working methods for obtaining the callee stack frame.

2018-07-24 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov requested changes to this revision.
george.karpenkov added a comment.
This revision now requires changes to proceed.

Minor nits mostly.




Comment at: include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h:411
+  /// for bad reasons, returning null, even in post-call of an inlined 
function.
+  AnalysisDeclContext *getCalleeAnalysisDeclContext() const;
+

Could we be more succinct here?
e.g. \return Best-effort getter for AnalysisDeclContext, returns null on 
failure.

Same for all the methods below.



Comment at: include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h:776
 
+public:
   /// If the given statement corresponds to an object under construction,

Could we group it with other public methods at the top?



Comment at: lib/StaticAnalyzer/Core/CallEvent.cpp:193
+  const Expr *E = getOriginExpr();
+  // We cannot lookup a CFG element without an origin-expression.
+  if (!E)

"we cannot have" comments seem redundant, it's usually implied by the code.
This one is up to you though.



Comment at: lib/StaticAnalyzer/Core/CallEvent.cpp:197
+
+  // Recover CFG block via reverse lookup. Maybe it should just be a part of 
the
+  // CallEvent object? That would have been convenient.

Can we remove "maybe" / "that would have been" comments?


Repository:
  rC Clang

https://reviews.llvm.org/D49715



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


[PATCH] D49718: [CodeGen][ObjC] Make block copy/dispose helper function exception-safe.

2018-07-24 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: lib/CodeGen/CGBlocks.cpp:1905
+case BlockCaptureEntityKind::None:
+  llvm_unreachable("unexpected BlockCaptureEntityKind");
 }

rjmccall wrote:
> These two switches differ only in (1) what kind of cleanup they push and (2) 
> a small optimization that can easily be conditionalized by the request to 
> push an EH-only cleanup.
Merged the two switch statements into helper function pushCaptureCleanup.


Repository:
  rC Clang

https://reviews.llvm.org/D49718



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


[PATCH] D49718: [CodeGen][ObjC] Make block copy/dispose helper function exception-safe.

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

Address review comments.

I think I should be able to merge pushBlockObjectRelease and enterByrefCleanup, 
but the BlockFieldFlags that are passed are different. We set 
BLOCK_FIELD_IS_WEAK in addition to BLOCK_FIELD_IS_BYREF when isObjCGCWeak() 
returns true and we are emitting the copy/dispose helper functions, but when 
enterByrefCleanup is called from EmitAutoVarCleanups, only BLOCK_FIELD_IS_BYREF 
is set.

In https://reviews.llvm.org/D49718#1173068, @rjmccall wrote:

> I don't think it makes any difference because we shouldn't be emitting 
> cleanup paths when exceptions are disabled.  I don't think there's an 
> intended difference in semantics between those two destructor-cleanup paths, 
> at least.


OK, I see.

If it doesn't make any difference, I think I can push NormalAndEHCleanup 
unconditionally when copying a BlockObject capture instead of pushing 
NormalCleanup when EH is disabled. I made that change in the updated patch.


Repository:
  rC Clang

https://reviews.llvm.org/D49718

Files:
  lib/CodeGen/CGBlocks.cpp
  test/CodeGenObjCXX/arc-blocks.mm

Index: test/CodeGenObjCXX/arc-blocks.mm
===
--- test/CodeGenObjCXX/arc-blocks.mm
+++ test/CodeGenObjCXX/arc-blocks.mm
@@ -1,6 +1,9 @@
-// RUN: %clang_cc1 -std=gnu++98 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-runtime-has-weak -fblocks -fobjc-arc -o - %s | FileCheck %s
+// RUN: %clang_cc1 -std=gnu++98 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-runtime-has-weak -fblocks -fobjc-arc -fexceptions -fobjc-arc-exceptions -o - %s | FileCheck -check-prefix CHECK %s
+// RUN: %clang_cc1 -std=gnu++98 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-runtime-has-weak -fblocks -fobjc-arc -fexceptions -fobjc-arc-exceptions -O1 -o - %s | FileCheck -check-prefix CHECK-O1 %s
 
 // CHECK: [[A:.*]] = type { i64, [10 x i8*] }
+// CHECK: %[[STRUCT_TEST1_S0:.*]] = type { i32 }
+// CHECK: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 }
 
 // CHECK: [[LAYOUT0:@.*]] = private unnamed_addr constant [3 x i8] c" 9\00"
 
@@ -47,3 +50,133 @@
   // CHECK-NEXT: call void @_ZN5test01AD1Ev([[A]]* [[T1]])
   // CHECK-NEXT: ret void
 }
+
+namespace test1 {
+
+// Check that copy/dispose helper functions are exception safe.
+
+// CHECK-LABEL: define internal void @__copy_helper_block_(
+// CHECK: %[[BLOCK_SOURCE:.*]] = bitcast i8* %{{.*}} to <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>*
+// CHECK: %[[BLOCK_DEST:.*]] = bitcast i8* %{{.*}} to <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>*
+
+// CHECK: %[[V4:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>* %[[BLOCK_SOURCE]], i32 0, i32 6
+// CHECK: %[[V5:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>* %[[BLOCK_DEST]], i32 0, i32 6
+// CHECK: %[[BLOCKCOPY_SRC:.*]] = load i8*, i8** %[[V4]], align 8
+// CHECK: %[[V6:.*]] = bitcast i8** %[[V5]] to i8*
+// CHECK: call void @_Block_object_assign(i8* %[[V6]], i8* %[[BLOCKCOPY_SRC]], i32 8)
+
+// CHECK: %[[V7:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>* %[[BLOCK_SOURCE]], i32 0, i32 7
+// CHECK: %[[V8:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>* %[[BLOCK_DEST]], i32 0, i32 7
+// CHECK: call void @objc_copyWeak(i8** %[[V8]], i8** %[[V7]])
+
+// CHECK: %[[V9:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>* %[[BLOCK_SOURCE]], i32 0, i32 5
+// CHECK: %[[V10:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>* %[[BLOCK_DEST]], i32 0, i32 5
+// CHECK: %[[BLOCKCOPY_SRC2:.*]] = load i8*, i8** %[[V9]], align 8
+// CHECK: 

[PATCH] D48958: [clang][ubsan] Implicit Cast Sanitizer - integer truncation - clang part

2018-07-24 Thread Vedant Kumar via Phabricator via cfe-commits
vsk accepted this revision.
vsk added a comment.
This revision is now accepted and ready to land.

LGTM, although I think it'd be helpful to have another +1 just to be safe.

I did two small experiments with this using a Stage1 Rel+Asserts compiler:

Stage2 Rel+Asserts build of llvm-tblgen:
ninja llvm-tblgen  384.27s user 14.98s system 1467% cpu 27.203 total

Stage2 Rel+Asserts build of llvm-tblgen with implicit-cast checking:
ninja llvm-tblgen  385.15s user 15.02s system 1472% cpu 27.170 total

With caveats about having a small sample size here and testing with an 
asserts-enabled stage1 build, I don't see any red flags about the compile-time 
overhead of the new check. I would have liked to measure the check against more 
code, but I couldn't complete a stage2 build due to a diagnostic which might 
plausibly point to a real issue in tblgen:

  
/Users/vsk/src/llvm.org-lldbsan/llvm/utils/TableGen/RegisterInfoEmitter.cpp:604:17:
 runtime error: implicit cast from type 'int' of value -1 (32-bit, signed) to 
type 'const unsigned short' changed the value to 65535 (16-bit, unsigned)

With -fno-sanitize-recover=all disabled, I found a few more reports:

  /Users/vsk/src/llvm.org-lldbsan/llvm/include/llvm/Object/Archive.h:278:38: 
runtime error: implicit cast from type 'int' of value -1 (32-bit, signed) to 
type 'uint16_t' (aka 'unsigned short') changed the value to 65535 (16-bit, 
unsigned)
  --> uint16_t FirstRegularStartOfFile = -1;
  
  /Users/vsk/src/llvm.org-lldbsan/llvm/lib/Analysis/MemorySSA.cpp:199:12: 
runtime error: implicit cast from type 'size_t' (aka 'unsigned long') of value 
4969132974595412838 (64-bit, unsigned) to type 'unsigned int' changed the value 
to 3765474150 (32-bit, unsigned)
  --> hash_combine() result casted to unsigned
  
  
/Users/vsk/src/llvm.org-lldbsan/llvm/lib/CodeGen/TargetLoweringBase.cpp:1212:30:
 runtime error: implicit cast from type 'unsigned int' of value 512 (32-bit, 
unsigned) to type 'unsigned char' changed the value to 0 (8-bit, unsigned)
  --> NumRegistersForVT[i] = getVectorTypeBreakdownMVT(...)
  
  
/Users/vsk/src/llvm.org-lldbsan/llvm/lib/Transforms/Scalar/EarlyCSE.cpp:136:12: 
runtime error: implicit cast from type 'size_t' (aka 'unsigned long') of value 
16583795711468875482 (64-bit, unsigned) to type 'unsigned int' changed the 
value to 3116347098 (32-bit, unsigned)
  --> hash_combine() result casted to unsigned
  ...

These four at least don't look like false positives:

- Maybe we should consider special-casing assignments of "-1" to unsigned 
values? This seems somewhat idiomatic.
- At least a few of these are due to not being explicit about dropping the high 
bits of hash_combine()'s result. Given that this check is opt-in, that that 
seems like a legitimate diagnostic (lost entropy).
- The TargetLoweringBase.cpp diagnostic looks a bit scary.




Comment at: lib/CodeGen/CGExprScalar.cpp:986
+  for (auto CastRef : llvm::reverse(CastExprStack)) {
+const CastExpr *Cast = &(CastRef.get());
+// Was there a previous cast?

nit, extra parens?


Repository:
  rC Clang

https://reviews.llvm.org/D48958



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


[PATCH] D45898: [SemaCXX] Mark destructor as referenced

2018-07-24 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

Does this check destructors of nested aggregate initializations in the case 
where brace elision occurs? I don't think just checking the top level of the 
SK_ListInitialization is enough. Perhaps it would make more sense to mark the 
dtors used from InitListChecker (in non-VerifyOnly mode).


Repository:
  rC Clang

https://reviews.llvm.org/D45898



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


[PATCH] D49745: Generate fundamental type info with weak linkage

2018-07-24 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc requested changes to this revision.
pcc added a comment.
This revision now requires changes to proceed.

As I mentioned in https://bugs.llvm.org/show_bug.cgi?id=38281 I don't see a 
good reason to do this. Also extern_weak is not an appropriate linkage for 
definitions, only declarations.


https://reviews.llvm.org/D49745



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


[PATCH] D49745: Generate fundamental type info with weak linkage

2018-07-24 Thread Tom Anderson via Phabricator via cfe-commits
thomasanderson created this revision.
thomasanderson added a reviewer: pcc.

https://reviews.llvm.org/D49745

Files:
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/rtti-fundamental.cpp
  test/CodeGenCXX/windows-itanium-type-info.cpp

Index: test/CodeGenCXX/windows-itanium-type-info.cpp
===
--- test/CodeGenCXX/windows-itanium-type-info.cpp
+++ test/CodeGenCXX/windows-itanium-type-info.cpp
@@ -24,8 +24,8 @@
   throw base();
 }
 
-// CHECK-DAG: @_ZTIi = dso_local dllexport constant
-// CHECK-DAG: @_ZTSi = dso_local dllexport constant
+// CHECK-DAG: @_ZTIi = extern_weak dso_local dllexport constant
+// CHECK-DAG: @_ZTSi = extern_weak dso_local dllexport constant
 
 // CHECK-DAG: @_ZTI7derived = dso_local dllexport constant
 // CHECK-DAG: @_ZTS7derived = dso_local dllexport constant
Index: test/CodeGenCXX/rtti-fundamental.cpp
===
--- test/CodeGenCXX/rtti-fundamental.cpp
+++ test/CodeGenCXX/rtti-fundamental.cpp
@@ -16,185 +16,185 @@
 }
 
 // void
-// CHECK: @_ZTIv = constant
-// CHECK-HIDDEN: @_ZTIv = hidden constant
-// CHECK: @_ZTIPv = constant
-// CHECK-HIDDEN: @_ZTIPv = hidden constant
-// CHECK: @_ZTIPKv = constant
-// CHECK-HIDDEN: @_ZTIPKv = hidden constant
+// CHECK: @_ZTIv = extern_weak constant
+// CHECK-HIDDEN: @_ZTIv = extern_weak hidden constant
+// CHECK: @_ZTIPv = extern_weak constant
+// CHECK-HIDDEN: @_ZTIPv = extern_weak hidden constant
+// CHECK: @_ZTIPKv = extern_weak constant
+// CHECK-HIDDEN: @_ZTIPKv = extern_weak hidden constant
 
 // std::nullptr_t
-// CHECK: @_ZTIDn = constant
-// CHECK-HIDDEN: @_ZTIDn = hidden constant
-// CHECK: @_ZTIPDn = constant
-// CHECK-HIDDEN: @_ZTIPDn = hidden constant
-// CHECK: @_ZTIPKDn = constant
-// CHECK-HIDDEN: @_ZTIPKDn = hidden constant
+// CHECK: @_ZTIDn = extern_weak constant
+// CHECK-HIDDEN: @_ZTIDn = extern_weak hidden constant
+// CHECK: @_ZTIPDn = extern_weak constant
+// CHECK-HIDDEN: @_ZTIPDn = extern_weak hidden constant
+// CHECK: @_ZTIPKDn = extern_weak constant
+// CHECK-HIDDEN: @_ZTIPKDn = extern_weak hidden constant
 
 // bool
-// CHECK: @_ZTIb = constant
-// CHECK-HIDDEN: @_ZTIb = hidden constant
-// CHECK: @_ZTIPb = constant
-// CHECK-HIDDEN: @_ZTIPb = hidden constant
-// CHECK: @_ZTIPKb = constant
-// CHECK-HIDDEN: @_ZTIPKb = hidden constant
+// CHECK: @_ZTIb = extern_weak constant
+// CHECK-HIDDEN: @_ZTIb = extern_weak hidden constant
+// CHECK: @_ZTIPb = extern_weak constant
+// CHECK-HIDDEN: @_ZTIPb = extern_weak hidden constant
+// CHECK: @_ZTIPKb = extern_weak constant
+// CHECK-HIDDEN: @_ZTIPKb = extern_weak hidden constant
 
 // wchar_t
-// CHECK: @_ZTIw = constant
-// CHECK-HIDDEN: @_ZTIw = hidden constant
-// CHECK: @_ZTIPw = constant
-// CHECK-HIDDEN: @_ZTIPw = hidden constant
-// CHECK: @_ZTIPKw = constant
-// CHECK-HIDDEN: @_ZTIPKw = hidden constant
+// CHECK: @_ZTIw = extern_weak constant
+// CHECK-HIDDEN: @_ZTIw = extern_weak hidden constant
+// CHECK: @_ZTIPw = extern_weak constant
+// CHECK-HIDDEN: @_ZTIPw = extern_weak hidden constant
+// CHECK: @_ZTIPKw = extern_weak constant
+// CHECK-HIDDEN: @_ZTIPKw = extern_weak hidden constant
 
 // char
-// CHECK: @_ZTIc = constant
-// CHECK-HIDDEN: @_ZTIc = hidden constant
-// CHECK: @_ZTIPc = constant
-// CHECK-HIDDEN: @_ZTIPc = hidden constant
-// CHECK: @_ZTIPKc = constant
-// CHECK-HIDDEN: @_ZTIPKc = hidden constant
+// CHECK: @_ZTIc = extern_weak constant
+// CHECK-HIDDEN: @_ZTIc = extern_weak hidden constant
+// CHECK: @_ZTIPc = extern_weak constant
+// CHECK-HIDDEN: @_ZTIPc = extern_weak hidden constant
+// CHECK: @_ZTIPKc = extern_weak constant
+// CHECK-HIDDEN: @_ZTIPKc = extern_weak hidden constant
 
 // unsigned char
-// CHECK: @_ZTIh = constant
-// CHECK-HIDDEN: @_ZTIh = hidden constant
-// CHECK: @_ZTIPh = constant
-// CHECK-HIDDEN: @_ZTIPh = hidden constant
-// CHECK: @_ZTIPKh = constant
-// CHECK-HIDDEN: @_ZTIPKh = hidden constant
+// CHECK: @_ZTIh = extern_weak constant
+// CHECK-HIDDEN: @_ZTIh = extern_weak hidden constant
+// CHECK: @_ZTIPh = extern_weak constant
+// CHECK-HIDDEN: @_ZTIPh = extern_weak hidden constant
+// CHECK: @_ZTIPKh = extern_weak constant
+// CHECK-HIDDEN: @_ZTIPKh = extern_weak hidden constant
 
 // signed char
-// CHECK: @_ZTIa = constant
-// CHECK-HIDDEN: @_ZTIa = hidden constant
-// CHECK: @_ZTIPa = constant
-// CHECK-HIDDEN: @_ZTIPa = hidden constant
-// CHECK: @_ZTIPKa = constant
-// CHECK-HIDDEN: @_ZTIPKa = hidden constant
+// CHECK: @_ZTIa = extern_weak constant
+// CHECK-HIDDEN: @_ZTIa = extern_weak hidden constant
+// CHECK: @_ZTIPa = extern_weak constant
+// CHECK-HIDDEN: @_ZTIPa = extern_weak hidden constant
+// CHECK: @_ZTIPKa = extern_weak constant
+// CHECK-HIDDEN: @_ZTIPKa = extern_weak hidden constant
 
 // short
-// CHECK: @_ZTIs = constant
-// CHECK-HIDDEN: @_ZTIs = hidden constant
-// CHECK: @_ZTIPs = constant
-// CHECK-HIDDEN: @_ZTIPs = hidden constant
-// CHECK: @_ZTIPKs = constant
-// 

[PATCH] D49734: [AST][4/4] Move the bit-fields from ObjCMethodDecl and ObjCContainerDecl into DeclContext

2018-07-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Same comment as the other 3.




Comment at: include/clang/AST/DeclObjC.h:190
+  /// InvalidObjCMethodFamily cast into an ObjCMethodFamily.
+  ObjCMethodFamily getFamilyImpl() const {
+return static_cast(ObjCMethodDeclBits.Family);

I'd again omit these.


Repository:
  rC Clang

https://reviews.llvm.org/D49734



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


[PATCH] D49733: [AST][3/4] Move the bit-fields from BlockDecl, LinkageSpecDecl and OMPDeclareReductionDecl into DeclContext

2018-07-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Another one in need of clang-format, but generally seems pretty mechanical.




Comment at: include/clang/AST/DeclCXX.h:2844
+
+  bool hasBracesImpl() const { return LinkageSpecDeclBits.HasBraces; }
+  void setBracesImpl(bool B = true) { LinkageSpecDeclBits.HasBraces = B; }

Again, I doubt the value here.


Repository:
  rC Clang

https://reviews.llvm.org/D49733



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


[PATCH] D49732: [AST][2/4] Move the bit-fields from FunctionDecl and CXXConstructorDecl into DeclContext

2018-07-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Anotherone in need of clang-format, otherwise seems alright to me.




Comment at: include/clang/AST/Decl.h:1809
+  // and setMultiVersion do not simply set/read the corresponding bit.
+  void setPureImpl(bool isPure) { FunctionDeclBits.IsPure = isPure; }
+  bool isDeletedImpl() const { return FunctionDeclBits.IsDeleted; }

I'm not sure I see the value of these.  FunctiondeclBits is littered around 
here a bit, so I don't think these additional ones have all that much value.  
At least the MultiVersion case actually doesn't do anything but call these.



Comment at: include/clang/AST/Decl.h:2033
+  }
+  void setHasImplicitReturnZero(bool IRZ) {
+FunctionDeclBits.HasImplicitReturnZero = IRZ;

Newline.


Repository:
  rC Clang

https://reviews.llvm.org/D49732



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


[PATCH] D49267: [clangd] Watch for changes in compile_commands.json

2018-07-24 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

> if/when we have a native implementation, supporting multiple mechanisms with 
> different layering requirements to get at most a 2x win in watcher resource 
> usage seems like a dubious way to spend our complexity budget.

I guess the only think that might force us to do this is the low system limit 
on the number of file watches. I do remember rumors that it can be a problem 
in, but I haven't really seen those on my own, so maybe I'm just pretending.
But I do agree that we shouldn't commit to have yet-another implementation in 
the long-term, unless we have good justification for it.

> it looks like the current design throws away all compilation databases (via 
> the global DB) when *any* compile_commands.json changes. I think it's 
> important that other stateful compilation databases aren't thrown away for 
> unrelated reasons. e.g. the Bazel DB takes nontrivial time to reinitialize.

Good point, we should fix this. Started a thread about it in the inline 
comments.




Comment at: clangd/ClangdLSPServer.cpp:430
 CDB.clear();
-
-reparseOpenedFiles();
+compileCommandsChangePost(CCChangeData);
   }

simark wrote:
> malaperle wrote:
> > ilya-biryukov wrote:
> > > Maybe keep the old logic of reparsing all open files? This would make the 
> > > change way simpler and I don't think we need this extra complexity in the 
> > > long run, when we have better integration with the build system.
> > > 
> > > ClangdServer will reuse the preamble if compile command didn't change 
> > > anyway, so reparse will be very fast and shouldn't be affected.
> > > If the compile command does change, we'll retrigger the full rebuild.
> > I think the change is not that complex but brings much added value. About 
> > the integration with the build system, there are many build systems out 
> > there so I don't think better integration will be useful in many scenarios 
> > (plain make, custom builds, etc). This solution is generic enough so that 
> > any build system that generates compile_commands.json will be supported in 
> > a pretty good way.
> @malaperle also suggested an alternative way of doing it.  Instead of saving 
> the the compile commands in a custom structure before clearing the cache, we 
> could save the compile flags in the `ParsedAST` object.  When some 
> compile_commands.json changes, we can compare the new compile flags with this 
> saved copy.  I think it would make the code a bit more straightforward.
> I think the change is not that complex but brings much added value.
> @malaperle also suggested an alternative way of doing it. Instead of saving 
> the the compile commands in a custom structure before clearing the cache, we 
> could save the compile flags in the ParsedAST object. When some 
> compile_commands.json changes, we can compare the new compile flags with this 
> saved copy. I think it would make the code a bit more straightforward.

The no-op rebuilds in case nothing changes is a good and long overdue 
optimization, and I agree that `ParsedAST` or `TUScheduler::update` is probably 
the right place to put it into. Any other benefits we get from snapshotting the 
compile commands here? Could we make this optimization in a separate change? It 
does not seem directly related to the file watching changes. Also happy to look 
at it, finding the right place to do it might involve digging through layers of 
classes that manage the AST.

> About the integration with the build system, there are many build systems out 
> there so I don't think better integration will be useful in many scenarios 
> (plain make, custom builds, etc). This solution is generic enough so that any 
> build system that generates compile_commands.json will be supported in a 
> pretty good way.
Just to clarify, the "better buildsystem integration" I refer to is not about 
enabling support for more build systems (though, that would be nice-to-have), 
it's about building abstractions that better support the current use-cases, 
i.e. making the connection between the CompiationDatabase and 
compiler_commands.json more explicit, allowing the track changes in the build 
system, etc. We think that file-watching will definitely be part of it, but we 
don't have full design yet.

In any case, we do think that there are improvements to be made both in 
compile_commands.json and in our internal Bazel integration.



Comment at: clangd/GlobalCompilationDatabase.cpp:71
+  std::lock_guard Lock(Mutex);
+  CompilationDatabases.clear();
+}

Could we only clear the databases for the folder under which the changed 
`compile_commands.json` lives?




Comment at: clangd/clients/clangd-vscode/src/extension.ts:35
 ['cpp', 'c', 'cc', 'cxx', 'c++', 'm', 'mm', 'h', 'hh', 'hpp', 'hxx', 
'inc'].join() + '}';
+const compileCommandsFilePattern: string = '**/compile_commands.json';
 const clientOptions: 

[PATCH] D49729: [AST][1/4] Move the bit-fields from TagDecl, EnumDecl and RecordDecl into DeclContext

2018-07-24 Thread Bruno Ricci via Phabricator via cfe-commits
bricci updated this revision to Diff 157063.
bricci added a comment.

- removed some unrelated change
- add a comment about why uint64_t instead of unsigned


Repository:
  rC Clang

https://reviews.llvm.org/D49729

Files:
  include/clang/AST/Decl.h
  include/clang/AST/DeclBase.h
  lib/AST/Decl.cpp
  lib/AST/DeclBase.cpp
  lib/AST/DeclCXX.cpp
  lib/AST/DeclTemplate.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp

Index: lib/Serialization/ASTWriterDecl.cpp
===
--- lib/Serialization/ASTWriterDecl.cpp
+++ lib/Serialization/ASTWriterDecl.cpp
@@ -1273,7 +1273,7 @@
 
   // Store (what we currently believe to be) the key function to avoid
   // deserializing every method so we can compute it.
-  if (D->IsCompleteDefinition)
+  if (D->isCompleteDefinition())
 Record.AddDeclRef(Context.getCurrentKeyFunction(D));
 
   Code = serialization::DECL_CXX_RECORD;
Index: lib/Serialization/ASTWriter.cpp
===
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -3960,7 +3960,8 @@
 
 bool ASTWriter::isLookupResultExternal(StoredDeclsList ,
DeclContext *DC) {
-  return Result.hasExternalDecls() && DC->NeedToReconcileExternalVisibleStorage;
+  return Result.hasExternalDecls() &&
+ DC->hasNeedToReconcileExternalVisibleStorage();
 }
 
 bool ASTWriter::isLookupResultEntirelyExternal(StoredDeclsList ,
@@ -3975,8 +3976,8 @@
 void
 ASTWriter::GenerateNameLookupTable(const DeclContext *ConstDC,
llvm::SmallVectorImpl ) {
-  assert(!ConstDC->HasLazyLocalLexicalLookups &&
- !ConstDC->HasLazyExternalLexicalLookups &&
+  assert(!ConstDC->hasLazyLocalLexicalLookups() &&
+ !ConstDC->hasLazyExternalLexicalLookups() &&
  "must call buildLookups first");
 
   // FIXME: We need to build the lookups table, which is logically const.
Index: lib/Serialization/ASTReaderDecl.cpp
===
--- lib/Serialization/ASTReaderDecl.cpp
+++ lib/Serialization/ASTReaderDecl.cpp
@@ -742,13 +742,13 @@
   ED->setPromotionType(Record.readType());
   ED->setNumPositiveBits(Record.readInt());
   ED->setNumNegativeBits(Record.readInt());
-  ED->IsScoped = Record.readInt();
-  ED->IsScopedUsingClassTag = Record.readInt();
-  ED->IsFixed = Record.readInt();
+  ED->setScoped(Record.readInt());
+  ED->setScopedUsingClassTag(Record.readInt());
+  ED->setFixed(Record.readInt());
 
   // If this is a definition subject to the ODR, and we already have a
   // definition, merge this one into it.
-  if (ED->IsCompleteDefinition &&
+  if (ED->isCompleteDefinition() &&
   Reader.getContext().getLangOpts().Modules &&
   Reader.getContext().getLangOpts().CPlusPlus) {
 EnumDecl * = Reader.EnumDefinitions[ED->getCanonicalDecl()];
@@ -764,7 +764,7 @@
 }
 if (OldDef) {
   Reader.MergedDeclContexts.insert(std::make_pair(ED, OldDef));
-  ED->IsCompleteDefinition = false;
+  ED->setCompleteDefinition(false);
   Reader.mergeDefinitionVisibility(OldDef, ED);
 } else {
   OldDef = ED;
@@ -1739,7 +1739,7 @@
 Reader.MergedDeclContexts.insert(std::make_pair(MergeDD.Definition,
 DD.Definition));
 Reader.PendingDefinitions.erase(MergeDD.Definition);
-MergeDD.Definition->IsCompleteDefinition = false;
+MergeDD.Definition->setCompleteDefinition(false);
 Reader.mergeDefinitionVisibility(DD.Definition, MergeDD.Definition);
 assert(Reader.Lookups.find(MergeDD.Definition) == Reader.Lookups.end() &&
"already loaded pending lookups for merged definition");
@@ -1879,7 +1879,7 @@
   }
 
   // Mark this declaration as being a definition.
-  D->IsCompleteDefinition = true;
+  D->setCompleteDefinition(true);
 
   // If this is not the first declaration or is an update record, we can have
   // other redeclarations already. Make a note that we need to propagate the
@@ -1941,7 +1941,7 @@
   // compute it.
   if (WasDefinition) {
 DeclID KeyFn = ReadDeclID();
-if (KeyFn && D->IsCompleteDefinition)
+if (KeyFn && D->isCompleteDefinition())
   // FIXME: This is wrong for the ARM ABI, where some other module may have
   // made this function no longer be a key function. We need an update
   // record or similar for that case.
@@ -3071,7 +3071,7 @@
 // we load the update record.
 if (!DD) {
   DD = new (Reader.getContext()) struct CXXRecordDecl::DefinitionData(RD);
-  RD->IsCompleteDefinition = true;
+  RD->setCompleteDefinition(true);
   RD->DefinitionData = DD;
   RD->getCanonicalDecl()->DefinitionData = DD;
 
Index: lib/AST/DeclTemplate.cpp
===
--- lib/AST/DeclTemplate.cpp
+++ 

  1   2   >