[PATCH] D39162: [test] Fix clang-test for FreeBSD and NetBSD

2017-10-23 Thread Tim Shen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316411: [test] Fix clang-test for FreeBSD and NetBSD 
(authored by timshen).

Changed prior to commit:
  https://reviews.llvm.org/D39162?vs=119803=119995#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39162

Files:
  cfe/trunk/test/Unit/lit.cfg.py


Index: cfe/trunk/test/Unit/lit.cfg.py
===
--- cfe/trunk/test/Unit/lit.cfg.py
+++ cfe/trunk/test/Unit/lit.cfg.py
@@ -35,17 +35,23 @@
 if symbolizer in os.environ:
 config.environment[symbolizer] = os.environ[symbolizer]
 
-shlibpath_var = ''
-if platform.system() == 'Linux':
-shlibpath_var = 'LD_LIBRARY_PATH'
-elif platform.system() == 'Darwin':
-shlibpath_var = 'DYLD_LIBRARY_PATH'
-elif platform.system() == 'Windows':
-shlibpath_var = 'PATH'
-
-# in stand-alone builds, shlibdir is clang's build tree
-# while llvm_libs_dir is installed LLVM (and possibly older clang)
-shlibpath = os.path.pathsep.join((config.shlibdir, config.llvm_libs_dir,
- config.environment.get(shlibpath_var,'')))
-
-config.environment[shlibpath_var] = shlibpath
+def find_shlibpath_var():
+if platform.system() in ['Linux', 'FreeBSD', 'NetBSD']:
+yield 'LD_LIBRARY_PATH'
+elif platform.system() == 'Darwin':
+yield 'DYLD_LIBRARY_PATH'
+elif platform.system() == 'Windows':
+yield 'PATH'
+
+for shlibpath_var in find_shlibpath_var():
+# in stand-alone builds, shlibdir is clang's build tree
+# while llvm_libs_dir is installed LLVM (and possibly older clang)
+shlibpath = os.path.pathsep.join(
+(config.shlibdir,
+ config.llvm_libs_dir,
+ config.environment.get(shlibpath_var, '')))
+config.environment[shlibpath_var] = shlibpath
+break
+else:
+lit_config.warning("unable to inject shared library path on '{}'"
+   .format(platform.system()))


Index: cfe/trunk/test/Unit/lit.cfg.py
===
--- cfe/trunk/test/Unit/lit.cfg.py
+++ cfe/trunk/test/Unit/lit.cfg.py
@@ -35,17 +35,23 @@
 if symbolizer in os.environ:
 config.environment[symbolizer] = os.environ[symbolizer]
 
-shlibpath_var = ''
-if platform.system() == 'Linux':
-shlibpath_var = 'LD_LIBRARY_PATH'
-elif platform.system() == 'Darwin':
-shlibpath_var = 'DYLD_LIBRARY_PATH'
-elif platform.system() == 'Windows':
-shlibpath_var = 'PATH'
-
-# in stand-alone builds, shlibdir is clang's build tree
-# while llvm_libs_dir is installed LLVM (and possibly older clang)
-shlibpath = os.path.pathsep.join((config.shlibdir, config.llvm_libs_dir,
- config.environment.get(shlibpath_var,'')))
-
-config.environment[shlibpath_var] = shlibpath
+def find_shlibpath_var():
+if platform.system() in ['Linux', 'FreeBSD', 'NetBSD']:
+yield 'LD_LIBRARY_PATH'
+elif platform.system() == 'Darwin':
+yield 'DYLD_LIBRARY_PATH'
+elif platform.system() == 'Windows':
+yield 'PATH'
+
+for shlibpath_var in find_shlibpath_var():
+# in stand-alone builds, shlibdir is clang's build tree
+# while llvm_libs_dir is installed LLVM (and possibly older clang)
+shlibpath = os.path.pathsep.join(
+(config.shlibdir,
+ config.llvm_libs_dir,
+ config.environment.get(shlibpath_var, '')))
+config.environment[shlibpath_var] = shlibpath
+break
+else:
+lit_config.warning("unable to inject shared library path on '{}'"
+   .format(platform.system()))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r316411 - [test] Fix clang-test for FreeBSD and NetBSD

2017-10-23 Thread Tim Shen via cfe-commits
Author: timshen
Date: Mon Oct 23 20:11:02 2017
New Revision: 316411

URL: http://llvm.org/viewvc/llvm-project?rev=316411=rev
Log:
[test] Fix clang-test for FreeBSD and NetBSD

Lit tries to inject the shared library paths, but no action is taken
when platform.system() is not recognized, results in an environment
variable with an empty name, which is illegal.

The patch fixes this mechanism for FreeBSD and NetBSD, and gives an
warning on other platforms, so that the latecomers don't have to spend
time on debugging lit.

Thanks Zhihao Yuan for the patch!

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

Modified:
cfe/trunk/test/Unit/lit.cfg.py

Modified: cfe/trunk/test/Unit/lit.cfg.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Unit/lit.cfg.py?rev=316411=316410=316411=diff
==
--- cfe/trunk/test/Unit/lit.cfg.py (original)
+++ cfe/trunk/test/Unit/lit.cfg.py Mon Oct 23 20:11:02 2017
@@ -35,17 +35,23 @@ for symbolizer in ['ASAN_SYMBOLIZER_PATH
 if symbolizer in os.environ:
 config.environment[symbolizer] = os.environ[symbolizer]
 
-shlibpath_var = ''
-if platform.system() == 'Linux':
-shlibpath_var = 'LD_LIBRARY_PATH'
-elif platform.system() == 'Darwin':
-shlibpath_var = 'DYLD_LIBRARY_PATH'
-elif platform.system() == 'Windows':
-shlibpath_var = 'PATH'
+def find_shlibpath_var():
+if platform.system() in ['Linux', 'FreeBSD', 'NetBSD']:
+yield 'LD_LIBRARY_PATH'
+elif platform.system() == 'Darwin':
+yield 'DYLD_LIBRARY_PATH'
+elif platform.system() == 'Windows':
+yield 'PATH'
 
-# in stand-alone builds, shlibdir is clang's build tree
-# while llvm_libs_dir is installed LLVM (and possibly older clang)
-shlibpath = os.path.pathsep.join((config.shlibdir, config.llvm_libs_dir,
- config.environment.get(shlibpath_var,'')))
-
-config.environment[shlibpath_var] = shlibpath
+for shlibpath_var in find_shlibpath_var():
+# in stand-alone builds, shlibdir is clang's build tree
+# while llvm_libs_dir is installed LLVM (and possibly older clang)
+shlibpath = os.path.pathsep.join(
+(config.shlibdir,
+ config.llvm_libs_dir,
+ config.environment.get(shlibpath_var, '')))
+config.environment[shlibpath_var] = shlibpath
+break
+else:
+lit_config.warning("unable to inject shared library path on '{}'"
+   .format(platform.system()))


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


[PATCH] D39220: [Analyzer] Store BodyFarm in std::unique_ptr

2017-10-23 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray added inline comments.



Comment at: lib/Analysis/AnalysisDeclContext.cpp:606
 
-AnalysisDeclContextManager::~AnalysisDeclContextManager() {
-  if (BdyFrm)
-delete BdyFrm;
-}
+AnalysisDeclContextManager::~AnalysisDeclContextManager() {}
 

Why having empty user-defined dtor?  This class has no vtbl; deleting the dtor 
declaration in `AnalysisDeclContext.h` should work.


https://reviews.llvm.org/D39220



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


[PATCH] D39127: Fix template parameter default args missed if redecled

2017-10-23 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

I think you forgot to svn add the test case


Repository:
  rL LLVM

https://reviews.llvm.org/D39127



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


[PATCH] D39035: Unnamed bitfields don't block constant evaluation of constexpr constructors

2017-10-23 Thread Jordan Rose via Phabricator via cfe-commits
jordan_rose closed this revision.
jordan_rose added a comment.

Landed in https://reviews.llvm.org/rL316408.


Repository:
  rL LLVM

https://reviews.llvm.org/D39035



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


r316408 - Unnamed bitfields don't block constant evaluation of constexpr ctors

2017-10-23 Thread Jordan Rose via cfe-commits
Author: jrose
Date: Mon Oct 23 19:17:07 2017
New Revision: 316408

URL: http://llvm.org/viewvc/llvm-project?rev=316408=rev
Log:
Unnamed bitfields don't block constant evaluation of constexpr ctors

C++14 [dcl.constexpr]p4 states that in the body of a constexpr
constructor,

> every non-variant non-static data member and base class sub-object
  shall be initialized

However, [class.bit]p2 notes that

> Unnamed bit-fields are not members and cannot be initialized.

Therefore, we should make sure to filter them out of the check that
all fields are initialized.

Fixing this makes the constant evaluator a bit smarter, and
specifically allows constexpr constructors to avoid tripping
-Wglobal-constructors when the type contains unnamed bitfields.

Reviewed at https://reviews.llvm.org/D39035.

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
cfe/trunk/test/SemaCXX/warn-global-constructors.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=316408=316407=316408=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Oct 23 19:17:07 2017
@@ -1818,6 +1818,9 @@ static bool CheckConstantExpression(Eval
   }
 }
 for (const auto *I : RD->fields()) {
+  if (I->isUnnamedBitfield())
+continue;
+
   if (!CheckConstantExpression(Info, DiagLoc, I->getType(),
Value.getStructField(I->getFieldIndex(
 return false;

Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=316408=316407=316408=diff
==
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Mon Oct 23 19:17:07 
2017
@@ -1931,6 +1931,22 @@ namespace Bitfields {
 };
 static_assert(X::f(3) == -1, "3 should truncate to -1");
   }
+
+  struct HasUnnamedBitfield {
+unsigned a;
+unsigned : 20;
+unsigned b;
+
+constexpr HasUnnamedBitfield() : a(), b() {}
+constexpr HasUnnamedBitfield(unsigned a, unsigned b) : a(a), b(b) {}
+  };
+
+  void testUnnamedBitfield() {
+const HasUnnamedBitfield zero{};
+int a = 1 / zero.b; // expected-warning {{division by zero is undefined}}
+const HasUnnamedBitfield oneZero{1, 0};
+int b = 1 / oneZero.b; // expected-warning {{division by zero is 
undefined}}
+  }
 }
 
 namespace ZeroSizeTypes {

Modified: cfe/trunk/test/SemaCXX/warn-global-constructors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-global-constructors.cpp?rev=316408=316407=316408=diff
==
--- cfe/trunk/test/SemaCXX/warn-global-constructors.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-global-constructors.cpp Mon Oct 23 19:17:07 2017
@@ -126,3 +126,22 @@ namespace pr20420 {
 void *array_storage[1];
 const int _reference = *(int *)array_storage;
 }
+
+namespace bitfields {
+  struct HasUnnamedBitfield {
+unsigned a;
+unsigned : 20;
+unsigned b;
+
+constexpr HasUnnamedBitfield() : a(), b() {}
+constexpr HasUnnamedBitfield(unsigned a, unsigned b) : a(a), b(b) {}
+explicit HasUnnamedBitfield(unsigned a) {}
+  };
+
+  const HasUnnamedBitfield zeroConst{};
+  HasUnnamedBitfield zeroMutable{};
+  const HasUnnamedBitfield explicitConst{1, 2};
+  HasUnnamedBitfield explicitMutable{1, 2};
+  const HasUnnamedBitfield nonConstexprConst{1}; // expected-warning {{global 
constructor}}
+  HasUnnamedBitfield nonConstexprMutable{1}; // expected-warning {{global 
constructor}}
+}


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


[PATCH] D39221: [libcxx] [test] Alignment must be > __STDCPP_DEFAULT_NEW_ALIGNMENT__ to call aligned new

2017-10-23 Thread Casey Carter via Phabricator via cfe-commits
CaseyCarter created this revision.

Update aligned `new` tests to use `__STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2` for 
"over-aligned" instead of `alignof(std::max_align_t) * 2`.


https://reviews.llvm.org/D39221

Files:
  
test/std/language.support/support.dynamic/new.delete/new.delete.array/delete_align_val_t_replace.pass.cpp
  
test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t.pass.cpp
  
test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t_nothrow.pass.cpp
  
test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t_nothrow_replace.pass.cpp
  
test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t_replace.pass.cpp
  
test/std/language.support/support.dynamic/new.delete/new.delete.single/delete_align_val_t_replace.pass.cpp
  
test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t.pass.cpp
  
test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow.pass.cpp
  
test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow_replace.pass.cpp
  
test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_replace.pass.cpp

Index: test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_replace.pass.cpp
===
--- test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_replace.pass.cpp
+++ test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_replace.pass.cpp
@@ -24,7 +24,7 @@
 
 #include "test_macros.h"
 
-constexpr auto OverAligned = alignof(std::max_align_t) * 2;
+constexpr auto OverAligned = __STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2;
 
 bool A_constructed = false;
 
Index: test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow_replace.pass.cpp
===
--- test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow_replace.pass.cpp
+++ test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow_replace.pass.cpp
@@ -35,7 +35,7 @@
 
 #include "test_macros.h"
 
-constexpr auto OverAligned = alignof(std::max_align_t) * 2;
+constexpr auto OverAligned = __STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2;
 
 bool A_constructed = false;
 
Index: test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow.pass.cpp
===
--- test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow.pass.cpp
+++ test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow.pass.cpp
@@ -37,7 +37,7 @@
 
 #include "test_macros.h"
 
-constexpr auto OverAligned = alignof(std::max_align_t) * 2;
+constexpr auto OverAligned = __STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2;
 
 int new_handler_called = 0;
 
Index: test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t.pass.cpp
===
--- test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t.pass.cpp
+++ test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t.pass.cpp
@@ -37,7 +37,7 @@
 
 #include "test_macros.h"
 
-constexpr auto OverAligned = alignof(std::max_align_t) * 2;
+constexpr auto OverAligned = __STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2;
 
 int new_handler_called = 0;
 
Index: test/std/language.support/support.dynamic/new.delete/new.delete.single/delete_align_val_t_replace.pass.cpp
===
--- test/std/language.support/support.dynamic/new.delete/new.delete.single/delete_align_val_t_replace.pass.cpp
+++ test/std/language.support/support.dynamic/new.delete/new.delete.single/delete_align_val_t_replace.pass.cpp
@@ -35,7 +35,7 @@
 
 #include "test_macros.h"
 
-constexpr auto OverAligned = alignof(std::max_align_t) * 2;
+constexpr auto OverAligned = __STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2;
 
 int unsized_delete_called = 0;
 int unsized_delete_nothrow_called = 0;
Index: test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t_replace.pass.cpp
===
--- test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t_replace.pass.cpp
+++ test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t_replace.pass.cpp
@@ -24,7 +24,7 @@
 
 #include "test_macros.h"
 
-constexpr auto OverAligned = alignof(std::max_align_t) * 2;
+constexpr auto OverAligned = __STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2;
 
 int A_constructed = 0;
 
Index: 

[PATCH] D39127: Fix template parameter default args missed if redecled

2017-10-23 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316405: Fix template parameter default args missed if 
redecled (authored by erichkeane).

Changed prior to commit:
  https://reviews.llvm.org/D39127?vs=119665=119991#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39127

Files:
  cfe/trunk/lib/Sema/SemaTemplate.cpp


Index: cfe/trunk/lib/Sema/SemaTemplate.cpp
===
--- cfe/trunk/lib/Sema/SemaTemplate.cpp
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp
@@ -4805,7 +4805,12 @@
   // template.
   TemplateArgumentListInfo NewArgs = TemplateArgs;
 
-  TemplateParameterList *Params = Template->getTemplateParameters();
+  // Make sure we get the template parameter list from the most
+  // recentdeclaration, since that is the only one that has is guaranteed to
+  // have all the default template argument information.
+  TemplateParameterList *Params =
+  cast(Template->getMostRecentDecl())
+  ->getTemplateParameters();
 
   SourceLocation RAngleLoc = NewArgs.getRAngleLoc();
 


Index: cfe/trunk/lib/Sema/SemaTemplate.cpp
===
--- cfe/trunk/lib/Sema/SemaTemplate.cpp
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp
@@ -4805,7 +4805,12 @@
   // template.
   TemplateArgumentListInfo NewArgs = TemplateArgs;
 
-  TemplateParameterList *Params = Template->getTemplateParameters();
+  // Make sure we get the template parameter list from the most
+  // recentdeclaration, since that is the only one that has is guaranteed to
+  // have all the default template argument information.
+  TemplateParameterList *Params =
+  cast(Template->getMostRecentDecl())
+  ->getTemplateParameters();
 
   SourceLocation RAngleLoc = NewArgs.getRAngleLoc();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38986: [Analyzer] Better unreachable message in enumeration

2017-10-23 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a comment.

@dcoughlin

> Is it when an end-user is running a build with assertions and can't provide a 
> reproducer but can provide the console output?

Yes, or just for developer staring at the crash for the first time, or for the 
crashers in CI.

> Does llvm_unreachable() guarantee that the string construction code is 
> completely removed from release builds?

I am not sure what do you mean, the string construction code would only be 
encountered when we are in the `default` branch, which would mean that we are 
crashing already. Or do you worry about the code size being slightly larger?


https://reviews.llvm.org/D38986



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


[PATCH] D39220: [Analyzer] Store BodyFarm in std::unique_ptr

2017-10-23 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov created this revision.
Herald added subscribers: szepet, kristof.beyls, xazax.hun, aemerson.

While by using `.get()` method we don't get the full protection offered by 
`std::unique_ptr`, given that two bugs were already encountered 
(http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/9065 and 
omitted nullptr assignment), using `std::unique_ptr` seems strictly better than 
raw pointer for all practical purposes.


https://reviews.llvm.org/D39220

Files:
  include/clang/Analysis/AnalysisDeclContext.h
  lib/Analysis/AnalysisDeclContext.cpp


Index: lib/Analysis/AnalysisDeclContext.cpp
===
--- lib/Analysis/AnalysisDeclContext.cpp
+++ lib/Analysis/AnalysisDeclContext.cpp
@@ -306,8 +306,8 @@
 
 BodyFarm *AnalysisDeclContextManager::getBodyFarm() {
   if (!BdyFrm)
-BdyFrm = new BodyFarm(ASTCtx, Injector.get());
-  return BdyFrm;
+BdyFrm = llvm::make_unique(ASTCtx, Injector.get());
+  return BdyFrm.get();
 }
 
 const StackFrameContext *
@@ -603,10 +603,7 @@
   }
 }
 
-AnalysisDeclContextManager::~AnalysisDeclContextManager() {
-  if (BdyFrm)
-delete BdyFrm;
-}
+AnalysisDeclContextManager::~AnalysisDeclContextManager() {}
 
 LocationContext::~LocationContext() {}
 
Index: include/clang/Analysis/AnalysisDeclContext.h
===
--- include/clang/Analysis/AnalysisDeclContext.h
+++ include/clang/Analysis/AnalysisDeclContext.h
@@ -421,7 +421,7 @@
 
   /// Pointer to a factory for creating and caching implementations for common
   /// methods during the analysis.
-  BodyFarm *BdyFrm = nullptr;
+  std::unique_ptr BdyFrm;
 
   /// Flag to indicate whether or not bodies should be synthesized
   /// for well-known functions.


Index: lib/Analysis/AnalysisDeclContext.cpp
===
--- lib/Analysis/AnalysisDeclContext.cpp
+++ lib/Analysis/AnalysisDeclContext.cpp
@@ -306,8 +306,8 @@
 
 BodyFarm *AnalysisDeclContextManager::getBodyFarm() {
   if (!BdyFrm)
-BdyFrm = new BodyFarm(ASTCtx, Injector.get());
-  return BdyFrm;
+BdyFrm = llvm::make_unique(ASTCtx, Injector.get());
+  return BdyFrm.get();
 }
 
 const StackFrameContext *
@@ -603,10 +603,7 @@
   }
 }
 
-AnalysisDeclContextManager::~AnalysisDeclContextManager() {
-  if (BdyFrm)
-delete BdyFrm;
-}
+AnalysisDeclContextManager::~AnalysisDeclContextManager() {}
 
 LocationContext::~LocationContext() {}
 
Index: include/clang/Analysis/AnalysisDeclContext.h
===
--- include/clang/Analysis/AnalysisDeclContext.h
+++ include/clang/Analysis/AnalysisDeclContext.h
@@ -421,7 +421,7 @@
 
   /// Pointer to a factory for creating and caching implementations for common
   /// methods during the analysis.
-  BodyFarm *BdyFrm = nullptr;
+  std::unique_ptr BdyFrm;
 
   /// Flag to indicate whether or not bodies should be synthesized
   /// for well-known functions.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39210: Add default calling convention support for regcall.

2017-10-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: lib/Sema/SemaType.cpp:3269-3273
+  bool IsMain = false;
+  if (D.getIdentifier() && D.getIdentifier()->isStr("main") &&
+  S.CurContext->getRedeclContext()->isTranslationUnit() &&
+  !S.getLangOpts().Freestanding)
+IsMain = true;

rnk wrote:
> erichkeane wrote:
> > rnk wrote:
> > > I highly doubt this is correct. I have a feeling there are all kinds of 
> > > ways you can get this to fire on things that aren't a function 
> > > declaration. It's also inefficient to check the identifier string every 
> > > time we make a function type. Please find somewhere else to add this. I'd 
> > > suggest adjusting the function type in CheckMain, or some time before 
> > > then, whereever we make main implicitly extern "C".
> > I believe the logic here was pulled from FunctionDecl's "isMain" function: 
> > https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html#aa2b31caf653741632b16cce1ae2061cc
> > 
> > As this is so early in the process (at Declarator), I didn't see a good 
> > place to recommend extracting this, besides pulling it into the Declarator. 
> >  
> > 
> > CheckMain is also run at the Decl stage, isn't it?  Is your suggestion be 
> > to simply let this go through with the wrong calling-convention here, then 
> > revert it it in "CheckMain"?
> Yep. You can look at how we use FunctionTypeUnwrapper and 
> ASTContext::adjustFunctionType in various places to fix up function types 
> that were built with the wrong calling convention without losing type source 
> info.
Perfect, thanks for the examples!  I am sure @eandrews can use those to track 
down the right place to fix this up.


https://reviews.llvm.org/D39210



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


[PATCH] D39064: implement __has_unique_object_representations

2017-10-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: lib/AST/Type.cpp:2226
+Context.getFieldOffset(*Record->field_begin()));
+for (const auto *Field : Record->fields()) {
+  if (!Field->getType().hasUniqueObjectRepresentations(Context))

rnk wrote:
> What about base classes? I think that's where the padding detection is going 
> to get wacky. =/
Based on my reading of the RecordLayout stuff, the "getFieldOffset" should take 
that into account, right?  It seems that 'fields' contains all fields, and thus 
should run through the offset of all of them, right?  I'll add another test 
that inherits from a Padded struct to verify (as well as one that causes 
padding with the inheritence).


https://reviews.llvm.org/D39064



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


[PATCH] D37808: [clang-tidy] Add new hicpp-multiway-paths-covered check for missing branches

2017-10-23 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere added inline comments.



Comment at: clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp:80
+
+  // Unsigned overflow occured. Returning max() is sufficient, since noone
+  // writes so many case labels in source code.

Maybe merge this with the function comment, no point in having both imho.



Comment at: clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp:82
+  // writes so many case labels in source code.
+  if (Bits > 0 && DiscreteValues <= 1) {
+return std::numeric_limits::max();

LLVM style guide says no braces with single line if/else statements. No need 
for the else after a return. Alternatively you could use the ternary operator. 



Comment at: clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp:100
+return twoPow(Context.getTypeSize(T));
+  else
+return twoPow(0ul);

No need for the else here. See previous comment. 



Comment at: clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp:146
+
+  if (CaseCount == 1 || CaseCount == 2) {
+diag(Switch->getLocStart(),

Braces



Comment at: clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp:180
+if (const auto *IntegerCondition =
+Result.Nodes.getNodeAs("non-enum-condition")) {
+  return getNumberOfPossibleValues(IntegerCondition->getType(),

Braces



Comment at: clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp:183
+   *Result.Context);
+} else if (const auto *BitfieldDecl =
+   Result.Nodes.getNodeAs("bitfield")) {

You can just use if because of the return.



Comment at: clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp:186
+  return twoPow(BitfieldDecl->getBitWidthValue(*Result.Context));
+} else {
+  llvm_unreachable("either bitfield or non-enum must be condition");

Drop the else



Comment at: clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp:198
+  // missed some value explicity, therefore add a default branch.
+  if (CaseCount < MaxPathsPossible) {
+diag(Switch->getLocStart(), CoverMsgs[CaseCount == 1 ? 0 : 1]);

Braces


https://reviews.llvm.org/D37808



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


r316403 - [Analyzer] Fix for the memory leak: fix typo in if-statement.

2017-10-23 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Mon Oct 23 18:09:43 2017
New Revision: 316403

URL: http://llvm.org/viewvc/llvm-project?rev=316403=rev
Log:
[Analyzer] Fix for the memory leak: fix typo in if-statement.

Modified:
cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp

Modified: cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp?rev=316403=316402=316403=diff
==
--- cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp (original)
+++ cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp Mon Oct 23 18:09:43 2017
@@ -604,7 +604,7 @@ AnalysisDeclContext::~AnalysisDeclContex
 }
 
 AnalysisDeclContextManager::~AnalysisDeclContextManager() {
-  if (!BdyFrm)
+  if (BdyFrm)
 delete BdyFrm;
 }
 


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


[PATCH] D39162: [test] Fix clang-test for FreeBSD and NetBSD

2017-10-23 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray added a comment.

ping?


https://reviews.llvm.org/D39162



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


[PATCH] D39005: [OpenMP] Clean up variable and function names for NVPTX backend

2017-10-23 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added a comment.

In https://reviews.llvm.org/D39005#900973, @jlebar wrote:

> > The first question that comes to mind is what is the link between data 
> > layout and name mangling conventions?
>
> I pulled up http://llvm.org/doxygen/classllvm_1_1DataLayout.html and searched 
> for "mangling" -- presumably this is what they were referring to.  We also 
> don't need to speculate, rnk still works on LLVM.  :)


DataLayout generally holds information that the target-independent optimizer 
needs in order to simplify the IR into our canonical form. This is as opposed 
to TargetTransformInfo, which provides data necessary to optimize the IR in 
target-aware ways (e.g., do things that are orthogonal to canonicalization such 
as inlining and vectorization). It is also as opposed to external utility 
functions that might be used by the frontend (e.g., 
llvm::sys::getHostCPUName()). If I recall correctly, this is information that 
would be used by the frontend when generating the IR, and the function results 
are controlled by the triple. As a result, I think that a general utility 
function somewhere would be fine.


Repository:
  rL LLVM

https://reviews.llvm.org/D39005



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


[PATCH] D39127: Fix template parameter default args missed if redecled

2017-10-23 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


https://reviews.llvm.org/D39127



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


[PATCH] D39053: [Bitfield] Add more cases to making the bitfield a separate location

2017-10-23 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added a comment.

> With this patch we avoid unaligned loads and stores, at least on MIPS 
> architecture.

Can you please explain the nature of the problematic situations?

Also, this patch does not update the comments that describe the splitting 
algorithm. That should be improved.

If this is just addressing the classic problem that, once we narrow a load we 
can't re-widen it, it might be best to solve this another way (e.g., by adding 
metadata noting the dereferenceable range).


https://reviews.llvm.org/D39053



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


[PATCH] D39218: [WebAssembly] Include libclang_rt.builtins in the standard way

2017-10-23 Thread Derek Schuff via Phabricator via cfe-commits
dschuff added inline comments.



Comment at: lib/Driver/ToolChain.cpp:318
+  else
+OSLibName = getOS();
   llvm::sys::path::append(Path, "lib", OSLibName);

Is this logic intended to replace what was removed from CommonArgs.cpp? Should 
there be an assert here too?


https://reviews.llvm.org/D39218



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


[PATCH] D39210: Add default calling convention support for regcall.

2017-10-23 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: lib/Sema/SemaType.cpp:3269-3273
+  bool IsMain = false;
+  if (D.getIdentifier() && D.getIdentifier()->isStr("main") &&
+  S.CurContext->getRedeclContext()->isTranslationUnit() &&
+  !S.getLangOpts().Freestanding)
+IsMain = true;

erichkeane wrote:
> rnk wrote:
> > I highly doubt this is correct. I have a feeling there are all kinds of 
> > ways you can get this to fire on things that aren't a function declaration. 
> > It's also inefficient to check the identifier string every time we make a 
> > function type. Please find somewhere else to add this. I'd suggest 
> > adjusting the function type in CheckMain, or some time before then, 
> > whereever we make main implicitly extern "C".
> I believe the logic here was pulled from FunctionDecl's "isMain" function: 
> https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html#aa2b31caf653741632b16cce1ae2061cc
> 
> As this is so early in the process (at Declarator), I didn't see a good place 
> to recommend extracting this, besides pulling it into the Declarator.  
> 
> CheckMain is also run at the Decl stage, isn't it?  Is your suggestion be to 
> simply let this go through with the wrong calling-convention here, then 
> revert it it in "CheckMain"?
Yep. You can look at how we use FunctionTypeUnwrapper and 
ASTContext::adjustFunctionType in various places to fix up function types that 
were built with the wrong calling convention without losing type source info.


https://reviews.llvm.org/D39210



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


[PATCH] D39210: Add default calling convention support for regcall.

2017-10-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: lib/Sema/SemaType.cpp:3269-3273
+  bool IsMain = false;
+  if (D.getIdentifier() && D.getIdentifier()->isStr("main") &&
+  S.CurContext->getRedeclContext()->isTranslationUnit() &&
+  !S.getLangOpts().Freestanding)
+IsMain = true;

rnk wrote:
> I highly doubt this is correct. I have a feeling there are all kinds of ways 
> you can get this to fire on things that aren't a function declaration. It's 
> also inefficient to check the identifier string every time we make a function 
> type. Please find somewhere else to add this. I'd suggest adjusting the 
> function type in CheckMain, or some time before then, whereever we make main 
> implicitly extern "C".
I believe the logic here was pulled from FunctionDecl's "isMain" function: 
https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html#aa2b31caf653741632b16cce1ae2061cc

As this is so early in the process (at Declarator), I didn't see a good place 
to recommend extracting this, besides pulling it into the Declarator.  

CheckMain is also run at the Decl stage, isn't it?  Is your suggestion be to 
simply let this go through with the wrong calling-convention here, then revert 
it it in "CheckMain"?


https://reviews.llvm.org/D39210



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


r316402 - [Analyzer] Handle implicit function reference in bodyfarming std::call_once

2017-10-23 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Mon Oct 23 17:13:18 2017
New Revision: 316402

URL: http://llvm.org/viewvc/llvm-project?rev=316402=rev
Log:
[Analyzer] Handle implicit function reference in bodyfarming std::call_once

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

Modified:
cfe/trunk/lib/Analysis/BodyFarm.cpp
cfe/trunk/test/Analysis/call_once.cpp

Modified: cfe/trunk/lib/Analysis/BodyFarm.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BodyFarm.cpp?rev=316402=316401=316402=diff
==
--- cfe/trunk/lib/Analysis/BodyFarm.cpp (original)
+++ cfe/trunk/lib/Analysis/BodyFarm.cpp Mon Oct 23 17:13:18 2017
@@ -253,13 +253,23 @@ static CallExpr *create_call_once_funcpt
const ParmVarDecl *Callback,
ArrayRef CallArgs) {
 
-  return new (C) CallExpr(
-  /*ASTContext=*/C,
-  /*StmtClass=*/M.makeLvalueToRvalue(/*Expr=*/Callback),
-  /*args=*/CallArgs,
-  /*QualType=*/C.VoidTy,
-  /*ExprValueType=*/VK_RValue,
-  /*SourceLocation=*/SourceLocation());
+  QualType Ty = Callback->getType();
+  DeclRefExpr *Call = M.makeDeclRefExpr(Callback);
+  CastKind CK;
+  if (Ty->isRValueReferenceType()) {
+CK = CK_LValueToRValue;
+  } else {
+assert(Ty->isLValueReferenceType());
+CK = CK_FunctionToPointerDecay;
+Ty = C.getPointerType(Ty.getNonReferenceType());
+  }
+
+  return new (C)
+  CallExpr(C, M.makeImplicitCast(Call, Ty.getNonReferenceType(), CK),
+   /*args=*/CallArgs,
+   /*QualType=*/C.VoidTy,
+   /*ExprValueType=*/VK_RValue,
+   /*SourceLocation=*/SourceLocation());
 }
 
 static CallExpr *create_call_once_lambda_call(ASTContext , ASTMaker M,
@@ -366,9 +376,11 @@ static Stmt *create_call_once(ASTContext
 CallbackFunctionType = CallbackRecordDecl->getLambdaCallOperator()
->getType()
->getAs();
-  } else {
+  } else if (!CallbackType->getPointeeType().isNull()) {
 CallbackFunctionType =
 CallbackType->getPointeeType()->getAs();
+  } else {
+CallbackFunctionType = CallbackType->getAs();
   }
 
   if (!CallbackFunctionType)

Modified: cfe/trunk/test/Analysis/call_once.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/call_once.cpp?rev=316402=316401=316402=diff
==
--- cfe/trunk/test/Analysis/call_once.cpp (original)
+++ cfe/trunk/test/Analysis/call_once.cpp Mon Oct 23 17:13:18 2017
@@ -290,3 +290,16 @@ void test_mutator_noref() {
   std::call_once(flag, _mutator, a);
   clang_analyzer_eval(a == 42); // expected-warning{{FALSE}}
 }
+
+// Function is implicitly treated as a function pointer
+// even when an ampersand is not explicitly set.
+void callbackn(int ) {
+  param = 42;
+};
+void test_implicit_funcptr() {
+  int x = 0;
+  static std::once_flag flagn;
+
+  std::call_once(flagn, callbackn, x);
+  clang_analyzer_eval(x == 42); // expected-warning{{TRUE}}
+}


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


[PATCH] D39201: [Analyzer] Handle implicit function reference in bodyfarming std::call_once

2017-10-23 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316402: [Analyzer] Handle implicit function reference in 
bodyfarming std::call_once (authored by george.karpenkov).

Changed prior to commit:
  https://reviews.llvm.org/D39201?vs=119911=119975#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39201

Files:
  cfe/trunk/lib/Analysis/BodyFarm.cpp
  cfe/trunk/test/Analysis/call_once.cpp


Index: cfe/trunk/lib/Analysis/BodyFarm.cpp
===
--- cfe/trunk/lib/Analysis/BodyFarm.cpp
+++ cfe/trunk/lib/Analysis/BodyFarm.cpp
@@ -253,13 +253,23 @@
const ParmVarDecl *Callback,
ArrayRef CallArgs) {
 
-  return new (C) CallExpr(
-  /*ASTContext=*/C,
-  /*StmtClass=*/M.makeLvalueToRvalue(/*Expr=*/Callback),
-  /*args=*/CallArgs,
-  /*QualType=*/C.VoidTy,
-  /*ExprValueType=*/VK_RValue,
-  /*SourceLocation=*/SourceLocation());
+  QualType Ty = Callback->getType();
+  DeclRefExpr *Call = M.makeDeclRefExpr(Callback);
+  CastKind CK;
+  if (Ty->isRValueReferenceType()) {
+CK = CK_LValueToRValue;
+  } else {
+assert(Ty->isLValueReferenceType());
+CK = CK_FunctionToPointerDecay;
+Ty = C.getPointerType(Ty.getNonReferenceType());
+  }
+
+  return new (C)
+  CallExpr(C, M.makeImplicitCast(Call, Ty.getNonReferenceType(), CK),
+   /*args=*/CallArgs,
+   /*QualType=*/C.VoidTy,
+   /*ExprValueType=*/VK_RValue,
+   /*SourceLocation=*/SourceLocation());
 }
 
 static CallExpr *create_call_once_lambda_call(ASTContext , ASTMaker M,
@@ -366,9 +376,11 @@
 CallbackFunctionType = CallbackRecordDecl->getLambdaCallOperator()
->getType()
->getAs();
-  } else {
+  } else if (!CallbackType->getPointeeType().isNull()) {
 CallbackFunctionType =
 CallbackType->getPointeeType()->getAs();
+  } else {
+CallbackFunctionType = CallbackType->getAs();
   }
 
   if (!CallbackFunctionType)
Index: cfe/trunk/test/Analysis/call_once.cpp
===
--- cfe/trunk/test/Analysis/call_once.cpp
+++ cfe/trunk/test/Analysis/call_once.cpp
@@ -290,3 +290,16 @@
   std::call_once(flag, _mutator, a);
   clang_analyzer_eval(a == 42); // expected-warning{{FALSE}}
 }
+
+// Function is implicitly treated as a function pointer
+// even when an ampersand is not explicitly set.
+void callbackn(int ) {
+  param = 42;
+};
+void test_implicit_funcptr() {
+  int x = 0;
+  static std::once_flag flagn;
+
+  std::call_once(flagn, callbackn, x);
+  clang_analyzer_eval(x == 42); // expected-warning{{TRUE}}
+}


Index: cfe/trunk/lib/Analysis/BodyFarm.cpp
===
--- cfe/trunk/lib/Analysis/BodyFarm.cpp
+++ cfe/trunk/lib/Analysis/BodyFarm.cpp
@@ -253,13 +253,23 @@
const ParmVarDecl *Callback,
ArrayRef CallArgs) {
 
-  return new (C) CallExpr(
-  /*ASTContext=*/C,
-  /*StmtClass=*/M.makeLvalueToRvalue(/*Expr=*/Callback),
-  /*args=*/CallArgs,
-  /*QualType=*/C.VoidTy,
-  /*ExprValueType=*/VK_RValue,
-  /*SourceLocation=*/SourceLocation());
+  QualType Ty = Callback->getType();
+  DeclRefExpr *Call = M.makeDeclRefExpr(Callback);
+  CastKind CK;
+  if (Ty->isRValueReferenceType()) {
+CK = CK_LValueToRValue;
+  } else {
+assert(Ty->isLValueReferenceType());
+CK = CK_FunctionToPointerDecay;
+Ty = C.getPointerType(Ty.getNonReferenceType());
+  }
+
+  return new (C)
+  CallExpr(C, M.makeImplicitCast(Call, Ty.getNonReferenceType(), CK),
+   /*args=*/CallArgs,
+   /*QualType=*/C.VoidTy,
+   /*ExprValueType=*/VK_RValue,
+   /*SourceLocation=*/SourceLocation());
 }
 
 static CallExpr *create_call_once_lambda_call(ASTContext , ASTMaker M,
@@ -366,9 +376,11 @@
 CallbackFunctionType = CallbackRecordDecl->getLambdaCallOperator()
->getType()
->getAs();
-  } else {
+  } else if (!CallbackType->getPointeeType().isNull()) {
 CallbackFunctionType =
 CallbackType->getPointeeType()->getAs();
+  } else {
+CallbackFunctionType = CallbackType->getAs();
   }
 
   if (!CallbackFunctionType)
Index: cfe/trunk/test/Analysis/call_once.cpp
===
--- cfe/trunk/test/Analysis/call_once.cpp
+++ cfe/trunk/test/Analysis/call_once.cpp
@@ -290,3 +290,16 @@
   std::call_once(flag, _mutator, a);
   clang_analyzer_eval(a == 42); // expected-warning{{FALSE}}
 }
+
+// Function is implicitly treated as a function pointer
+// even when an ampersand is not explicitly set.
+void callbackn(int ) {
+  param = 42;
+};
+void 

[PATCH] D39210: Add default calling convention support for regcall.

2017-10-23 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: lib/Sema/SemaType.cpp:3269-3273
+  bool IsMain = false;
+  if (D.getIdentifier() && D.getIdentifier()->isStr("main") &&
+  S.CurContext->getRedeclContext()->isTranslationUnit() &&
+  !S.getLangOpts().Freestanding)
+IsMain = true;

I highly doubt this is correct. I have a feeling there are all kinds of ways 
you can get this to fire on things that aren't a function declaration. It's 
also inefficient to check the identifier string every time we make a function 
type. Please find somewhere else to add this. I'd suggest adjusting the 
function type in CheckMain, or some time before then, whereever we make main 
implicitly extern "C".


https://reviews.llvm.org/D39210



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


[PATCH] D39208: [Analyzer] Do not use static storage to for implementations created in BodyFarm.cpp

2017-10-23 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a comment.

@dcoughlin OK sorry, I haven't considered the point that codebase predates the 
requirement, and the master format-all commit was never done.
I've committed this one already, but I will be more careful with applying 
clang-format to future changes.


Repository:
  rL LLVM

https://reviews.llvm.org/D39208



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


[PATCH] D39208: [Analyzer] Do not use static storage to for implementations created in BodyFarm.cpp

2017-10-23 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin added a comment.

That would require going into the past and requiring everyone back then to run 
clang-format as well. Unfortunately they didn't -- so human judgment is needed 
when modifying code that doesn't obey the guidelines.


Repository:
  rL LLVM

https://reviews.llvm.org/D39208



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


[PATCH] D39208: [Analyzer] Do not use static storage to for implementations created in BodyFarm.cpp

2017-10-23 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316400: [Analyzer] Do not use static storage to for 
implementations created in BodyFarm. (authored by george.karpenkov).

Changed prior to commit:
  https://reviews.llvm.org/D39208?vs=119949=119974#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39208

Files:
  cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h
  cfe/trunk/include/clang/Analysis/BodyFarm.h
  cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp
  cfe/trunk/lib/Analysis/BodyFarm.cpp
  cfe/trunk/lib/Analysis/BodyFarm.h
  cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp

Index: cfe/trunk/include/clang/Analysis/BodyFarm.h
===
--- cfe/trunk/include/clang/Analysis/BodyFarm.h
+++ cfe/trunk/include/clang/Analysis/BodyFarm.h
@@ -0,0 +1,51 @@
+//== BodyFarm.h - Factory for conjuring up fake bodies -*- C++ -*-//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// BodyFarm is a factory for creating faux implementations for functions/methods
+// for analysis purposes.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_ANALYSIS_BODYFARM_H
+#define LLVM_CLANG_LIB_ANALYSIS_BODYFARM_H
+
+#include "clang/AST/DeclBase.h"
+#include "clang/Basic/LLVM.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/Optional.h"
+
+namespace clang {
+
+class ASTContext;
+class FunctionDecl;
+class ObjCMethodDecl;
+class ObjCPropertyDecl;
+class Stmt;
+class CodeInjector;
+
+class BodyFarm {
+public:
+  BodyFarm(ASTContext , CodeInjector *injector) : C(C), Injector(injector) {}
+
+  /// Factory method for creating bodies for ordinary functions.
+  Stmt *getBody(const FunctionDecl *D);
+
+  /// Factory method for creating bodies for Objective-C properties.
+  Stmt *getBody(const ObjCMethodDecl *D);
+
+private:
+  typedef llvm::DenseMap> BodyMap;
+
+  ASTContext 
+  BodyMap Bodies;
+  CodeInjector *Injector;
+};
+} // namespace clang
+
+#endif
Index: cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h
===
--- cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h
+++ cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h
@@ -16,6 +16,7 @@
 #define LLVM_CLANG_ANALYSIS_ANALYSISDECLCONTEXT_H
 
 #include "clang/AST/Decl.h"
+#include "clang/Analysis/BodyFarm.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Analysis/CodeInjector.h"
 #include "llvm/ADT/DenseMap.h"
@@ -409,29 +410,33 @@
   typedef llvm::DenseMap>
   ContextMap;
 
+  ASTContext 
   ContextMap Contexts;
   LocationContextManager LocContexts;
   CFG::BuildOptions cfgBuildOptions;
 
   /// Pointer to an interface that can provide function bodies for
   /// declarations from external source.
   std::unique_ptr Injector;
-  
+
+  /// Pointer to a factory for creating and caching implementations for common
+  /// methods during the analysis.
+  BodyFarm *BdyFrm = nullptr;
+
   /// Flag to indicate whether or not bodies should be synthesized
   /// for well-known functions.
   bool SynthesizeBodies;
 
 public:
-  AnalysisDeclContextManager(bool useUnoptimizedCFG = false,
+  AnalysisDeclContextManager(ASTContext , bool useUnoptimizedCFG = false,
  bool addImplicitDtors = false,
  bool addInitializers = false,
  bool addTemporaryDtors = false,
- bool addLifetime = false,
- bool addLoopExit = false,
+ bool addLifetime = false, bool addLoopExit = false,
  bool synthesizeBodies = false,
  bool addStaticInitBranches = false,
  bool addCXXNewAllocator = true,
- CodeInjector* injector = nullptr);
+ CodeInjector *injector = nullptr);
 
   ~AnalysisDeclContextManager();
 
@@ -472,6 +477,9 @@
 return LocContexts.getStackFrame(getContext(D), Parent, S, Blk, Idx);
   }
 
+  /// Get and lazily create a {@code BodyFarm} instance.
+  BodyFarm *getBodyFarm();
+
   /// Discard all previously created AnalysisDeclContexts.
   void clear();
 
Index: cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp
@@ -14,33 +14,25 @@
 
 void AnalysisManager::anchor() { }
 
-AnalysisManager::AnalysisManager(ASTContext , DiagnosticsEngine ,
- const LangOptions ,
- const 

[PATCH] D39208: [Analyzer] Do not use static storage to for implementations created in BodyFarm.cpp

2017-10-23 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a comment.

@dcoughlin the context I was thinking about is that if everyone consistently 
runs `clang-format` (if we want that), then we never would have discussion.
The alternative is that every run of `clang-format` would be followed by 
manually reverting changes which were introduced by mistake (in this case, 
because the file was moved).


https://reviews.llvm.org/D39208



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


r316400 - [Analyzer] Do not use static storage to for implementations created in BodyFarm.cpp

2017-10-23 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Mon Oct 23 16:59:52 2017
New Revision: 316400

URL: http://llvm.org/viewvc/llvm-project?rev=316400=rev
Log:
[Analyzer] Do not use static storage to for implementations created in 
BodyFarm.cpp

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

Added:
cfe/trunk/include/clang/Analysis/BodyFarm.h
  - copied, changed from r316249, cfe/trunk/lib/Analysis/BodyFarm.h
Removed:
cfe/trunk/lib/Analysis/BodyFarm.h
Modified:
cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h
cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp
cfe/trunk/lib/Analysis/BodyFarm.cpp
cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp

Modified: cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h?rev=316400=316399=316400=diff
==
--- cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h (original)
+++ cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h Mon Oct 23 16:59:52 
2017
@@ -16,6 +16,7 @@
 #define LLVM_CLANG_ANALYSIS_ANALYSISDECLCONTEXT_H
 
 #include "clang/AST/Decl.h"
+#include "clang/Analysis/BodyFarm.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Analysis/CodeInjector.h"
 #include "llvm/ADT/DenseMap.h"
@@ -409,6 +410,7 @@ class AnalysisDeclContextManager {
   typedef llvm::DenseMap>
   ContextMap;
 
+  ASTContext 
   ContextMap Contexts;
   LocationContextManager LocContexts;
   CFG::BuildOptions cfgBuildOptions;
@@ -416,22 +418,25 @@ class AnalysisDeclContextManager {
   /// Pointer to an interface that can provide function bodies for
   /// declarations from external source.
   std::unique_ptr Injector;
-  
+
+  /// Pointer to a factory for creating and caching implementations for common
+  /// methods during the analysis.
+  BodyFarm *BdyFrm = nullptr;
+
   /// Flag to indicate whether or not bodies should be synthesized
   /// for well-known functions.
   bool SynthesizeBodies;
 
 public:
-  AnalysisDeclContextManager(bool useUnoptimizedCFG = false,
+  AnalysisDeclContextManager(ASTContext , bool useUnoptimizedCFG = 
false,
  bool addImplicitDtors = false,
  bool addInitializers = false,
  bool addTemporaryDtors = false,
- bool addLifetime = false,
- bool addLoopExit = false,
+ bool addLifetime = false, bool addLoopExit = 
false,
  bool synthesizeBodies = false,
  bool addStaticInitBranches = false,
  bool addCXXNewAllocator = true,
- CodeInjector* injector = nullptr);
+ CodeInjector *injector = nullptr);
 
   ~AnalysisDeclContextManager();
 
@@ -472,6 +477,9 @@ public:
 return LocContexts.getStackFrame(getContext(D), Parent, S, Blk, Idx);
   }
 
+  /// Get and lazily create a {@code BodyFarm} instance.
+  BodyFarm *getBodyFarm();
+
   /// Discard all previously created AnalysisDeclContexts.
   void clear();
 

Copied: cfe/trunk/include/clang/Analysis/BodyFarm.h (from r316249, 
cfe/trunk/lib/Analysis/BodyFarm.h)
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/BodyFarm.h?p2=cfe/trunk/include/clang/Analysis/BodyFarm.h=cfe/trunk/lib/Analysis/BodyFarm.h=316249=316400=316400=diff
==
--- cfe/trunk/lib/Analysis/BodyFarm.h (original)
+++ cfe/trunk/include/clang/Analysis/BodyFarm.h Mon Oct 23 16:59:52 2017
@@ -28,11 +28,11 @@ class ObjCMethodDecl;
 class ObjCPropertyDecl;
 class Stmt;
 class CodeInjector;
-  
+
 class BodyFarm {
 public:
   BodyFarm(ASTContext , CodeInjector *injector) : C(C), Injector(injector) {}
-  
+
   /// Factory method for creating bodies for ordinary functions.
   Stmt *getBody(const FunctionDecl *D);
 
@@ -40,12 +40,12 @@ public:
   Stmt *getBody(const ObjCMethodDecl *D);
 
 private:
-  typedef llvm::DenseMap > BodyMap;
+  typedef llvm::DenseMap> BodyMap;
 
   ASTContext 
   BodyMap Bodies;
   CodeInjector *Injector;
 };
-}
+} // namespace clang
 
 #endif

Modified: cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp?rev=316400=316399=316400=diff
==
--- cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp (original)
+++ cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp Mon Oct 23 16:59:52 2017
@@ -13,7 +13,6 @@
 
//===--===//
 
 #include "clang/Analysis/AnalysisDeclContext.h"
-#include "BodyFarm.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclObjC.h"
@@ -23,6 +22,7 @@
 #include 

[PATCH] D39208: [Analyzer] Do not use static storage to for implementations created in BodyFarm.cpp

2017-10-23 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin added a comment.

I think a good strategy is to look at your diffs and consider whether the 
benefits of normalizing the style outweigh the cost of losing the history. In 
this case, I think keeping the history makes sense. (Imagine you are a future 
maintainer and want to know when and why a new option was added. Is is very 
helpful to use git annotate to understand why the code is the way it is.)


https://reviews.llvm.org/D39208



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


[PATCH] D39174: [analyzer] Fix handling of labels in getLValueElement

2017-10-23 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316399: [analyzer] Fix handling of labels in 
getLValueElement (authored by alexshap).

Changed prior to commit:
  https://reviews.llvm.org/D39174?vs=119808=119972#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39174

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp
  cfe/trunk/test/Analysis/ptr-arith.c


Index: cfe/trunk/test/Analysis/ptr-arith.c
===
--- cfe/trunk/test/Analysis/ptr-arith.c
+++ cfe/trunk/test/Analysis/ptr-arith.c
@@ -342,3 +342,8 @@
   clang_analyzer_eval(*ptr3 == 'a'); // expected-warning{{UNKNOWN}}
 }
 
+void test_no_crash_on_pointer_to_label() {
+  char *a = &
+  a[0] = 0;
+label:;
+}
Index: cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp
@@ -440,7 +440,10 @@
   //  value. See also the similar FIXME in getLValueFieldOrIvar().
   if (Base.isUnknownOrUndef() || Base.getAs())
 return Base;
-
+  
+  if (Base.getAs())
+return UnknownVal();
+  
   const SubRegion *BaseRegion =
   Base.castAs().getRegionAs();
 


Index: cfe/trunk/test/Analysis/ptr-arith.c
===
--- cfe/trunk/test/Analysis/ptr-arith.c
+++ cfe/trunk/test/Analysis/ptr-arith.c
@@ -342,3 +342,8 @@
   clang_analyzer_eval(*ptr3 == 'a'); // expected-warning{{UNKNOWN}}
 }
 
+void test_no_crash_on_pointer_to_label() {
+  char *a = &
+  a[0] = 0;
+label:;
+}
Index: cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp
@@ -440,7 +440,10 @@
   //  value. See also the similar FIXME in getLValueFieldOrIvar().
   if (Base.isUnknownOrUndef() || Base.getAs())
 return Base;
-
+  
+  if (Base.getAs())
+return UnknownVal();
+  
   const SubRegion *BaseRegion =
   Base.castAs().getRegionAs();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r316399 - [analyzer] Fix handling of labels in getLValueElement

2017-10-23 Thread Alexander Shaposhnikov via cfe-commits
Author: alexshap
Date: Mon Oct 23 16:46:06 2017
New Revision: 316399

URL: http://llvm.org/viewvc/llvm-project?rev=316399=rev
Log:
[analyzer] Fix handling of labels in getLValueElement

In getLValueElement Base may represent the address of a label 
(as in the newly-added test case), in this case it's not a loc::MemRegionVal 
and Base.castAs() triggers an assert, this diff makes 
getLValueElement return UnknownVal instead.

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp
cfe/trunk/test/Analysis/ptr-arith.c

Modified: cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp?rev=316399=316398=316399=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp Mon Oct 23 16:46:06 2017
@@ -440,7 +440,10 @@ SVal StoreManager::getLValueElement(Qual
   //  value. See also the similar FIXME in getLValueFieldOrIvar().
   if (Base.isUnknownOrUndef() || Base.getAs())
 return Base;
-
+  
+  if (Base.getAs())
+return UnknownVal();
+  
   const SubRegion *BaseRegion =
   Base.castAs().getRegionAs();
 

Modified: cfe/trunk/test/Analysis/ptr-arith.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/ptr-arith.c?rev=316399=316398=316399=diff
==
--- cfe/trunk/test/Analysis/ptr-arith.c (original)
+++ cfe/trunk/test/Analysis/ptr-arith.c Mon Oct 23 16:46:06 2017
@@ -342,3 +342,8 @@ void negativeIndex(char *str) {
   clang_analyzer_eval(*ptr3 == 'a'); // expected-warning{{UNKNOWN}}
 }
 
+void test_no_crash_on_pointer_to_label() {
+  char *a = &
+  a[0] = 0;
+label:;
+}


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


[PATCH] D39217: [libclang, bindings]: add spelling location

2017-10-23 Thread Masud Rahman via Phabricator via cfe-commits
frutiger added a comment.

I would very much appreciate some guidance on whether or not this kind of a 
change in behaviour for `clang_getSpellingLocation` is an acceptable thing to 
do.


https://reviews.llvm.org/D39217



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


[PATCH] D39217: [libclang, bindings]: add spelling location

2017-10-23 Thread Masud Rahman via Phabricator via cfe-commits
frutiger updated this revision to Diff 119971.
frutiger added a comment.

Add context to the patch.


https://reviews.llvm.org/D39217

Files:
  bindings/python/clang/cindex.py
  bindings/python/tests/cindex/test_location.py
  test/Index/annotate-tokens.c
  test/Index/blocks.c
  test/Index/c-index-api-loadTU-test.m
  test/Index/c-index-getCursor-test.m
  test/Index/get-cursor.cpp
  test/Index/get-cursor.m
  test/Index/load-exprs.c
  test/Index/preamble-conditionals-crash.cpp
  test/Index/preamble_macro_template.cpp
  tools/libclang/CXSourceLocation.cpp

Index: tools/libclang/CXSourceLocation.cpp
===
--- tools/libclang/CXSourceLocation.cpp
+++ tools/libclang/CXSourceLocation.cpp
@@ -318,8 +318,7 @@
   
   const SourceManager  =
   *static_cast(location.ptr_data[0]);
-  // FIXME: This should call SourceManager::getSpellingLoc().
-  SourceLocation SpellLoc = SM.getFileLoc(Loc);
+  SourceLocation SpellLoc = SM.getSpellingLoc(Loc);
   std::pair LocInfo = SM.getDecomposedLoc(SpellLoc);
   FileID FID = LocInfo.first;
   unsigned FileOffset = LocInfo.second;
Index: test/Index/preamble_macro_template.cpp
===
--- test/Index/preamble_macro_template.cpp
+++ test/Index/preamble_macro_template.cpp
@@ -8,7 +8,7 @@
 // CHECK: preamble_macro_template.h:4:13: ParmDecl=p:4:13 (Definition) Extent=[4:10 - 4:14]
 // CHECK: preamble_macro_template.h:4:16: CompoundStmt= Extent=[4:16 - 6:2]
 // CHECK: preamble_macro_template.h:5:3: CStyleCastExpr= Extent=[5:3 - 5:27]
-// CHECK: preamble_macro_template.h:5:9: CXXStaticCastExpr= Extent=[5:9 - 5:27]
+// CHECK: preamble_macro_template.h:1:21: CXXStaticCastExpr= Extent=[1:21 - 5:27]
 // CHECK: preamble_macro_template.h:5:25: UnexposedExpr= Extent=[5:25 - 5:26]
 // CHECK: preamble_macro_template.h:5:25: IntegerLiteral= Extent=[5:25 - 5:26]
 // CHECK: preamble_macro_template.cpp:3:5: FunctionDecl=main:3:5 (Definition) Extent=[3:1 - 3:15]
Index: test/Index/preamble-conditionals-crash.cpp
===
--- test/Index/preamble-conditionals-crash.cpp
+++ test/Index/preamble-conditionals-crash.cpp
@@ -9,4 +9,4 @@
 // RUN: | FileCheck %s --implicit-check-not "libclang: crash detected" \
 // RUN:--implicit-check-not "error:"
 // CHECK: macro expansion=FOO:3:9 Extent=[4:1 - 4:4]
-// CHECK: VarDecl=aba:4:1 (Definition) Extent=[4:1 - 4:4]
+// CHECK: VarDecl=aba:3:17 (Definition) Extent=[3:13 - 4:4]
Index: test/Index/load-exprs.c
===
--- test/Index/load-exprs.c
+++ test/Index/load-exprs.c
@@ -52,7 +52,7 @@
 // CHECK: load-exprs.c:7:23: DeclRefExpr=x:6:12 Extent=[7:23 - 7:24]
 // CHECK: load-exprs.c:10:5: FunctionDecl=test_blocks:10:5 (Definition) Extent=[10:1 - 21:2]
 // CHECK: load-exprs.c:10:21: ParmDecl=x:10:21 (Definition) Extent=[10:17 - 10:22]
-// CHECK: load-exprs.c:11:15: VarDecl=y:11:15 (Definition) Extent=[11:3 - 11:20]
+// CHECK: load-exprs.c:11:15: VarDecl=y:11:15 (Definition)
 // CHECK: load-exprs.c:11:19: DeclRefExpr=x:10:21 Extent=[11:19 - 11:20]
 // CHECK: load-exprs.c:12:3: CallExpr= Extent=[12:3 - 19:7]
 // CHECK: load-exprs.c:13:17: VarDecl=z:13:17 (Definition) Extent=[13:6 - 13:22]
Index: test/Index/get-cursor.m
===
--- test/Index/get-cursor.m
+++ test/Index/get-cursor.m
@@ -229,11 +229,11 @@
 // CHECK-TRANSPARENT: 139:1 TypeRef=TestTransparent:133:17 (Transparent: enum TestTransparent) Extent=[139:1 - 139:16] Spelling=TestTransparent ([139:1 - 139:16])
 // CHECK-TRANSPARENT: 140:6 TypeRef=enum TestTransparent:133:17 Extent=[140:6 - 140:21] Spelling=enum TestTransparent ([140:6 - 140:21])
 // CHECK-TRANSPARENT: 141:1 TypeRef=NotTransparent:137:30 Extent=[141:1 - 141:15] Spelling=NotTransparent ([141:1 - 141:15])
-// CHECK-TRANSPARENT: 147:1 TypeRef=TokenPaste_t:144:9 Extent=[147:1 - 147:13] Spelling=TokenPaste_t ([147:1 - 147:13])
+// CHECK-TRANSPARENT: 147:1 TypeRef=TokenPaste_t:2:1 Extent=[147:1 - 147:13] Spelling=TokenPaste_t ([147:1 - 147:13])
 // CHECK-TRANSPARENT: 151:1 TypeRef=SomeT:150:17 (Transparent: struct SomeT) Extent=[151:1 - 151:6] Spelling=SomeT ([151:1 - 151:6])
 // CHECK-TRANSPARENT: 155:1 TypeRef=SomeT2:154:18 Extent=[155:1 - 155:7] Spelling=SomeT2 ([155:1 - 155:7])
 
 // RUN: c-index-test -cursor-at=%s:160:12 -cursor-at=%s:161:8 %s | FileCheck -check-prefix=CHECK-EXTERNAL %s
 // CHECK-EXTERNAL: 160:12 ObjCInterfaceDecl=ExtCls:160:12 (external lang: Swift, defined: some_module, gen: 1)
 // CHECK-EXTERNAL: 161:8 ObjCInstanceMethodDecl=method:161:8 (external lang: Swift, defined: some_module, gen: 1)
-C
\ No newline at end of file
+C
Index: test/Index/get-cursor.cpp
===
--- test/Index/get-cursor.cpp
+++ test/Index/get-cursor.cpp
@@ -214,7 +214,7 @@
 // 

Re: r316278 - [libclang, bindings]: add spelling location

2017-10-23 Thread Masud Rahman via cfe-commits
I created a new revision to review and to fix the tests:
https://reviews.llvm.org/D39217.

On Sat, Oct 21, 2017 at 6:24 PM, Masud Rahman  wrote:

> Thanks, I will take a look.
>
> On Sat, Oct 21, 2017 at 5:53 PM, Aaron Ballman 
> wrote:
>
>> I've reverted back to green in r316279 due to more bots failing.
>>
>> ~Aaron
>>
>> On Sat, Oct 21, 2017 at 5:35 PM, Aaron Ballman 
>> wrote:
>> > This commit appears to have broken several bots. Can you revert or
>> > quickly fix the issue?
>> >
>> > http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/11896
>> > http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/12380
>> >
>> > Thanks!
>> >
>> > ~Aaron
>> >
>> > On Sat, Oct 21, 2017 at 4:53 PM, Masud Rahman via cfe-commits
>> >  wrote:
>> >> Author: frutiger
>> >> Date: Sat Oct 21 13:53:49 2017
>> >> New Revision: 316278
>> >>
>> >> URL: http://llvm.org/viewvc/llvm-project?rev=316278=rev
>> >> Log:
>> >> [libclang, bindings]: add spelling location
>> >>
>> >>  o) Add a 'Location' class that represents the four properties of a
>> >> physical location
>> >>
>> >>  o) Enhance 'SourceLocation' to provide 'expansion' and 'spelling'
>> >> locations, maintaining backwards compatibility with existing code
>> by
>> >> forwarding the four properties to 'expansion'.
>> >>
>> >>  o) Update the implementation to use 'clang_getExpansionLocation'
>> >> instead of the deprecated 'clang_getInstantiationLocation', which
>> >> has been present since 2011.
>> >>
>> >>  o) Update the implementation of 'clang_getSpellingLocation' to
>> actually
>> >> obtain spelling location instead of file location.
>> >>
>> >> Modified:
>> >> cfe/trunk/bindings/python/clang/cindex.py
>> >> cfe/trunk/bindings/python/tests/cindex/test_location.py
>> >> cfe/trunk/tools/libclang/CXSourceLocation.cpp
>> >>
>> >> Modified: cfe/trunk/bindings/python/clang/cindex.py
>> >> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/pytho
>> n/clang/cindex.py?rev=316278=316277=316278=diff
>> >> 
>> ==
>> >> --- cfe/trunk/bindings/python/clang/cindex.py (original)
>> >> +++ cfe/trunk/bindings/python/clang/cindex.py Sat Oct 21 13:53:49 2017
>> >> @@ -214,25 +214,45 @@ class _CXString(Structure):
>> >>  assert isinstance(res, _CXString)
>> >>  return conf.lib.clang_getCString(res)
>> >>
>> >> +class Location(object):
>> >> +"""A Location is a specific kind of source location.  A
>> SourceLocation
>> >> +refers to several kinds of locations (e.g.  spelling location vs.
>> expansion
>> >> +location)."""
>> >> +
>> >> +def __init__(self, file, line, column, offset):
>> >> +self._file   = File(file) if file else None
>> >> +self._line   = int(line.value)
>> >> +self._column = int(column.value)
>> >> +self._offset = int(offset.value)
>> >> +
>> >> +
>> >> +@property
>> >> +def file(self):
>> >> +"""Get the file represented by this source location."""
>> >> +return self._file
>> >> +
>> >> +@property
>> >> +def line(self):
>> >> +"""Get the line represented by this source location."""
>> >> +return self._line
>> >> +
>> >> +@property
>> >> +def column(self):
>> >> +"""Get the column represented by this source location."""
>> >> +return self._column
>> >> +
>> >> +@property
>> >> +def offset(self):
>> >> +"""Get the file offset represented by this source location."""
>> >> +return self._offset
>> >>
>> >>  class SourceLocation(Structure):
>> >>  """
>> >>  A SourceLocation represents a particular location within a source
>> file.
>> >>  """
>> >>  _fields_ = [("ptr_data", c_void_p * 2), ("int_data", c_uint)]
>> >> -_data = None
>> >> -
>> >> -def _get_instantiation(self):
>> >> -if self._data is None:
>> >> -f, l, c, o = c_object_p(), c_uint(), c_uint(), c_uint()
>> >> -conf.lib.clang_getInstantiationLocation(self, byref(f),
>> byref(l),
>> >> -byref(c), byref(o))
>> >> -if f:
>> >> -f = File(f)
>> >> -else:
>> >> -f = None
>> >> -self._data = (f, int(l.value), int(c.value), int(o.value))
>> >> -return self._data
>> >> +_expansion = None
>> >> +_spelling = None
>> >>
>> >>  @staticmethod
>> >>  def from_position(tu, file, line, column):
>> >> @@ -253,24 +273,72 @@ class SourceLocation(Structure):
>> >>  return conf.lib.clang_getLocationForOffset(tu, file, offset)
>> >>
>> >>  @property
>> >> +def expansion(self):
>> >> +"""
>> >> +The source location where then entity this object is
>> referring to is
>> >> +expanded.
>> >> +"""
>> >> +if not self._expansion:
>> >> +

[PATCH] D39069: CodeGen: Fix missing debug loc due to alloca

2017-10-23 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

Anytime the code between saveIP() and restoreIP() could set the current debug 
location, it needs to be saved/restored along with the insertion point.  I have 
to say the problem is not obvious to me here, so maybe saveIP/restoreIP should 
be changed (or eliminated in favor of always using InsertPointGuard).  I'm not 
seeing a lot of places where saveIP/restoreIP are used.

The test looks like all it's doing is verifying both calls have a debug 
location at all.  It could verify that both calls have the _same_ debug 
location, which I would find much more robust and convincing.


https://reviews.llvm.org/D39069



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


[PATCH] D39217: [libclang, bindings]: add spelling location

2017-10-23 Thread Masud Rahman via Phabricator via cfe-commits
frutiger created this revision.

- Add a 'Location' class that represents the four properties of a physical 
location
- Enhance 'SourceLocation' to provide 'expansion' and 'spelling' locations, 
maintaining backwards compatibility with existing code by forwarding the four 
properties to 'expansion'.
- Update the implementation to use 'clang_getExpansionLocation' instead of the 
deprecated 'clang_getInstantiationLocation', which has been present since 2011.
- Update the implementation of 'clang_getSpellingLocation' to actually obtain 
spelling location instead of file location.
- Update test cases to account for changes to the result of 
'clang_getSpellingLocation'.

Note: this commit is a reapplication of r316278 along with fixes to the
test cases.


https://reviews.llvm.org/D39217

Files:
  bindings/python/clang/cindex.py
  bindings/python/tests/cindex/test_location.py
  test/Index/annotate-tokens.c
  test/Index/blocks.c
  test/Index/c-index-api-loadTU-test.m
  test/Index/c-index-getCursor-test.m
  test/Index/get-cursor.cpp
  test/Index/get-cursor.m
  test/Index/load-exprs.c
  test/Index/preamble-conditionals-crash.cpp
  test/Index/preamble_macro_template.cpp
  tools/libclang/CXSourceLocation.cpp

Index: tools/libclang/CXSourceLocation.cpp
===
--- tools/libclang/CXSourceLocation.cpp
+++ tools/libclang/CXSourceLocation.cpp
@@ -318,8 +318,7 @@
   
   const SourceManager  =
   *static_cast(location.ptr_data[0]);
-  // FIXME: This should call SourceManager::getSpellingLoc().
-  SourceLocation SpellLoc = SM.getFileLoc(Loc);
+  SourceLocation SpellLoc = SM.getSpellingLoc(Loc);
   std::pair LocInfo = SM.getDecomposedLoc(SpellLoc);
   FileID FID = LocInfo.first;
   unsigned FileOffset = LocInfo.second;
Index: test/Index/preamble_macro_template.cpp
===
--- test/Index/preamble_macro_template.cpp
+++ test/Index/preamble_macro_template.cpp
@@ -8,7 +8,7 @@
 // CHECK: preamble_macro_template.h:4:13: ParmDecl=p:4:13 (Definition) Extent=[4:10 - 4:14]
 // CHECK: preamble_macro_template.h:4:16: CompoundStmt= Extent=[4:16 - 6:2]
 // CHECK: preamble_macro_template.h:5:3: CStyleCastExpr= Extent=[5:3 - 5:27]
-// CHECK: preamble_macro_template.h:5:9: CXXStaticCastExpr= Extent=[5:9 - 5:27]
+// CHECK: preamble_macro_template.h:1:21: CXXStaticCastExpr= Extent=[1:21 - 5:27]
 // CHECK: preamble_macro_template.h:5:25: UnexposedExpr= Extent=[5:25 - 5:26]
 // CHECK: preamble_macro_template.h:5:25: IntegerLiteral= Extent=[5:25 - 5:26]
 // CHECK: preamble_macro_template.cpp:3:5: FunctionDecl=main:3:5 (Definition) Extent=[3:1 - 3:15]
Index: test/Index/preamble-conditionals-crash.cpp
===
--- test/Index/preamble-conditionals-crash.cpp
+++ test/Index/preamble-conditionals-crash.cpp
@@ -9,4 +9,4 @@
 // RUN: | FileCheck %s --implicit-check-not "libclang: crash detected" \
 // RUN:--implicit-check-not "error:"
 // CHECK: macro expansion=FOO:3:9 Extent=[4:1 - 4:4]
-// CHECK: VarDecl=aba:4:1 (Definition) Extent=[4:1 - 4:4]
+// CHECK: VarDecl=aba:3:17 (Definition) Extent=[3:13 - 4:4]
Index: test/Index/load-exprs.c
===
--- test/Index/load-exprs.c
+++ test/Index/load-exprs.c
@@ -52,7 +52,7 @@
 // CHECK: load-exprs.c:7:23: DeclRefExpr=x:6:12 Extent=[7:23 - 7:24]
 // CHECK: load-exprs.c:10:5: FunctionDecl=test_blocks:10:5 (Definition) Extent=[10:1 - 21:2]
 // CHECK: load-exprs.c:10:21: ParmDecl=x:10:21 (Definition) Extent=[10:17 - 10:22]
-// CHECK: load-exprs.c:11:15: VarDecl=y:11:15 (Definition) Extent=[11:3 - 11:20]
+// CHECK: load-exprs.c:11:15: VarDecl=y:11:15 (Definition)
 // CHECK: load-exprs.c:11:19: DeclRefExpr=x:10:21 Extent=[11:19 - 11:20]
 // CHECK: load-exprs.c:12:3: CallExpr= Extent=[12:3 - 19:7]
 // CHECK: load-exprs.c:13:17: VarDecl=z:13:17 (Definition) Extent=[13:6 - 13:22]
Index: test/Index/get-cursor.m
===
--- test/Index/get-cursor.m
+++ test/Index/get-cursor.m
@@ -229,11 +229,11 @@
 // CHECK-TRANSPARENT: 139:1 TypeRef=TestTransparent:133:17 (Transparent: enum TestTransparent) Extent=[139:1 - 139:16] Spelling=TestTransparent ([139:1 - 139:16])
 // CHECK-TRANSPARENT: 140:6 TypeRef=enum TestTransparent:133:17 Extent=[140:6 - 140:21] Spelling=enum TestTransparent ([140:6 - 140:21])
 // CHECK-TRANSPARENT: 141:1 TypeRef=NotTransparent:137:30 Extent=[141:1 - 141:15] Spelling=NotTransparent ([141:1 - 141:15])
-// CHECK-TRANSPARENT: 147:1 TypeRef=TokenPaste_t:144:9 Extent=[147:1 - 147:13] Spelling=TokenPaste_t ([147:1 - 147:13])
+// CHECK-TRANSPARENT: 147:1 TypeRef=TokenPaste_t:2:1 Extent=[147:1 - 147:13] Spelling=TokenPaste_t ([147:1 - 147:13])
 // CHECK-TRANSPARENT: 151:1 TypeRef=SomeT:150:17 (Transparent: struct SomeT) Extent=[151:1 - 151:6] Spelling=SomeT ([151:1 - 151:6])
 // 

[PATCH] D37341: [Sema] Fix an assert-on-invalid by avoiding function template specialisation deduction for invalid functions with fabricated template arguments

2017-10-23 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 119967.
arphaman added a comment.

Use just the `isInvalidDecl` check.


Repository:
  rL LLVM

https://reviews.llvm.org/D37341

Files:
  lib/Sema/SemaDecl.cpp
  test/SemaTemplate/deduction-crash.cpp
  test/SemaTemplate/explicit-specialization-member.cpp


Index: test/SemaTemplate/explicit-specialization-member.cpp
===
--- test/SemaTemplate/explicit-specialization-member.cpp
+++ test/SemaTemplate/explicit-specialization-member.cpp
@@ -38,24 +38,20 @@
 
   template
   template
-  void Baz::bar() { // expected-note {{couldn't infer template argument 
'N'}}
+  void Baz::bar() {
   }
 
-  // FIXME: We shouldn't try to match this against a prior declaration if
-  // template parameter matching failed.
   template
-  void Baz::bar<0>() { // expected-error {{cannot specialize a member of an 
unspecialized template}} \
-  // expected-error {{no function template matches}}
+  void Baz::bar<0>() { // expected-error {{cannot specialize a member of an 
unspecialized template}}
   }
 }
 
 namespace PR19340 {
 template struct Helper {
-  template static void func(const T *m) {} // expected-note {{failed 
template argument deduction}}
+  template static void func(const T *m) {}
 };
 
-template void Helper::func<2>() {} // expected-error {{cannot 
specialize a member}} \
-  // expected-error {{no 
function template matches}}
+template void Helper::func<2>() {} // expected-error {{cannot 
specialize a member}}
 }
 
 namespace SpecLoc {
Index: test/SemaTemplate/deduction-crash.cpp
===
--- test/SemaTemplate/deduction-crash.cpp
+++ test/SemaTemplate/deduction-crash.cpp
@@ -144,3 +144,20 @@
   template int n; // expected-error +{{}} 
expected-note {{}}
   int k = n;
 }
+
+namespace deduceFunctionSpecializationForInvalidOutOfLineFunction {
+
+template 
+struct SourceSelectionRequirement {
+  template
+  OutputT evaluateSelectionRequirement(InputT &) {
+  }
+};
+
+template 
+OutputT SourceSelectionRequirement::
+evaluateSelectionRequirement(InputT &) { // expected-error 
{{cannot specialize a member of an unspecialized template}}
+  return Value;
+}
+
+}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -8962,10 +8962,10 @@
   diag::ext_function_specialization_in_class :
   diag::err_function_specialization_in_class)
   << NewFD->getDeclName();
-  } else if (CheckFunctionTemplateSpecialization(NewFD,
-  (HasExplicitTemplateArgs ? 
-   : nullptr),
- Previous))
+  } else if (!NewFD->isInvalidDecl() &&
+ CheckFunctionTemplateSpecialization(
+ NewFD, (HasExplicitTemplateArgs ?  : 
nullptr),
+ Previous))
 NewFD->setInvalidDecl();
 
   // C++ [dcl.stc]p1:


Index: test/SemaTemplate/explicit-specialization-member.cpp
===
--- test/SemaTemplate/explicit-specialization-member.cpp
+++ test/SemaTemplate/explicit-specialization-member.cpp
@@ -38,24 +38,20 @@
 
   template
   template
-  void Baz::bar() { // expected-note {{couldn't infer template argument 'N'}}
+  void Baz::bar() {
   }
 
-  // FIXME: We shouldn't try to match this against a prior declaration if
-  // template parameter matching failed.
   template
-  void Baz::bar<0>() { // expected-error {{cannot specialize a member of an unspecialized template}} \
-  // expected-error {{no function template matches}}
+  void Baz::bar<0>() { // expected-error {{cannot specialize a member of an unspecialized template}}
   }
 }
 
 namespace PR19340 {
 template struct Helper {
-  template static void func(const T *m) {} // expected-note {{failed template argument deduction}}
+  template static void func(const T *m) {}
 };
 
-template void Helper::func<2>() {} // expected-error {{cannot specialize a member}} \
-  // expected-error {{no function template matches}}
+template void Helper::func<2>() {} // expected-error {{cannot specialize a member}}
 }
 
 namespace SpecLoc {
Index: test/SemaTemplate/deduction-crash.cpp
===
--- test/SemaTemplate/deduction-crash.cpp
+++ test/SemaTemplate/deduction-crash.cpp
@@ -144,3 +144,20 @@
   template int n; // expected-error +{{}} expected-note {{}}
   int k = n;
 }
+
+namespace deduceFunctionSpecializationForInvalidOutOfLineFunction {
+
+template 
+struct SourceSelectionRequirement {
+  template
+  OutputT evaluateSelectionRequirement(InputT &) {
+  }
+};
+
+template 

[PATCH] D16970: scoped alloc construct: adds basic tests

2017-10-23 Thread Masud Rahman via Phabricator via cfe-commits
frutiger abandoned this revision.
frutiger added a comment.

@AlisdairM maybe you want to commandeer this revision?  I don't think this is 
going anywhere...


https://reviews.llvm.org/D16970



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


[PATCH] D37341: [Sema] Fix an assert-on-invalid by avoiding function template specialisation deduction for invalid functions with fabricated template arguments

2017-10-23 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman marked an inline comment as done.
arphaman added a comment.

In https://reviews.llvm.org/D37341#869042, @vsapsai wrote:

> Does your fix work for deeper nesting too (e.g. template in template in 
> template)? Looks like it should, just want to confirm.


Yes.

> Are there other places where you need to avoid calling 
> `DeduceTemplateArguments` due to templates depth mismatch? 
> `CheckDependentFunctionTemplateSpecialization` should be OK as it's not 
> deducing template arguments. But I'm not sure about 
> `CheckMemberSpecialization`. It doesn't call `DeduceTemplateArguments` 
> directly but I haven't dug deep enough to confirm it's not performing 
> deduction indirectly.

The problem only seems to happen when the TPL is fabricated. I didn't see other 
potential places where such an issue might happen.




Comment at: lib/Sema/SemaDecl.cpp:8880-8881
   << NewFD->getDeclName();
-  } else if (CheckFunctionTemplateSpecialization(NewFD,
+  } else if (!HasFabricatedTemplateSpecializationTemplateParams &&
+ CheckFunctionTemplateSpecialization(NewFD,
   (HasExplicitTemplateArgs ? 

vsapsai wrote:
> Will something more general like
> 
> !NewFD->isInvalidDecl() && CheckFunctionTemplateSpecialization(...)
> 
> work here? Because if matching template parameters to scope specifier fails, 
> `NewFD` is marked as invalid decl and seems like we can use that.
Yeah, good idea.


Repository:
  rL LLVM

https://reviews.llvm.org/D37341



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


[PATCH] D16967: support/allocators: implements requirements

2017-10-23 Thread Masud Rahman via Phabricator via cfe-commits
frutiger abandoned this revision.
frutiger added a subscriber: AlisdairM.
frutiger added a comment.

@AlisdairM maybe you want to commandeer this?  This revision is probably not 
going anywhere any time soon...


https://reviews.llvm.org/D16967



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


[libcxx] r316394 - More fuzzing interfaces

2017-10-23 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Mon Oct 23 16:19:30 2017
New Revision: 316394

URL: http://llvm.org/viewvc/llvm-project?rev=316394=rev
Log:
More fuzzing interfaces

Added:
libcxx/trunk/fuzzing/RoutineNames.txt
Modified:
libcxx/trunk/fuzzing/fuzzing.cpp
libcxx/trunk/fuzzing/fuzzing.h

Added: libcxx/trunk/fuzzing/RoutineNames.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/fuzzing/RoutineNames.txt?rev=316394=auto
==
--- libcxx/trunk/fuzzing/RoutineNames.txt (added)
+++ libcxx/trunk/fuzzing/RoutineNames.txt Mon Oct 23 16:19:30 2017
@@ -0,0 +1,16 @@
+sort
+stable_sort
+partition
+stable_partition
+nth_element
+partial_sort
+make_heap
+push_heap
+pop_heap
+regex_ECMAScript
+regex_POSIX
+regex_extended
+regex_awk
+regex_grep
+regex_egrep
+search

Modified: libcxx/trunk/fuzzing/fuzzing.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/fuzzing/fuzzing.cpp?rev=316394=316393=316394=diff
==
--- libcxx/trunk/fuzzing/fuzzing.cpp (original)
+++ libcxx/trunk/fuzzing/fuzzing.cpp Mon Oct 23 16:19:30 2017
@@ -26,9 +26,12 @@
 #include "fuzzing.h"
 #include 
 #include 
+#include 
 #include 
 
-// If we had C++14, we could use the four iterator version of 
is_permutation
+#include 
+
+// If we had C++14, we could use the four iterator version of 
is_permutation and equal
 
 namespace fuzzing {
 
@@ -273,4 +276,101 @@ int regex_egrep (const uint8_t *data, si
return 0;
 }
 
+// --  heap fuzzers
+int make_heap (const uint8_t *data, size_t size)
+{
+   std::vector working(data, data + size);
+   std::make_heap(working.begin(), working.end());
+
+   if (!std::is_heap(working.begin(), working.end())) return 1;
+   if (!std::is_permutation(data, data + size, working.begin())) return 99;
+   return 0;
+}
+
+int push_heap (const uint8_t *data, size_t size)
+{
+   if (size < 2) return 0;
+
+// Make a heap from the first half of the data
+   std::vector working(data, data + size);
+   auto iter = working.begin() + (size / 2);
+   std::make_heap(working.begin(), iter);
+   if (!std::is_heap(working.begin(), iter)) return 1;
+
+// Now push the rest onto the heap, one at a time
+   ++iter;
+   for (; iter != working.end(); ++iter) {
+   std::push_heap(working.begin(), iter);
+   if (!std::is_heap(working.begin(), iter)) return 2; 
+   }
+
+   if (!std::is_permutation(data, data + size, working.begin())) return 99;
+   return 0;
+}
+
+int pop_heap (const uint8_t *data, size_t size)
+{
+   if (size < 2) return 0;
+   std::vector working(data, data + size);
+   std::make_heap(working.begin(), working.end());
+
+// Pop things off, one at a time
+   auto iter = --working.end();
+   while (iter != working.begin()) {
+   std::pop_heap(working.begin(), iter);
+   if (!std::is_heap(working.begin(), --iter)) return 2;   
+   }
+
+   return 0;
+}
+
+
+// --  search fuzzers
+int search (const uint8_t *data, size_t size)
+{
+   if (size < 2) return 0;
+   
+   const size_t pat_size = data[0] * (size - 1) / 
std::numeric_limits::max();
+   assert(pat_size <= size - 1);
+   const uint8_t *pat_begin = data + 1;
+   const uint8_t *pat_end   = pat_begin + pat_size;
+   const uint8_t *data_end  = data + size;
+   assert(pat_end <= data_end);
+// std::cerr << "data[0] = " << size_t(data[0]) << " ";
+// std::cerr << "Pattern size = " << pat_size << "; corpus is " << size - 
1 << std::endl;
+   auto it = std::search(pat_end, data_end, pat_begin, pat_end);
+   if (it != data_end) // not found
+   if (!std::equal(pat_begin, pat_end, it))
+   return 1;
+   return 0;
+}
+
+template 
+static int search_helper (const uint8_t *data, size_t size)
+{
+   if (size < 2) return 0;
+   
+   const size_t pat_size = data[0] * (size - 1) / 
std::numeric_limits::max();
+   const uint8_t *pat_begin = data + 1;
+   const uint8_t *pat_end   = pat_begin + pat_size;
+   const uint8_t *data_end  = data + size;
+
+   auto it = std::search(pat_end, data_end, S(pat_begin, pat_end));
+   if (it != data_end) // not found
+   if (!std::equal(pat_begin, pat_end, it))
+   return 1;
+   return 0;
+}
+
+// These are still in std::experimental
+// int search_boyer_moore (const uint8_t *data, size_t size)
+// {
+// return search_helper(data, 
size);
+// }
+// 
+// int search_boyer_moore_horspool (const uint8_t *data, size_t size)
+// {
+// return search_helper(data, size);
+// }
+
 } // namespace fuzzing

Modified: libcxx/trunk/fuzzing/fuzzing.h
URL: 

[PATCH] D39206: [libunwind] Add missing checks for register number

2017-10-23 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


https://reviews.llvm.org/D39206



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


[PATCH] D39208: [Analyzer] Do not use static storage to for implementations created in BodyFarm.cpp

2017-10-23 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a comment.

@dcoughlin that's not me, that's clang-format.
If we agree on always running it, I think the changes should stay there.


https://reviews.llvm.org/D39208



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


[PATCH] D39208: [Analyzer] Do not use static storage to for implementations created in BodyFarm.cpp

2017-10-23 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

Content-wise, LGTM. There is a style nit inline.

Also, can you avoid reformatting the lines that haven't changed? This will help 
preserve the history of the file and make it clear what changes are related to 
your intended change in functionality.




Comment at: lib/Analysis/AnalysisDeclContext.cpp:308
+BodyFarm *AnalysisDeclContextManager::getBodyFarm() {
+  if (BdyFrm == nullptr)
+BdyFrm = new BodyFarm(ASTCtx, Injector.get());

Nit: Style-wise this is idiomatically written as:
```
if (!BdyFrm)
```


https://reviews.llvm.org/D39208



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


[PATCH] D37954: Try to shorten system header paths when using -MD depfiles

2017-10-23 Thread Peter Wu via Phabricator via cfe-commits
Lekensteyn added a comment.

(FWIW, the suggestion to use `FileManager:getCanonicalName` did not work 
because I have no DirectoryEntry. And `-no-canonical-prefixes` it used very 
early and stripped from normal options, it seems used for a different purpose. 
Given the opposition, I think that this patch is a no-go.)

In https://reviews.llvm.org/D37954#902979, @jyknight wrote:

> It seems to me that it was caused by the prefix being set as "/bin" instead 
> of "/usr/bin", because clang _doesn't_ actually canonicalize its prefix, even 
> when -no-canonical-prefixes isn't specified! All it does, now, is to make the 
> prefix absolute -- without fully canonicalizing. I think that's simply a bug.
>
> If the prefix had been, properly, /usr/bin, then the include path would've 
> been:
>
>   
> /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.2.0/../../../../include/c++/7.2.0/iostream
>
> And in that case, it would've worked properly with ninja, without adding the 
> feature in this patch.
>
> Reference clang/tools/driver/driver.cpp:297:
>
>   // FIXME: We don't actually canonicalize this, we just make it absolute.
>   if (CanonicalPrefixes)
> llvm::sys::fs::make_absolute(InstalledPath);


If this fixes the issue, then it would definitely be a much better approach. If 
this has changed between Clang 4 -> 5, then it is possible the root cause.

On my system (Arch Linux) `/bin` is a symlink to `usr/bin`. Output of `clang 
-v`:

  clang version 5.0.0 (tags/RELEASE_500/final)
  Target: x86_64-unknown-linux-gnu
  Thread model: posix
  InstalledDir: /bin
  Found candidate GCC installation: /bin/../lib/gcc/x86_64-pc-linux-gnu/7.2.0
  Found candidate GCC installation: /bin/../lib64/gcc/x86_64-pc-linux-gnu/7.2.0
  Found candidate GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0
  Found candidate GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/7.2.0
  Selected GCC installation: /bin/../lib64/gcc/x86_64-pc-linux-gnu/7.2.0
  Candidate multilib: .;@m64
  Candidate multilib: 32;@m32
  Selected multilib: .;@m64


Repository:
  rL LLVM

https://reviews.llvm.org/D37954



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


[PATCH] D39210: Add default calling convention support for regcall.

2017-10-23 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.

Added support for regcall as default calling convention.  Also added code to 
exclude main when applying default calling conventions.


https://reviews.llvm.org/D39210

Files:
  include/clang/AST/ASTContext.h
  include/clang/Basic/LangOptions.h
  include/clang/Driver/CC1Options.td
  include/clang/Driver/CLCompatOptions.td
  lib/AST/ASTContext.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenCXX/default_calling_conv.cpp
  test/Driver/cl-cc-flags.c

Index: test/Driver/cl-cc-flags.c
===
--- test/Driver/cl-cc-flags.c
+++ test/Driver/cl-cc-flags.c
@@ -13,6 +13,9 @@
 // RUN: %clang_cl --target=i686-windows-msvc /Gv -### -- %s 2>&1 | FileCheck --check-prefix=VECTORCALL %s
 // VECTORCALL: -fdefault-calling-conv=vectorcall
 
+// RUN: %clang_cl --target=i686-windows-msvc /Gregcall -### -- %s 2>&1 | FileCheck --check-prefix=REGCALL %s
+// REGCALL: -fdefault-calling-conv=regcall
+
 // Last one should win:
 
 // RUN: %clang_cl --target=i686-windows-msvc /Gd /Gv -### -- %s 2>&1 | FileCheck --check-prefix=LASTWINS_VECTOR %s
Index: test/CodeGenCXX/default_calling_conv.cpp
===
--- test/CodeGenCXX/default_calling_conv.cpp
+++ test/CodeGenCXX/default_calling_conv.cpp
@@ -3,11 +3,13 @@
 // RUN: %clang_cc1 -triple i486-unknown-linux-gnu -fdefault-calling-conv=stdcall -emit-llvm -o - %s | FileCheck %s --check-prefix=STDCALL --check-prefix=ALL
 // RUN: %clang_cc1 -triple i486-unknown-linux-gnu -mrtd -emit-llvm -o - %s | FileCheck %s --check-prefix=STDCALL --check-prefix=ALL
 // RUN: %clang_cc1 -triple i986-unknown-linux-gnu -fdefault-calling-conv=vectorcall -emit-llvm -o - %s | FileCheck %s --check-prefix=VECTORCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i986-unknown-linux-gnu -fdefault-calling-conv=regcall -emit-llvm -o - %s | FileCheck %s --check-prefix=REGCALL --check-prefix=ALL
 
 // CDECL: define void @_Z5test1v
 // FASTCALL: define x86_fastcallcc void @_Z5test1v
 // STDCALL: define x86_stdcallcc void @_Z5test1v
 // VECTORCALL: define x86_vectorcallcc void @_Z5test1v
+// REGCALL: define x86_regcallcc void @_Z17__regcall3__test1v
 void test1() {}
 
 // ALL: define void @_Z5test2v
@@ -22,6 +24,9 @@
 // ALL: define  x86_vectorcallcc void @_Z5test5v
 void __attribute__((vectorcall)) test5() {}
 
+// ALL: define x86_regcallcc void @_Z17__regcall3__test6v
+void __attribute__((regcall)) test6() {}
+
 // ALL: define linkonce_odr void @_ZN1A11test_memberEv
 class A {
 public:
@@ -32,3 +37,8 @@
   A a;
   a.test_member();
 }
+
+// ALL: define i32 @main
+int main() {
+  return 1;
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -3266,8 +3266,14 @@
 }
   }
 
-  CallingConv CC = S.Context.getDefaultCallingConvention(FTI.isVariadic,
- IsCXXInstanceMethod);
+  bool IsMain = false;
+  if (D.getIdentifier() && D.getIdentifier()->isStr("main") &&
+  S.CurContext->getRedeclContext()->isTranslationUnit() &&
+  !S.getLangOpts().Freestanding)
+IsMain = true;
+
+  CallingConv CC = S.Context.getDefaultCallingConvention(
+  FTI.isVariadic, IsCXXInstanceMethod, IsMain);
 
   // Attribute AT_OpenCLKernel affects the calling convention for SPIR
   // and AMDGPU targets, hence it cannot be treated as a calling
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2299,12 +2299,12 @@
   // Check for MS default calling conventions being specified.
   if (Arg *A = Args.getLastArg(OPT_fdefault_calling_conv_EQ)) {
 LangOptions::DefaultCallingConvention DefaultCC =
-llvm::StringSwitch(
-A->getValue())
+llvm::StringSwitch(A->getValue())
 .Case("cdecl", LangOptions::DCC_CDecl)
 .Case("fastcall", LangOptions::DCC_FastCall)
 .Case("stdcall", LangOptions::DCC_StdCall)
 .Case("vectorcall", LangOptions::DCC_VectorCall)
+.Case("regcall", LangOptions::DCC_RegCall)
 .Default(LangOptions::DCC_None);
 if (DefaultCC == LangOptions::DCC_None)
   Diags.Report(diag::err_drv_invalid_value)
@@ -2315,7 +2315,8 @@
 bool emitError = (DefaultCC == LangOptions::DCC_FastCall ||
   DefaultCC == LangOptions::DCC_StdCall) &&
  Arch != llvm::Triple::x86;
-emitError |= DefaultCC == LangOptions::DCC_VectorCall &&
+emitError |= (DefaultCC == LangOptions::DCC_VectorCall ||
+  DefaultCC == LangOptions::DCC_RegCall) &&
  !(Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64);
 if (emitError)
   

[PATCH] D36790: [ObjC] Messages to 'self' in class methods should use class method dispatch to avoid multiple method ambiguities

2017-10-23 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

@doug.gregor Ping


Repository:
  rL LLVM

https://reviews.llvm.org/D36790



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


[PATCH] D39079: New clang option -fno-plt to avoid PLT for external calls

2017-10-23 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


https://reviews.llvm.org/D39079



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


[PATCH] D38774: [CodeGen] Add support for IncompleteArrayType in Obj-C ivars.

2017-10-23 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/lib/CodeGen/CGObjCMac.cpp:5095
+fieldType = fieldType->getAsArrayTypeUnsafe()->getElementType();
+  }
+

vsapsai wrote:
> rjmccall wrote:
> > You can't just use isa<> here; there can be typedefs of incomplete array 
> > type.
> Thanks for catching it.
Oh, and C allows you to have incomplete arrays of array type, e.g. int x[][4];


https://reviews.llvm.org/D38774



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


[PATCH] D38774: [CodeGen] Add support for IncompleteArrayType in Obj-C ivars.

2017-10-23 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai updated this revision to Diff 119952.
vsapsai added a comment.

- Resubmit my last change without files from underlying branch.


https://reviews.llvm.org/D38774

Files:
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/test/CodeGenObjC/ivar-layout-flexible-array.m


Index: clang/test/CodeGenObjC/ivar-layout-flexible-array.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/ivar-layout-flexible-array.m
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -Wno-objc-root-class -fobjc-arc 
-emit-llvm -o - %s | FileCheck %s
+
+// rdar://problem/21054495
+typedef char FlexibleArray[];
+
+@interface FlexibleArrayMember {
+  FlexibleArray flexible_array;
+}
+@end
+@implementation FlexibleArrayMember
+@end
+// CHECK: @OBJC_METH_VAR_NAME_{{.*}} = private unnamed_addr constant {{.*}} 
c"flexible_array\00"
+// CHECK-NEXT: @OBJC_METH_VAR_TYPE_{{.*}} = private unnamed_addr constant 
{{.*}} c"^c\00"
+
+
+struct Packet {
+  int size;
+  FlexibleArray data;
+};
+
+@interface VariableSizeIvar {
+  struct Packet flexible_struct;
+}
+@end
+@implementation VariableSizeIvar
+@end
+// CHECK: @OBJC_METH_VAR_NAME_{{.*}} = private unnamed_addr constant {{.*}} 
c"flexible_struct\00"
+// CHECK-NEXT: @OBJC_METH_VAR_TYPE_{{.*}} = private unnamed_addr constant 
{{.*}} c"{Packet=\22size\22i\22data\22[0c]}\00"
Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -5089,6 +5089,11 @@
 fieldType = arrayType->getElementType();
   }
 
+  if (auto arrayType = CGM.getContext().getAsIncompleteArrayType(fieldType)) {
+numElts = 0;
+fieldType = arrayType->getElementType();
+  }
+
   assert(!fieldType->isArrayType() && "ivar of non-constant array type?");
 
   // If we ended up with a zero-sized array, we've done what we can do within


Index: clang/test/CodeGenObjC/ivar-layout-flexible-array.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/ivar-layout-flexible-array.m
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -Wno-objc-root-class -fobjc-arc -emit-llvm -o - %s | FileCheck %s
+
+// rdar://problem/21054495
+typedef char FlexibleArray[];
+
+@interface FlexibleArrayMember {
+  FlexibleArray flexible_array;
+}
+@end
+@implementation FlexibleArrayMember
+@end
+// CHECK: @OBJC_METH_VAR_NAME_{{.*}} = private unnamed_addr constant {{.*}} c"flexible_array\00"
+// CHECK-NEXT: @OBJC_METH_VAR_TYPE_{{.*}} = private unnamed_addr constant {{.*}} c"^c\00"
+
+
+struct Packet {
+  int size;
+  FlexibleArray data;
+};
+
+@interface VariableSizeIvar {
+  struct Packet flexible_struct;
+}
+@end
+@implementation VariableSizeIvar
+@end
+// CHECK: @OBJC_METH_VAR_NAME_{{.*}} = private unnamed_addr constant {{.*}} c"flexible_struct\00"
+// CHECK-NEXT: @OBJC_METH_VAR_TYPE_{{.*}} = private unnamed_addr constant {{.*}} c"{Packet=\22size\22i\22data\22[0c]}\00"
Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -5089,6 +5089,11 @@
 fieldType = arrayType->getElementType();
   }
 
+  if (auto arrayType = CGM.getContext().getAsIncompleteArrayType(fieldType)) {
+numElts = 0;
+fieldType = arrayType->getElementType();
+  }
+
   assert(!fieldType->isArrayType() && "ivar of non-constant array type?");
 
   // If we ended up with a zero-sized array, we've done what we can do within
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38774: [CodeGen] Add support for IncompleteArrayType in Obj-C ivars.

2017-10-23 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai updated this revision to Diff 119951.
vsapsai added a comment.

- Address rjmccall review comment about isa<>.

Decided to keep in test only cases with typedefs because test coverage is the
same and there is less similar code.


https://reviews.llvm.org/D38774

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclObjC.cpp
  clang/lib/Sema/SemaObjCProperty.cpp
  clang/test/CodeGenObjC/ivar-layout-flexible-array.m
  clang/test/Sema/transparent-union.c
  clang/test/SemaCXX/flexible-array-test.cpp
  clang/test/SemaObjC/flexible-array-arc.m
  clang/test/SemaObjC/flexible-array.m
  clang/test/SemaObjC/ivar-sem-check-1.m
  clang/test/SemaObjCXX/flexible-array.mm

Index: clang/test/SemaObjCXX/flexible-array.mm
===
--- /dev/null
+++ clang/test/SemaObjCXX/flexible-array.mm
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
+
+// Test only flexible array member functionality specific to C++.
+
+union VariableSizeUnion {
+  int s;
+  char c[];
+};
+
+@interface LastUnionIvar {
+  VariableSizeUnion flexible;
+}
+@end
+
+@interface NotLastUnionIvar {
+  VariableSizeUnion flexible; // expected-error {{field 'flexible' with variable sized type 'VariableSizeUnion' is not at the end of class}}
+  int last; // expected-note {{next instance variable declaration is here}}
+}
+@end
+
+
+class VariableSizeClass {
+public:
+  int s;
+  char c[];
+};
+
+@interface LastClassIvar {
+  VariableSizeClass flexible;
+}
+@end
+
+@interface NotLastClassIvar {
+  VariableSizeClass flexible; // expected-error {{field 'flexible' with variable sized type 'VariableSizeClass' is not at the end of class}}
+  int last; // expected-note {{next instance variable declaration is here}}
+}
+@end
Index: clang/test/SemaObjC/ivar-sem-check-1.m
===
--- clang/test/SemaObjC/ivar-sem-check-1.m
+++ clang/test/SemaObjC/ivar-sem-check-1.m
@@ -6,14 +6,15 @@
 @interface INTF
 {
 	struct F {} JJ;
-	int arr[];  // expected-error {{field has incomplete type}}
+	int arr[];  // expected-error {{flexible array member 'arr' with type 'int []' is not at the end of class}}
 	struct S IC;  // expected-error {{field has incomplete type}}
+	  // expected-note@-1 {{next instance variable declaration is here}}
 	struct T { // expected-note {{previous definition is here}}
 	  struct T {} X;  // expected-error {{nested redefinition of 'T'}}
 	}YYY; 
 	FOOBADFUNC;  // expected-error {{field 'BADFUNC' declared as a function}}
 	int kaka;	// expected-note {{previous declaration is here}}
 	int kaka;	// expected-error {{duplicate member 'kaka'}}
-	char ch[];	// expected-error {{field has incomplete type}}
+	char ch[];
 }
 @end
Index: clang/test/SemaObjC/flexible-array.m
===
--- /dev/null
+++ clang/test/SemaObjC/flexible-array.m
@@ -0,0 +1,288 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
+
+// # Flexible array member.
+// ## Instance variables only in interface.
+@interface LastIvar {
+  char flexible[];
+}
+@end
+
+@interface NotLastIvar {
+  char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char []' is not at the end of class}}
+  int last; // expected-note {{next instance variable declaration is here}}
+}
+@end
+
+// ## Instance variables in implementation.
+@interface LastIvarInImpl
+@end
+@implementation LastIvarInImpl {
+  char flexible[]; // expected-warning {{field 'flexible' with variable sized type 'char []' is not visible to subclasses and can conflict with their instance variables}}
+}
+@end
+
+@interface NotLastIvarInImpl
+@end
+@implementation NotLastIvarInImpl {
+  char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char []' is not at the end of class}}
+  // expected-warning@-1 {{field 'flexible' with variable sized type 'char []' is not visible to subclasses and can conflict with their instance variables}}
+  int last; // expected-note {{next instance variable declaration is here}}
+}
+@end
+
+@implementation NotLastIvarInImplWithoutInterface { // expected-warning {{cannot find interface declaration for 'NotLastIvarInImplWithoutInterface'}}
+  char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char []' is not at the end of class}}
+  // expected-warning@-1 {{field 'flexible' with variable sized type 'char []' is not visible to subclasses and can conflict with their instance variables}}
+  int last; // expected-note {{next instance variable declaration is here}}
+}
+@end
+
+@interface LastIvarInClass_OtherIvarInImpl {
+  char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char []' is not at the end of class}}
+}
+@end
+@implementation 

[PATCH] D39079: New clang option -fno-plt to avoid PLT for external calls

2017-10-23 Thread Sriraman Tallam via Phabricator via cfe-commits
tmsriram added inline comments.



Comment at: lib/CodeGen/CGCall.cpp:1859
+if (auto *Fn = dyn_cast(TargetDecl)) {
+  if (!Fn->isDefined() && !AttrOnCallSite) {
+FuncAttrs.addAttribute(llvm::Attribute::NonLazyBind);

rnk wrote:
> Remind me what happens when the definition is within the current DSO after 
> linking. I seem to recall that the call through memory is 6 bytes and the 
> direct pcrel call is 5 bytes, and the linker is required to know to rewrite 
> the indirect call to a nop. Is that accurate?
That's accurate, the linker rewrites it with a nop equivalent.


https://reviews.llvm.org/D39079



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


[PATCH] D38538: Avoid printing some redundant name qualifiers in completion

2017-10-23 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added inline comments.
This revision is now accepted and ready to land.



Comment at: test/CodeCompletion/qualifiers-as-written.cpp:29
+  // CHECK-2: COMPLETION: func : [#int#]func(<#foo a#>, <#bar b#>, <#ns::bar 
c#>, <#ns::baz d#>
+  // CHECK-2: COMPLETION: func : [#int#]func(<#foo::type a#>, <#bar b#>, <#baz 
c#>
+}

ilya-biryukov wrote:
> arphaman wrote:
> > Sorry, I see the issue now. However, I don't think that we'd like to change 
> > the signature for a function like this, as we'd still prefer to show `func 
> > (foo::type, ns::bar, ns::baz);` on this line.
> > 
> > In Xcode we actually avoid the problem with `std::vector<>`s that you've 
> > pointed out entirely by using `value_type`. I'll check what our solution 
> > does.
> > 
> > Btw, maybe using things like `value_type` is completely wrong (with or 
> > without the qualifier)? If we have `std::vector` shouldn't we rather 
> > show `push_back(int _Value)`, rather than the `value_type`? Perhaps this 
> > kind of change should be discussed with a wider community somehow to find 
> > out what's best for all users.
> Using `int _Value` may be good in case of `vector`, but it would 
> probably loose typedefs, i.e. `vector` would still have `int`, which 
> may be undesirable.
> Also, for `vector`, the type inside `push_back` would probably 
> end up being `vector`. 
> 
> 
> As for the current vs new behavior, I can totally see why you want to see 
> more context in completion items. 
> 
> I would argue that the current code does not do a great job there, as it only 
> adds qualifiers to unqualified references. But the context may be missing for 
> qualified references as well.
> For example, in the following code:
> ```
>   template >
>   struct vector {
> typedef T value_type;
> 
> typename value_type::some_type foo();
> value_type bar()
>   };
> ```
> 
> Completion item for `vector::bar` will have return type `vector std::allocator>::value_type`. However, completion item for `vector std::allocator>::foo` will have return type `value_type::some_type` (note 
> that no `vector` qualifier was added).
> 
> I would also question the intent of the current implementation. The following 
> line suggest that adding those qualifers was not intended in the first place:
> ```
>   Policy.SuppressUnwrittenScope = true;
> ```
> But that's just a wild guess, I may be completely wrong.
> 
> 
> That being said, I don't think there is one right preference, different 
> people may prefer different options. We can surely discuss that in a wider 
> community, though.
> 
> Would you be open to adding an option for that in completion and keeping the 
> current behavior as a default?
> 
> 
Sorry about the delay.

I clarified Xcode's behavior - we actually didn't show the qualifiers for 
typedefs and typealiases because of an older Clang, with ToT the behavior is as 
you describe.

So this patch will remove qualifiers for structs and classes, like in the 
`func` example here. I'm willing to accept it right now. We might have to 
revisit this change at some point though. Let's also keep one behavior right 
now, I don't think we need to diverge yet.



https://reviews.llvm.org/D38538



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


[PATCH] D39208: [Analyzer] Do not use static storage to for implementations created in BodyFarm.cpp

2017-10-23 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov created this revision.
Herald added subscribers: szepet, kristof.beyls, xazax.hun, javed.absar, 
aemerson.

https://reviews.llvm.org/D39208

Files:
  include/clang/Analysis/AnalysisDeclContext.h
  include/clang/Analysis/BodyFarm.h
  lib/Analysis/AnalysisDeclContext.cpp
  lib/Analysis/BodyFarm.cpp
  lib/Analysis/BodyFarm.h
  lib/StaticAnalyzer/Core/AnalysisManager.cpp

Index: lib/StaticAnalyzer/Core/AnalysisManager.cpp
===
--- lib/StaticAnalyzer/Core/AnalysisManager.cpp
+++ lib/StaticAnalyzer/Core/AnalysisManager.cpp
@@ -14,33 +14,25 @@
 
 void AnalysisManager::anchor() { }
 
-AnalysisManager::AnalysisManager(ASTContext , DiagnosticsEngine ,
- const LangOptions ,
- const PathDiagnosticConsumers ,
- StoreManagerCreator storemgr,
- ConstraintManagerCreator constraintmgr,
- CheckerManager *checkerMgr,
- AnalyzerOptions ,
- CodeInjector *injector)
-  : AnaCtxMgr(Options.UnoptimizedCFG,
-  Options.includeImplicitDtorsInCFG(),
-  /*AddInitializers=*/true,
-  Options.includeTemporaryDtorsInCFG(),
-	Options.includeLifetimeInCFG(),
-  // Adding LoopExit elements to the CFG is a requirement for loop
-  // unrolling.
-  Options.includeLoopExitInCFG() || Options.shouldUnrollLoops(),
-  Options.shouldSynthesizeBodies(),
-  Options.shouldConditionalizeStaticInitializers(),
-  /*addCXXNewAllocator=*/true,
-  injector),
-Ctx(ctx),
-Diags(diags),
-LangOpts(lang),
-PathConsumers(PDC),
-CreateStoreMgr(storemgr), CreateConstraintMgr(constraintmgr),
-CheckerMgr(checkerMgr),
-options(Options) {
+AnalysisManager::AnalysisManager(
+ASTContext , DiagnosticsEngine , const LangOptions ,
+const PathDiagnosticConsumers , StoreManagerCreator storemgr,
+ConstraintManagerCreator constraintmgr, CheckerManager *checkerMgr,
+AnalyzerOptions , CodeInjector *injector)
+: AnaCtxMgr(ASTCtx, Options.UnoptimizedCFG,
+Options.includeImplicitDtorsInCFG(),
+/*AddInitializers=*/true, Options.includeTemporaryDtorsInCFG(),
+Options.includeLifetimeInCFG(),
+// Adding LoopExit elements to the CFG is a requirement for loop
+// unrolling.
+Options.includeLoopExitInCFG() || Options.shouldUnrollLoops(),
+Options.shouldSynthesizeBodies(),
+Options.shouldConditionalizeStaticInitializers(),
+/*addCXXNewAllocator=*/true,
+injector),
+  Ctx(ASTCtx), Diags(diags), LangOpts(lang), PathConsumers(PDC),
+  CreateStoreMgr(storemgr), CreateConstraintMgr(constraintmgr),
+  CheckerMgr(checkerMgr), options(Options) {
   AnaCtxMgr.getCFGBuildOptions().setAllAlwaysAdd();
 }
 
Index: lib/Analysis/BodyFarm.cpp
===
--- lib/Analysis/BodyFarm.cpp
+++ lib/Analysis/BodyFarm.cpp
@@ -12,7 +12,7 @@
 //
 //===--===//
 
-#include "BodyFarm.h"
+#include "clang/Analysis/BodyFarm.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/Decl.h"
Index: lib/Analysis/AnalysisDeclContext.cpp
===
--- lib/Analysis/AnalysisDeclContext.cpp
+++ lib/Analysis/AnalysisDeclContext.cpp
@@ -13,7 +13,6 @@
 //===--===//
 
 #include "clang/Analysis/AnalysisDeclContext.h"
-#include "BodyFarm.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclObjC.h"
@@ -23,6 +22,7 @@
 #include "clang/Analysis/Analyses/CFGReachabilityAnalysis.h"
 #include "clang/Analysis/Analyses/LiveVariables.h"
 #include "clang/Analysis/Analyses/PseudoConstantAnalysis.h"
+#include "clang/Analysis/BodyFarm.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Analysis/CFGStmtMap.h"
 #include "clang/Analysis/Support/BumpVector.h"
@@ -63,18 +63,12 @@
   cfgBuildOptions.forcedBlkExprs = 
 }
 
-AnalysisDeclContextManager::AnalysisDeclContextManager(bool useUnoptimizedCFG,
-   bool addImplicitDtors,
-   bool addInitializers,
-   bool addTemporaryDtors,
-   bool addLifetime,
-   bool addLoopExit,
-   bool synthesizeBodies,
- 

[PATCH] D39079: New clang option -fno-plt to avoid PLT for external calls

2017-10-23 Thread Sriraman Tallam via Phabricator via cfe-commits
tmsriram updated this revision to Diff 119950.
tmsriram added a comment.

Added test test/CodeGen/noplt.c


https://reviews.llvm.org/D39079

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGCall.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/noplt.c


Index: test/CodeGen/noplt.c
===
--- test/CodeGen/noplt.c
+++ test/CodeGen/noplt.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -emit-llvm -fno-plt %s -o - | FileCheck %s 
-check-prefix=CHECK-NOPLT
+
+// CHECK-NOPLT: Function Attrs: nonlazybind
+// CHECK-NOPLT-NEXT: declare i32 @foo
+int foo();
+
+int bar() {
+  return foo();
+}
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -650,6 +650,7 @@
   Args.hasArg(OPT_mincremental_linker_compatible);
   Opts.PIECopyRelocations =
   Args.hasArg(OPT_mpie_copy_relocations);
+  Opts.NoPLT = Args.hasArg(OPT_fno_plt);
   Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer);
   Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels);
   Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm);
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3386,6 +3386,10 @@
 CmdArgs.push_back("-mpie-copy-relocations");
   }
 
+  if (Args.hasFlag(options::OPT_fno_plt, options::OPT_fplt, false)) {
+CmdArgs.push_back("-fno-plt");
+  }
+
   // -fhosted is default.
   // TODO: Audit uses of KernelOrKext and see where it'd be more appropriate to
   // use Freestanding.
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -1852,6 +1852,16 @@
   !(TargetDecl && TargetDecl->hasAttr()))
 FuncAttrs.addAttribute("split-stack");
 
+  // Add NonLazyBind attribute to function declarations when -fno-plt
+  // is used.
+  if (TargetDecl && CodeGenOpts.NoPLT) {
+if (auto *Fn = dyn_cast(TargetDecl)) {
+  if (!Fn->isDefined() && !AttrOnCallSite) {
+FuncAttrs.addAttribute(llvm::Attribute::NonLazyBind);
+  }
+}
+  }
+
   if (!AttrOnCallSite) {
 bool DisableTailCalls =
 CodeGenOpts.DisableTailCalls ||
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -294,6 +294,8 @@
 /// Whether to emit .debug_gnu_pubnames section instead of .debug_pubnames.
 CODEGENOPT(GnuPubnames, 1, 0)
 
+CODEGENOPT(NoPLT, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1363,6 +1363,10 @@
 def fno_pic : Flag<["-"], "fno-pic">, Group;
 def fpie : Flag<["-"], "fpie">, Group;
 def fno_pie : Flag<["-"], "fno-pie">, Group;
+def fplt : Flag<["-"], "fplt">, Group, Flags<[CC1Option]>,
+  HelpText<"Use the PLT to make function calls">;
+def fno_plt : Flag<["-"], "fno-plt">, Group, Flags<[CC1Option]>,
+  HelpText<"Do not use the PLT to make function calls">;
 def fropi : Flag<["-"], "fropi">, Group;
 def fno_ropi : Flag<["-"], "fno-ropi">, Group;
 def frwpi : Flag<["-"], "frwpi">, Group;


Index: test/CodeGen/noplt.c
===
--- test/CodeGen/noplt.c
+++ test/CodeGen/noplt.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -emit-llvm -fno-plt %s -o - | FileCheck %s -check-prefix=CHECK-NOPLT
+
+// CHECK-NOPLT: Function Attrs: nonlazybind
+// CHECK-NOPLT-NEXT: declare i32 @foo
+int foo();
+
+int bar() {
+  return foo();
+}
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -650,6 +650,7 @@
   Args.hasArg(OPT_mincremental_linker_compatible);
   Opts.PIECopyRelocations =
   Args.hasArg(OPT_mpie_copy_relocations);
+  Opts.NoPLT = Args.hasArg(OPT_fno_plt);
   Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer);
   Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels);
   Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm);
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3386,6 +3386,10 @@
 CmdArgs.push_back("-mpie-copy-relocations");
   }
 
+  if (Args.hasFlag(options::OPT_fno_plt, options::OPT_fplt, false)) {
+CmdArgs.push_back("-fno-plt");
+  }
+
   // 

[PATCH] D38774: [CodeGen] Add support for IncompleteArrayType in Obj-C ivars.

2017-10-23 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added inline comments.



Comment at: clang/lib/CodeGen/CGObjCMac.cpp:5095
+fieldType = fieldType->getAsArrayTypeUnsafe()->getElementType();
+  }
+

rjmccall wrote:
> You can't just use isa<> here; there can be typedefs of incomplete array type.
Thanks for catching it.


https://reviews.llvm.org/D38774



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


[PATCH] D39069: CodeGen: Fix missing debug loc due to alloca

2017-10-23 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

The code looks fine to me.  The test seems very vague to me, but I'd like Dave 
to weigh in on that, because I'm not sure it's reasonable to test the exact 
pattern here.

Also, Dave, I don't know what the IR invariants around debug info are.  Is this 
something we should be updating all of our uses of saveIP() to do if there's a 
possibility of emitting arbitrary code while the IP is saved?


https://reviews.llvm.org/D39069



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


[PATCH] D39201: [Analyzer] Handle implicit function reference in bodyfarming std::call_once

2017-10-23 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

LGTM!


https://reviews.llvm.org/D39201



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


[PATCH] D38773: [Sema] Add support for flexible array members in Obj-C.

2017-10-23 Thread Volodymyr Sapsai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316381: [Sema] Add support for flexible array members in 
Obj-C. (authored by vsapsai).

Changed prior to commit:
  https://reviews.llvm.org/D38773?vs=118990=119943#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38773

Files:
  cfe/trunk/include/clang/Basic/DiagnosticGroups.td
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Sema/SemaDeclObjC.cpp
  cfe/trunk/lib/Sema/SemaObjCProperty.cpp
  cfe/trunk/test/Sema/transparent-union.c
  cfe/trunk/test/SemaCXX/flexible-array-test.cpp
  cfe/trunk/test/SemaObjC/flexible-array-arc.m
  cfe/trunk/test/SemaObjC/flexible-array.m
  cfe/trunk/test/SemaObjC/ivar-sem-check-1.m
  cfe/trunk/test/SemaObjCXX/flexible-array.mm

Index: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
===
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp
@@ -1290,6 +1290,14 @@
 // An abstract type is as bad as an incomplete type.
 CompleteTypeErr = true;
   }
+  if (!CompleteTypeErr) {
+const RecordType *RecordTy = PropertyIvarType->getAs();
+if (RecordTy && RecordTy->getDecl()->hasFlexibleArrayMember()) {
+  Diag(PropertyIvarLoc, diag::err_synthesize_variable_sized_ivar)
+<< PropertyIvarType;
+  CompleteTypeErr = true; // suppress later diagnostics about the ivar
+}
+  }
   if (CompleteTypeErr)
 Ivar->setInvalidDecl();
   ClassImpDecl->addDecl(Ivar);
Index: cfe/trunk/lib/Sema/SemaDecl.cpp
===
--- cfe/trunk/lib/Sema/SemaDecl.cpp
+++ cfe/trunk/lib/Sema/SemaDecl.cpp
@@ -14997,67 +14997,78 @@
 //   possibly recursively, a member that is such a structure)
 //   shall not be a member of a structure or an element of an
 //   array.
+bool IsLastField = (i + 1 == Fields.end());
 if (FDTy->isFunctionType()) {
   // Field declared as a function.
   Diag(FD->getLocation(), diag::err_field_declared_as_function)
 << FD->getDeclName();
   FD->setInvalidDecl();
   EnclosingDecl->setInvalidDecl();
   continue;
-} else if (FDTy->isIncompleteArrayType() && Record &&
-   ((i + 1 == Fields.end() && !Record->isUnion()) ||
-((getLangOpts().MicrosoftExt ||
-  getLangOpts().CPlusPlus) &&
- (i + 1 == Fields.end() || Record->isUnion() {
-  // Flexible array member.
-  // Microsoft and g++ is more permissive regarding flexible array.
-  // It will accept flexible array in union and also
-  // as the sole element of a struct/class.
-  unsigned DiagID = 0;
-  if (Record->isUnion())
-DiagID = getLangOpts().MicrosoftExt
- ? diag::ext_flexible_array_union_ms
- : getLangOpts().CPlusPlus
-   ? diag::ext_flexible_array_union_gnu
-   : diag::err_flexible_array_union;
-  else if (NumNamedMembers < 1)
-DiagID = getLangOpts().MicrosoftExt
- ? diag::ext_flexible_array_empty_aggregate_ms
- : getLangOpts().CPlusPlus
-   ? diag::ext_flexible_array_empty_aggregate_gnu
-   : diag::err_flexible_array_empty_aggregate;
-
-  if (DiagID)
-Diag(FD->getLocation(), DiagID) << FD->getDeclName()
-<< Record->getTagKind();
-  // While the layout of types that contain virtual bases is not specified
-  // by the C++ standard, both the Itanium and Microsoft C++ ABIs place
-  // virtual bases after the derived members.  This would make a flexible
-  // array member declared at the end of an object not adjacent to the end
-  // of the type.
-  if (CXXRecordDecl *RD = dyn_cast(Record))
-if (RD->getNumVBases() != 0)
-  Diag(FD->getLocation(), diag::err_flexible_array_virtual_base)
+} else if (FDTy->isIncompleteArrayType() &&
+   (Record || isa(EnclosingDecl))) {
+  if (Record) {
+// Flexible array member.
+// Microsoft and g++ is more permissive regarding flexible array.
+// It will accept flexible array in union and also
+// as the sole element of a struct/class.
+unsigned DiagID = 0;
+if (!Record->isUnion() && !IsLastField) {
+  Diag(FD->getLocation(), diag::err_flexible_array_not_at_end)
+<< FD->getDeclName() << FD->getType() << Record->getTagKind();
+  Diag((*(i + 1))->getLocation(), diag::note_next_field_declaration);
+  FD->setInvalidDecl();
+  EnclosingDecl->setInvalidDecl();
+  continue;
+} else if (Record->isUnion())
+  DiagID = getLangOpts().MicrosoftExt
+   ? 

r316381 - [Sema] Add support for flexible array members in Obj-C.

2017-10-23 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Mon Oct 23 15:01:41 2017
New Revision: 316381

URL: http://llvm.org/viewvc/llvm-project?rev=316381=rev
Log:
[Sema] Add support for flexible array members in Obj-C.

Allow Obj-C ivars with incomplete array type but only as the last ivar.
Also add a requirement for ivars that contain a flexible array member to
be at the end of class too. It is possible to add in a subclass another
ivar at the end but we'll emit a warning in this case. Also we'll emit a
warning if a variable sized ivar is declared in class extension or in
implementation because subclasses won't know they should avoid adding
new ivars.

In ARC incomplete array objects are treated as __unsafe_unretained so
require them to be marked as such.

Prohibit synthesizing ivars with flexible array members because order of
synthesized ivars is not obvious and tricky to control. Spelling out
ivar explicitly gives control to developers and helps to avoid surprises
with unexpected ivar ordering.

For C and C++ changed diagnostic to tell explicitly a field is not the
last one and point to the next field. It is not as useful as in Obj-C
but it is an improvement and it is consistent with Obj-C. For C for
unions emit more specific err_flexible_array_union instead of generic
err_field_incomplete.

rdar://problem/21054495

Reviewers: rjmccall, theraven

Reviewed By: rjmccall

Subscribers: cfe-commits

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


Added:
cfe/trunk/test/SemaObjC/flexible-array-arc.m
cfe/trunk/test/SemaObjC/flexible-array.m
cfe/trunk/test/SemaObjCXX/flexible-array.mm
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/lib/Sema/SemaObjCProperty.cpp
cfe/trunk/test/Sema/transparent-union.c
cfe/trunk/test/SemaCXX/flexible-array-test.cpp
cfe/trunk/test/SemaObjC/ivar-sem-check-1.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=316381=316380=316381=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Mon Oct 23 15:01:41 2017
@@ -374,6 +374,7 @@ def ObjCRootClass : DiagGroup<"objc-root
 def ObjCPointerIntrospectPerformSelector : 
DiagGroup<"deprecated-objc-pointer-introspection-performSelector">;
 def ObjCPointerIntrospect : DiagGroup<"deprecated-objc-pointer-introspection", 
[ObjCPointerIntrospectPerformSelector]>;
 def ObjCMultipleMethodNames : DiagGroup<"objc-multiple-method-names">;
+def ObjCFlexibleArray : DiagGroup<"objc-flexible-array">;
 def OpenCLUnsupportedRGBA: DiagGroup<"opencl-unsupported-rgba">;
 def DeprecatedObjCIsaUsage : DiagGroup<"deprecated-objc-isa-usage">;
 def ExplicitInitializeCall : DiagGroup<"explicit-initialize-call">;
@@ -750,6 +751,7 @@ def Most : DiagGroup<"most", [
 VolatileRegisterVar,
 ObjCMissingSuperCalls,
 ObjCDesignatedInit,
+ObjCFlexibleArray,
 OverloadedVirtual,
 PrivateExtern,
 SelTypeCast,

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=316381=316380=316381=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Oct 23 15:01:41 
2017
@@ -5222,6 +5222,28 @@ def ext_flexible_array_empty_aggregate_g
 def ext_flexible_array_union_gnu : Extension<
   "flexible array member %0 in a union is a GNU extension">, 
InGroup;
 
+def err_flexible_array_not_at_end : Error<
+  "flexible array member %0 with type %1 is not at the end of"
+  " %select{struct|interface|union|class|enum}2">;
+def err_objc_variable_sized_type_not_at_end : Error<
+  "field %0 with variable sized type %1 is not at the end of class">;
+def note_next_field_declaration : Note<
+  "next field declaration is here">;
+def note_next_ivar_declaration : Note<
+  "next %select{instance variable declaration|synthesized instance variable}0"
+  " is here">;
+def err_synthesize_variable_sized_ivar : Error<
+  "synthesized property with variable size type %0"
+  " requires an existing instance variable">;
+def err_flexible_array_arc_retainable : Error<
+  "ARC forbids flexible array members with retainable object type">;
+def warn_variable_sized_ivar_visibility : Warning<
+  "field %0 with variable sized type %1 is not visible to subclasses and"
+  " can conflict with their instance variables">, InGroup;
+def warn_superclass_variable_sized_type_not_at_end : Warning<
+  "field %0 can overwrite instance variable %1 with variable sized type %2"
+  " in superclass %3">, InGroup;
+
 let CategoryName = "ARC 

[PATCH] D38939: [clangd] Handle exit notification (proper shutdown)

2017-10-23 Thread Raoul Wols via Phabricator via cfe-commits
rwols marked 3 inline comments as done.
rwols added a comment.

> you have commit access now, right?

I'll have to think about if I want that responsibility!


https://reviews.llvm.org/D38939



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


[PATCH] D39204: [CodeGen] __builtin_sqrt should map to the compiler's intrinsic sqrt function

2017-10-23 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

The gcc documentation says "GCC includes built-in versions of many of the 
functions in the standard C library. These functions come in two forms: one 
whose names start with the `__builtin_` prefix, and the other without. Both 
forms have the same type (including prototype), the same address (when their 
address is taken), and the same meaning as the C library functions".  And gcc 
specifically preserves the stated semantics.  Given that, I'm not sure it makes 
sense for us to try to redefine `__builtin_sqrt()` just because it's convenient.

Note that this reasoning only applies if the user hasn't specified any 
fast-math flags; under -ffinite-math-only, we can assume the result isn't a 
NaN, and therefore we can use `llvm.sqrt.*`. (The definition of `llvm.sqrt.*` 
changed in https://reviews.llvm.org/D28797; I don't think we ever updated clang 
to take advantage of this).

If we really need a name for the never-sets-errno sqrt, we should probably use 
a different name, e.g. `__builtin_ieee_sqrt()`.


https://reviews.llvm.org/D39204



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


[PATCH] D38939: [clangd] Handle exit notification (proper shutdown)

2017-10-23 Thread Raoul Wols via Phabricator via cfe-commits
rwols updated this revision to Diff 119941.
rwols added a comment.

- Clarify why we invert the tests in protocol.test,
- Use a variable name to clarify why we exit with status code 1 (when run() 
returns true),
- Reword misleading comment in onShutdown method.


https://reviews.llvm.org/D38939

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/Protocol.h
  clangd/ProtocolHandlers.cpp
  clangd/ProtocolHandlers.h
  clangd/tool/ClangdMain.cpp
  test/clangd/authority-less-uri.test
  test/clangd/completion-priorities.test
  test/clangd/completion-qualifiers.test
  test/clangd/completion-snippet.test
  test/clangd/completion.test
  test/clangd/definitions.test
  test/clangd/diagnostics-preamble.test
  test/clangd/diagnostics.test
  test/clangd/did-change-watch-files.test
  test/clangd/extra-flags.test
  test/clangd/fixits.test
  test/clangd/formatting.test
  test/clangd/initialize-params-invalid.test
  test/clangd/initialize-params.test
  test/clangd/input-mirror.test
  test/clangd/protocol.test
  test/clangd/shutdown-with-exit.test
  test/clangd/shutdown-without-exit.test
  test/clangd/signature-help.test
  test/clangd/unsupported-method.test

Index: test/clangd/unsupported-method.test
===
--- test/clangd/unsupported-method.test
+++ test/clangd/unsupported-method.test
@@ -17,3 +17,7 @@
 Content-Length: 44
 
 {"jsonrpc":"2.0","id":2,"method":"shutdown"}
+# CHECK: {"jsonrpc":"2.0","id":2,"result":null}
+Content-Length: 33
+
+{"jsonrpc":"2.0":"method":"exit"}
Index: test/clangd/signature-help.test
===
--- test/clangd/signature-help.test
+++ test/clangd/signature-help.test
@@ -40,3 +40,7 @@
 Content-Length: 49
 
 {"jsonrpc":"2.0","id":10,"method":"shutdown"}
+# CHECK: {"jsonrpc":"2.0","id":10,"result":null}
+Content-Length: 33
+
+{"jsonrpc":"2.0":"method":"exit"}
Index: test/clangd/shutdown-without-exit.test
===
--- /dev/null
+++ test/clangd/shutdown-without-exit.test
@@ -0,0 +1,6 @@
+# RUN: not clangd -run-synchronously < %s
+# vim: fileformat=dos
+# It is absolutely vital that this file has CRLF line endings.
+Content-Length: 33
+
+{"jsonrpc":"2.0":"method":"exit"}
Index: test/clangd/shutdown-with-exit.test
===
--- /dev/null
+++ test/clangd/shutdown-with-exit.test
@@ -0,0 +1,9 @@
+# RUN: clangd -run-synchronously < %s
+# vim: fileformat=dos
+# It is absolutely vital that this file has CRLF line endings.
+Content-Length: 44
+
+{"jsonrpc":"2.0","id":3,"method":"shutdown"}
+Content-Length: 33
+
+{"jsonrpc":"2.0":"method":"exit"}
Index: test/clangd/protocol.test
===
--- test/clangd/protocol.test
+++ test/clangd/protocol.test
@@ -1,8 +1,10 @@
-# RUN: clangd -run-synchronously < %s | FileCheck %s
-# RUN: clangd -run-synchronously < %s 2>&1 | FileCheck -check-prefix=STDERR %s
+# RUN: not clangd -run-synchronously < %s | FileCheck %s
+# RUN: not clangd -run-synchronously < %s 2>&1 | FileCheck -check-prefix=STDERR %s
 # vim: fileformat=dos
 # It is absolutely vital that this file has CRLF line endings.
 #
+# Note that we invert the test because we intent to let clangd exit prematurely.
+#
 # Test protocol parsing
 Content-Length: 125
 Content-Type: application/vscode-jsonrpc; charset-utf-8
Index: test/clangd/input-mirror.test
===
--- test/clangd/input-mirror.test
+++ test/clangd/input-mirror.test
@@ -152,3 +152,7 @@
 Content-Length: 44
 
 {"jsonrpc":"2.0","id":3,"method":"shutdown"}
+# CHECK: {"jsonrpc":"2.0","id":3,"result":null}
+Content-Length: 33
+
+{"jsonrpc":"2.0":"method":"exit"}
Index: test/clangd/initialize-params.test
===
--- test/clangd/initialize-params.test
+++ test/clangd/initialize-params.test
@@ -20,3 +20,7 @@
 Content-Length: 44
 
 {"jsonrpc":"2.0","id":3,"method":"shutdown"}
+# CHECK: {"jsonrpc":"2.0","id":3,"result":null}
+Content-Length: 33
+
+{"jsonrpc":"2.0":"method":"exit"}
Index: test/clangd/initialize-params-invalid.test
===
--- test/clangd/initialize-params-invalid.test
+++ test/clangd/initialize-params-invalid.test
@@ -20,3 +20,7 @@
 Content-Length: 44
 
 {"jsonrpc":"2.0","id":3,"method":"shutdown"}
+# CHECK: {"jsonrpc":"2.0","id":3,"result":null}
+Content-Length: 33
+
+{"jsonrpc":"2.0":"method":"exit"}
Index: test/clangd/formatting.test
===
--- test/clangd/formatting.test
+++ test/clangd/formatting.test
@@ -65,3 +65,7 @@
 Content-Length: 44
 
 {"jsonrpc":"2.0","id":6,"method":"shutdown"}
+# CHECK: {"jsonrpc":"2.0","id":6,"result":null}
+Content-Length: 33
+
+{"jsonrpc":"2.0":"method":"exit"}
Index: 

[PATCH] D39206: [libunwind] Add missing checks for register number

2017-10-23 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.
Herald added a subscriber: JDevlieghere.

Most other cases that touch `savedRegisters[reg]` have got this check, but 
these three seemed to lack it.


https://reviews.llvm.org/D39206

Files:
  src/DwarfParser.hpp


Index: src/DwarfParser.hpp
===
--- src/DwarfParser.hpp
+++ src/DwarfParser.hpp
@@ -605,6 +605,11 @@
   break;
 case DW_CFA_val_offset:
   reg = addressSpace.getULEB128(p, instructionsEnd);
+  if (reg > kMaxRegisterNumber) {
+fprintf(stderr,
+"malformed DW_CFA_val_offset DWARF unwind, reg too big\n");
+return false;
+  }
   offset = (int64_t)addressSpace.getULEB128(p, instructionsEnd)
 * cieInfo.dataAlignFactor;
   results->savedRegisters[reg].location = kRegisterOffsetFromCFA;
@@ -668,6 +673,11 @@
   switch (opcode & 0xC0) {
   case DW_CFA_offset:
 reg = operand;
+if (reg > kMaxRegisterNumber) {
+  fprintf(stderr,
+  "malformed DW_CFA_offset DWARF unwind, reg too big\n");
+  return false;
+}
 offset = (int64_t)addressSpace.getULEB128(p, instructionsEnd)
 * cieInfo.dataAlignFactor;
 results->savedRegisters[reg].location = kRegisterInCFA;
@@ -682,6 +692,11 @@
 break;
   case DW_CFA_restore:
 reg = operand;
+if (reg > kMaxRegisterNumber) {
+  fprintf(stderr,
+  "malformed DW_CFA_restore DWARF unwind, reg too big\n");
+  return false;
+}
 results->savedRegisters[reg] = initialState.savedRegisters[reg];
 _LIBUNWIND_TRACE_DWARF("DW_CFA_restore(reg=%" PRIu64 ")\n",
static_cast(operand));


Index: src/DwarfParser.hpp
===
--- src/DwarfParser.hpp
+++ src/DwarfParser.hpp
@@ -605,6 +605,11 @@
   break;
 case DW_CFA_val_offset:
   reg = addressSpace.getULEB128(p, instructionsEnd);
+  if (reg > kMaxRegisterNumber) {
+fprintf(stderr,
+"malformed DW_CFA_val_offset DWARF unwind, reg too big\n");
+return false;
+  }
   offset = (int64_t)addressSpace.getULEB128(p, instructionsEnd)
 * cieInfo.dataAlignFactor;
   results->savedRegisters[reg].location = kRegisterOffsetFromCFA;
@@ -668,6 +673,11 @@
   switch (opcode & 0xC0) {
   case DW_CFA_offset:
 reg = operand;
+if (reg > kMaxRegisterNumber) {
+  fprintf(stderr,
+  "malformed DW_CFA_offset DWARF unwind, reg too big\n");
+  return false;
+}
 offset = (int64_t)addressSpace.getULEB128(p, instructionsEnd)
 * cieInfo.dataAlignFactor;
 results->savedRegisters[reg].location = kRegisterInCFA;
@@ -682,6 +692,11 @@
 break;
   case DW_CFA_restore:
 reg = operand;
+if (reg > kMaxRegisterNumber) {
+  fprintf(stderr,
+  "malformed DW_CFA_restore DWARF unwind, reg too big\n");
+  return false;
+}
 results->savedRegisters[reg] = initialState.savedRegisters[reg];
 _LIBUNWIND_TRACE_DWARF("DW_CFA_restore(reg=%" PRIu64 ")\n",
static_cast(operand));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r316379 - [Driver] Use ld.lld directly for Fuchsia rather than passing flavor

2017-10-23 Thread Rui Ueyama via cfe-commits
Nice. Dispatching based on argv[0] is more common and probably a
recommended way now, so this patch aligned with that.

On Mon, Oct 23, 2017 at 2:31 PM, Petr Hosek via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: phosek
> Date: Mon Oct 23 14:31:05 2017
> New Revision: 316379
>
> URL: http://llvm.org/viewvc/llvm-project?rev=316379=rev
> Log:
> [Driver] Use ld.lld directly for Fuchsia rather than passing flavor
>
> Passing a flavor to LLD requires command line argument, but if these
> are being passed through a response file, this will fail because LLD
> needs to know which driver to use before processing the response file.
> Use ld.lld directly instead to avoid this issue.
>
> Differential Revision: https://reviews.llvm.org/D39176
>
> Modified:
> cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
> cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
> cfe/trunk/test/Driver/fuchsia.c
> cfe/trunk/test/Driver/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=316379=316378=316379=diff
> 
> ==
> --- cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp Mon Oct 23 14:31:05 2017
> @@ -44,10 +44,8 @@ void fuchsia::Linker::ConstructJob(Compi
>Args.ClaimAllArgs(options::OPT_w);
>
>const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
> -  if (llvm::sys::path::stem(Exec).equals_lower("lld")) {
> -CmdArgs.push_back("-flavor");
> -CmdArgs.push_back("gnu");
> -
> +  if (llvm::sys::path::filename(Exec).equals_lower("ld.lld") ||
> +  llvm::sys::path::stem(Exec).equals_lower("ld.lld")) {
>  CmdArgs.push_back("-z");
>  CmdArgs.push_back("rodynamic");
>}
>
> Modified: cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/
> ToolChains/Fuchsia.h?rev=316379=316378=316379=diff
> 
> ==
> --- cfe/trunk/lib/Driver/ToolChains/Fuchsia.h (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.h Mon Oct 23 14:31:05 2017
> @@ -82,7 +82,7 @@ public:
> llvm::opt::ArgStringList ) const
> override;
>
>const char *getDefaultLinker() const override {
> -return "lld";
> +return "ld.lld";
>}
>
>  protected:
>
> Modified: cfe/trunk/test/Driver/fuchsia.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/
> fuchsia.c?rev=316379=316378=316379=diff
> 
> ==
> --- cfe/trunk/test/Driver/fuchsia.c (original)
> +++ cfe/trunk/test/Driver/fuchsia.c Mon Oct 23 14:31:05 2017
> @@ -1,16 +1,15 @@
>  // RUN: %clang %s -### -no-canonical-prefixes --target=x86_64-unknown-fuchsia
> \
> -// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \
> +// RUN: --sysroot=%S/platform 2>&1 \
>  // RUN: | FileCheck -check-prefixes=CHECK,CHECK-X86_64 %s
>  // RUN: %clang %s -### -no-canonical-prefixes 
> --target=aarch64-unknown-fuchsia
> \
> -// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \
> +// RUN: --sysroot=%S/platform 2>&1 \
>  // RUN: | FileCheck -check-prefixes=CHECK,CHECK-AARCH64 %s
>  // CHECK: {{.*}}clang{{.*}}" "-cc1"
>  // CHECK: "-munwind-tables"
>  // CHECK: "-fuse-init-array"
>  // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
>  // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
> -// CHECK: {{.*}}lld{{.*}}" "-flavor" "gnu"
> -// CHECK: "-z" "rodynamic"
> +// CHECK: {{.*}}ld.lld{{.*}}" "-z" "rodynamic"
>  // CHECK: "--sysroot=[[SYSROOT]]"
>  // CHECK: "-pie"
>  // CHECK: "--build-id"
>
> Modified: cfe/trunk/test/Driver/fuchsia.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/
> fuchsia.cpp?rev=316379=316378=316379=diff
> 
> ==
> --- cfe/trunk/test/Driver/fuchsia.cpp (original)
> +++ cfe/trunk/test/Driver/fuchsia.cpp Mon Oct 23 14:31:05 2017
> @@ -1,13 +1,12 @@
>  // RUN: %clangxx %s -### -no-canonical-prefixes 
> --target=x86_64-unknown-fuchsia
> \
> -// RUN: --sysroot=%S/platform 2>&1 -fuse-ld=ld | FileCheck %s
> +// RUN: --sysroot=%S/platform 2>&1 | FileCheck %s
>  // CHECK: {{.*}}clang{{.*}}" "-cc1"
>  // CHECK: "-triple" "x86_64-fuchsia"
>  // CHECK: "-fuse-init-array"
>  // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
>  // CHECK: "-internal-isystem" "{{.*[/\\]}}x86_64-fuchsia{{/|
> }}include{{/|}}c++{{/|}}v1"
>  // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
> -// CHECK: {{.*}}lld{{.*}}" "-flavor" "gnu"
> -// CHECK: "-z" "rodynamic"
> +// CHECK: {{.*}}ld.lld{{.*}}" "-z" "rodynamic"
>  // CHECK: "--sysroot=[[SYSROOT]]"
>  // CHECK: "-pie"
>  // CHECK: "--build-id"
>
>
> ___
> cfe-commits mailing list
> 

[PATCH] D38819: [libunwind] Add support for dwarf unwinding on windows on x86_64

2017-10-23 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added inline comments.



Comment at: src/UnwindRegistersRestore.S:98
+  # skip fs
+  # skip gs
+  movq  56(%rcx), %rsp  # cut back rsp to new location

rnk wrote:
> mstorsjo wrote:
> > mstorsjo wrote:
> > > compnerd wrote:
> > > > Doesn't Win64 ABI require some of the MMX registers be saved/restored 
> > > > too?
> > > Right, yes, xmm6-xmm15 should be backed up and restored. I'll try to 
> > > amend this with such a change.
> > Actually, such a change doesn't necessarily make much sense on its own.
> > 
> > As long as the dwarf encoding itself doesn't describe how to restore those 
> > registers (and on unix platforms you don't need to, so it probably isn't 
> > even specified), you'd just end up backing up the xmm registers on entry 
> > when throwing the exception, and restoring the exactly same ones again - it 
> > only guards against changes within libcxxabi/libunwind and the unwinding 
> > machinery itself, not against changes further down in the call stack 
> > between the thrower and catcher of the exception.
> > 
> > So with that, I guess this patch is futile unless planning to extend the 
> > x86_64 dwarf handling in llvm to include those registers as well - and 
> > that's a little out of scope of what I intended to do here...
> If we have XMM values in the register context, we might as well reload them 
> here. I assume libunwind will switch away from DWARF and over to UNWIND_INFO 
> opcodes in the near future, and that will give us an accurate register 
> context.
Yeah, although to do anything useful with the XMM registers, the llvm backend 
would have to output dwarf opcodes for callee saved xmm registers, which it 
currently doesn't. Otherwise it'll just reload them back to the same values as 
they already are. I've managed to hack LLVM to do that (without fully 
understanding what I'm doing though), and I'll see if I manage to update 
libunwind to use that as well. 


https://reviews.llvm.org/D38819



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


[PATCH] D39176: [Driver] Use ld.lld directly for Fuchsia rather than passing flavor

2017-10-23 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316379: [Driver] Use ld.lld directly for Fuchsia rather than 
passing flavor (authored by phosek).

Changed prior to commit:
  https://reviews.llvm.org/D39176?vs=119923=119938#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39176

Files:
  cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
  cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
  cfe/trunk/test/Driver/fuchsia.c
  cfe/trunk/test/Driver/fuchsia.cpp


Index: cfe/trunk/test/Driver/fuchsia.c
===
--- cfe/trunk/test/Driver/fuchsia.c
+++ cfe/trunk/test/Driver/fuchsia.c
@@ -1,16 +1,15 @@
 // RUN: %clang %s -### -no-canonical-prefixes --target=x86_64-unknown-fuchsia \
-// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \
+// RUN: --sysroot=%S/platform 2>&1 \
 // RUN: | FileCheck -check-prefixes=CHECK,CHECK-X86_64 %s
 // RUN: %clang %s -### -no-canonical-prefixes --target=aarch64-unknown-fuchsia 
\
-// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \
+// RUN: --sysroot=%S/platform 2>&1 \
 // RUN: | FileCheck -check-prefixes=CHECK,CHECK-AARCH64 %s
 // CHECK: {{.*}}clang{{.*}}" "-cc1"
 // CHECK: "-munwind-tables"
 // CHECK: "-fuse-init-array"
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
-// CHECK: {{.*}}lld{{.*}}" "-flavor" "gnu"
-// CHECK: "-z" "rodynamic"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "rodynamic"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"
Index: cfe/trunk/test/Driver/fuchsia.cpp
===
--- cfe/trunk/test/Driver/fuchsia.cpp
+++ cfe/trunk/test/Driver/fuchsia.cpp
@@ -1,13 +1,12 @@
 // RUN: %clangxx %s -### -no-canonical-prefixes 
--target=x86_64-unknown-fuchsia \
-// RUN: --sysroot=%S/platform 2>&1 -fuse-ld=ld | FileCheck %s
+// RUN: --sysroot=%S/platform 2>&1 | FileCheck %s
 // CHECK: {{.*}}clang{{.*}}" "-cc1"
 // CHECK: "-triple" "x86_64-fuchsia"
 // CHECK: "-fuse-init-array"
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK: "-internal-isystem" 
"{{.*[/\\]}}x86_64-fuchsia{{/|}}include{{/|}}c++{{/|}}v1"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
-// CHECK: {{.*}}lld{{.*}}" "-flavor" "gnu"
-// CHECK: "-z" "rodynamic"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "rodynamic"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"
Index: cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
@@ -44,10 +44,8 @@
   Args.ClaimAllArgs(options::OPT_w);
 
   const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
-  if (llvm::sys::path::stem(Exec).equals_lower("lld")) {
-CmdArgs.push_back("-flavor");
-CmdArgs.push_back("gnu");
-
+  if (llvm::sys::path::filename(Exec).equals_lower("ld.lld") ||
+  llvm::sys::path::stem(Exec).equals_lower("ld.lld")) {
 CmdArgs.push_back("-z");
 CmdArgs.push_back("rodynamic");
   }
Index: cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
===
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
@@ -82,7 +82,7 @@
llvm::opt::ArgStringList ) const override;
 
   const char *getDefaultLinker() const override {
-return "lld";
+return "ld.lld";
   }
 
 protected:


Index: cfe/trunk/test/Driver/fuchsia.c
===
--- cfe/trunk/test/Driver/fuchsia.c
+++ cfe/trunk/test/Driver/fuchsia.c
@@ -1,16 +1,15 @@
 // RUN: %clang %s -### -no-canonical-prefixes --target=x86_64-unknown-fuchsia \
-// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \
+// RUN: --sysroot=%S/platform 2>&1 \
 // RUN: | FileCheck -check-prefixes=CHECK,CHECK-X86_64 %s
 // RUN: %clang %s -### -no-canonical-prefixes --target=aarch64-unknown-fuchsia \
-// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \
+// RUN: --sysroot=%S/platform 2>&1 \
 // RUN: | FileCheck -check-prefixes=CHECK,CHECK-AARCH64 %s
 // CHECK: {{.*}}clang{{.*}}" "-cc1"
 // CHECK: "-munwind-tables"
 // CHECK: "-fuse-init-array"
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
-// CHECK: {{.*}}lld{{.*}}" "-flavor" "gnu"
-// CHECK: "-z" "rodynamic"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "rodynamic"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"
Index: cfe/trunk/test/Driver/fuchsia.cpp
===
--- cfe/trunk/test/Driver/fuchsia.cpp
+++ cfe/trunk/test/Driver/fuchsia.cpp
@@ -1,13 +1,12 @@
 // RUN: %clangxx %s -### -no-canonical-prefixes --target=x86_64-unknown-fuchsia \
-// RUN: --sysroot=%S/platform 

r316379 - [Driver] Use ld.lld directly for Fuchsia rather than passing flavor

2017-10-23 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Mon Oct 23 14:31:05 2017
New Revision: 316379

URL: http://llvm.org/viewvc/llvm-project?rev=316379=rev
Log:
[Driver] Use ld.lld directly for Fuchsia rather than passing flavor

Passing a flavor to LLD requires command line argument, but if these
are being passed through a response file, this will fail because LLD
needs to know which driver to use before processing the response file.
Use ld.lld directly instead to avoid this issue.

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

Modified:
cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
cfe/trunk/test/Driver/fuchsia.c
cfe/trunk/test/Driver/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=316379=316378=316379=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp Mon Oct 23 14:31:05 2017
@@ -44,10 +44,8 @@ void fuchsia::Linker::ConstructJob(Compi
   Args.ClaimAllArgs(options::OPT_w);
 
   const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
-  if (llvm::sys::path::stem(Exec).equals_lower("lld")) {
-CmdArgs.push_back("-flavor");
-CmdArgs.push_back("gnu");
-
+  if (llvm::sys::path::filename(Exec).equals_lower("ld.lld") ||
+  llvm::sys::path::stem(Exec).equals_lower("ld.lld")) {
 CmdArgs.push_back("-z");
 CmdArgs.push_back("rodynamic");
   }

Modified: cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Fuchsia.h?rev=316379=316378=316379=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.h Mon Oct 23 14:31:05 2017
@@ -82,7 +82,7 @@ public:
llvm::opt::ArgStringList ) const override;
 
   const char *getDefaultLinker() const override {
-return "lld";
+return "ld.lld";
   }
 
 protected:

Modified: cfe/trunk/test/Driver/fuchsia.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fuchsia.c?rev=316379=316378=316379=diff
==
--- cfe/trunk/test/Driver/fuchsia.c (original)
+++ cfe/trunk/test/Driver/fuchsia.c Mon Oct 23 14:31:05 2017
@@ -1,16 +1,15 @@
 // RUN: %clang %s -### -no-canonical-prefixes --target=x86_64-unknown-fuchsia \
-// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \
+// RUN: --sysroot=%S/platform 2>&1 \
 // RUN: | FileCheck -check-prefixes=CHECK,CHECK-X86_64 %s
 // RUN: %clang %s -### -no-canonical-prefixes --target=aarch64-unknown-fuchsia 
\
-// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \
+// RUN: --sysroot=%S/platform 2>&1 \
 // RUN: | FileCheck -check-prefixes=CHECK,CHECK-AARCH64 %s
 // CHECK: {{.*}}clang{{.*}}" "-cc1"
 // CHECK: "-munwind-tables"
 // CHECK: "-fuse-init-array"
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
-// CHECK: {{.*}}lld{{.*}}" "-flavor" "gnu"
-// CHECK: "-z" "rodynamic"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "rodynamic"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"

Modified: cfe/trunk/test/Driver/fuchsia.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fuchsia.cpp?rev=316379=316378=316379=diff
==
--- cfe/trunk/test/Driver/fuchsia.cpp (original)
+++ cfe/trunk/test/Driver/fuchsia.cpp Mon Oct 23 14:31:05 2017
@@ -1,13 +1,12 @@
 // RUN: %clangxx %s -### -no-canonical-prefixes 
--target=x86_64-unknown-fuchsia \
-// RUN: --sysroot=%S/platform 2>&1 -fuse-ld=ld | FileCheck %s
+// RUN: --sysroot=%S/platform 2>&1 | FileCheck %s
 // CHECK: {{.*}}clang{{.*}}" "-cc1"
 // CHECK: "-triple" "x86_64-fuchsia"
 // CHECK: "-fuse-init-array"
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK: "-internal-isystem" 
"{{.*[/\\]}}x86_64-fuchsia{{/|}}include{{/|}}c++{{/|}}v1"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
-// CHECK: {{.*}}lld{{.*}}" "-flavor" "gnu"
-// CHECK: "-z" "rodynamic"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "rodynamic"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"


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


[PATCH] D38819: [libunwind] Add support for dwarf unwinding on windows on x86_64

2017-10-23 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: src/UnwindRegistersRestore.S:98
+  # skip fs
+  # skip gs
+  movq  56(%rcx), %rsp  # cut back rsp to new location

mstorsjo wrote:
> mstorsjo wrote:
> > compnerd wrote:
> > > Doesn't Win64 ABI require some of the MMX registers be saved/restored too?
> > Right, yes, xmm6-xmm15 should be backed up and restored. I'll try to amend 
> > this with such a change.
> Actually, such a change doesn't necessarily make much sense on its own.
> 
> As long as the dwarf encoding itself doesn't describe how to restore those 
> registers (and on unix platforms you don't need to, so it probably isn't even 
> specified), you'd just end up backing up the xmm registers on entry when 
> throwing the exception, and restoring the exactly same ones again - it only 
> guards against changes within libcxxabi/libunwind and the unwinding machinery 
> itself, not against changes further down in the call stack between the 
> thrower and catcher of the exception.
> 
> So with that, I guess this patch is futile unless planning to extend the 
> x86_64 dwarf handling in llvm to include those registers as well - and that's 
> a little out of scope of what I intended to do here...
If we have XMM values in the register context, we might as well reload them 
here. I assume libunwind will switch away from DWARF and over to UNWIND_INFO 
opcodes in the near future, and that will give us an accurate register context.


https://reviews.llvm.org/D38819



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


[PATCH] D38618: Do not add a colon chunk to the code completion of class inheritance access modifiers

2017-10-23 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

Overall LGTM, just a couple of comments:




Comment at: include/clang/Sema/Scope.h:131
+
+/// We are between inheritance colon and the real class/struct definition 
scope
+ClassInheritanceScope = 0x80,

Nit: Add '.' to the end of the comment + clang-format.



Comment at: lib/Parse/ParseDeclCXX.cpp:3198
   if (Tok.is(tok::colon)) {
+ParseScope InheritanceScope(this, Scope::ClassScope | Scope::DeclScope |
+  Scope::ClassInheritanceScope);

Might be better to use `getCurScope()->getFlags() | 
Scope::ClassInheritanceScope` to avoid dealing with any future scoping rule 
changes if such changes will occur.



Comment at: lib/Sema/SemaCodeComplete.cpp:1661
 
+bool IsNotInheritanceScope = !(S->getFlags() & 
Scope::ClassInheritanceScope);
 // public:

80 columns violation, please clang-format


https://reviews.llvm.org/D38618



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


[PATCH] D39079: New clang option -fno-plt to avoid PLT for external calls

2017-10-23 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

In https://reviews.llvm.org/D39079#904050, @lebedev.ri wrote:

> No tests?


+1, there should be an -emit-llvm test in clang/test/CodeGen/.




Comment at: lib/CodeGen/CGCall.cpp:1859
+if (auto *Fn = dyn_cast(TargetDecl)) {
+  if (!Fn->isDefined() && !AttrOnCallSite) {
+FuncAttrs.addAttribute(llvm::Attribute::NonLazyBind);

Remind me what happens when the definition is within the current DSO after 
linking. I seem to recall that the call through memory is 6 bytes and the 
direct pcrel call is 5 bytes, and the linker is required to know to rewrite the 
indirect call to a nop. Is that accurate?


https://reviews.llvm.org/D39079



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


[PATCH] D39160: [CodeGen] __builtin_sqrt should map to the compiler's intrinsic sqrt function

2017-10-23 Thread Sanjay Patel via Phabricator via cfe-commits
spatel abandoned this revision.
spatel added a comment.

Reincarnated as https://reviews.llvm.org/D39204.


https://reviews.llvm.org/D39160



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


[PATCH] D39204: [CodeGen] __builtin_sqrt should map to the compiler's intrinsic sqrt function

2017-10-23 Thread Sanjay Patel via Phabricator via cfe-commits
spatel created this revision.
Herald added a subscriber: mcrosier.

This patch is intended to answer a question raised in PR27435:
https://bugs.llvm.org/show_bug.cgi?id=27435

Is a programmer using __builtin_sqrt() invoking the compiler's intrinsic 
definition of sqrt or the mathlib definition of sqrt?

I know there are follow-up bugs that still need to be solved 
(https://reviews.llvm.org/D28335), but I think we should answer this first. 
Also if this patch is correct, it is enough to produce the hoped-for result in 
the PR27435 examples because we'll get this IR at -O2:

$ ./clang -O2 27435.c -S -o - -emit-llvm | grep llvm.sqrt

  %2 = call <2 x double> @llvm.sqrt.v2f64(<2 x double> %1)
  %2 = call <4 x float> @llvm.sqrt.v4f32(<4 x float> %1)


https://reviews.llvm.org/D39204

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/builtins.c


Index: test/CodeGen/builtins.c
===
--- test/CodeGen/builtins.c
+++ test/CodeGen/builtins.c
@@ -318,13 +318,13 @@
   // CHECK: call x86_fp80 @llvm.floor.f80
 
   resf = __builtin_sqrtf(F);
-  // CHECK: call float @sqrtf(
+  // CHECK: call float @llvm.sqrt.f32
 
   resd = __builtin_sqrt(D);
-  // CHECK: call double @sqrt(
+  // CHECK: call double @llvm.sqrt.f64
 
   resld = __builtin_sqrtl(LD);
-  // CHECK: call x86_fp80 @sqrtl(
+  // CHECK: call x86_fp80 @llvm.sqrt.f80
 
   resf = __builtin_truncf(F);
   // CHECK: call float @llvm.trunc.f32
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -941,6 +941,12 @@
   case Builtin::BI__builtin_roundl: {
 return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::round));
   }
+
+  case Builtin::BI__builtin_sqrt:
+  case Builtin::BI__builtin_sqrtf:
+  case Builtin::BI__builtin_sqrtl:
+return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::sqrt));
+
   case Builtin::BI__builtin_fmin:
   case Builtin::BI__builtin_fminf:
   case Builtin::BI__builtin_fminl: {


Index: test/CodeGen/builtins.c
===
--- test/CodeGen/builtins.c
+++ test/CodeGen/builtins.c
@@ -318,13 +318,13 @@
   // CHECK: call x86_fp80 @llvm.floor.f80
 
   resf = __builtin_sqrtf(F);
-  // CHECK: call float @sqrtf(
+  // CHECK: call float @llvm.sqrt.f32
 
   resd = __builtin_sqrt(D);
-  // CHECK: call double @sqrt(
+  // CHECK: call double @llvm.sqrt.f64
 
   resld = __builtin_sqrtl(LD);
-  // CHECK: call x86_fp80 @sqrtl(
+  // CHECK: call x86_fp80 @llvm.sqrt.f80
 
   resf = __builtin_truncf(F);
   // CHECK: call float @llvm.trunc.f32
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -941,6 +941,12 @@
   case Builtin::BI__builtin_roundl: {
 return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::round));
   }
+
+  case Builtin::BI__builtin_sqrt:
+  case Builtin::BI__builtin_sqrtf:
+  case Builtin::BI__builtin_sqrtl:
+return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::sqrt));
+
   case Builtin::BI__builtin_fmin:
   case Builtin::BI__builtin_fminf:
   case Builtin::BI__builtin_fminl: {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39176: [Driver] Use ld.lld directly for Fuchsia rather than passing flavor

2017-10-23 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr accepted this revision.
mcgrathr added a comment.
This revision is now accepted and ready to land.

This seems like how it always should have been, since -fuse-ld=lld sets it to 
ld.lld, not lld.
Looks to me like the existing MipsLinux and WebAssembly implementations are 
wrong too and only BareMetal is right.


Repository:
  rL LLVM

https://reviews.llvm.org/D39176



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


[PATCH] D39160: [CodeGen] __builtin_sqrt should map to the compiler's intrinsic sqrt function

2017-10-23 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added a comment.

In https://reviews.llvm.org/D39160#902918, @spatel wrote:

> Oops - I wrongly made llvm-commits a subscriber rather than cfe-commits. Let 
> me know if I should reopen under a new thread to get the patch to hit the 
> right mailing list.


Yes, please reopen.


https://reviews.llvm.org/D39160



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


[PATCH] D39176: [Driver] Use ld.lld directly for Fuchsia rather than passing flavor

2017-10-23 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 119923.

Repository:
  rL LLVM

https://reviews.llvm.org/D39176

Files:
  lib/Driver/ToolChains/Fuchsia.cpp
  lib/Driver/ToolChains/Fuchsia.h
  test/Driver/fuchsia.c
  test/Driver/fuchsia.cpp


Index: test/Driver/fuchsia.cpp
===
--- test/Driver/fuchsia.cpp
+++ test/Driver/fuchsia.cpp
@@ -1,13 +1,12 @@
 // RUN: %clangxx %s -### -no-canonical-prefixes 
--target=x86_64-unknown-fuchsia \
-// RUN: --sysroot=%S/platform 2>&1 -fuse-ld=ld | FileCheck %s
+// RUN: --sysroot=%S/platform 2>&1 | FileCheck %s
 // CHECK: {{.*}}clang{{.*}}" "-cc1"
 // CHECK: "-triple" "x86_64-fuchsia"
 // CHECK: "-fuse-init-array"
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK: "-internal-isystem" 
"{{.*[/\\]}}x86_64-fuchsia{{/|}}include{{/|}}c++{{/|}}v1"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
-// CHECK: {{.*}}lld{{.*}}" "-flavor" "gnu"
-// CHECK: "-z" "rodynamic"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "rodynamic"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"
Index: test/Driver/fuchsia.c
===
--- test/Driver/fuchsia.c
+++ test/Driver/fuchsia.c
@@ -1,16 +1,15 @@
 // RUN: %clang %s -### -no-canonical-prefixes --target=x86_64-unknown-fuchsia \
-// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \
+// RUN: --sysroot=%S/platform 2>&1 \
 // RUN: | FileCheck -check-prefixes=CHECK,CHECK-X86_64 %s
 // RUN: %clang %s -### -no-canonical-prefixes --target=aarch64-unknown-fuchsia 
\
-// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \
+// RUN: --sysroot=%S/platform 2>&1 \
 // RUN: | FileCheck -check-prefixes=CHECK,CHECK-AARCH64 %s
 // CHECK: {{.*}}clang{{.*}}" "-cc1"
 // CHECK: "-munwind-tables"
 // CHECK: "-fuse-init-array"
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
-// CHECK: {{.*}}lld{{.*}}" "-flavor" "gnu"
-// CHECK: "-z" "rodynamic"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "rodynamic"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"
Index: lib/Driver/ToolChains/Fuchsia.h
===
--- lib/Driver/ToolChains/Fuchsia.h
+++ lib/Driver/ToolChains/Fuchsia.h
@@ -82,7 +82,7 @@
llvm::opt::ArgStringList ) const override;
 
   const char *getDefaultLinker() const override {
-return "lld";
+return "ld.lld";
   }
 
 protected:
Index: lib/Driver/ToolChains/Fuchsia.cpp
===
--- lib/Driver/ToolChains/Fuchsia.cpp
+++ lib/Driver/ToolChains/Fuchsia.cpp
@@ -44,10 +44,8 @@
   Args.ClaimAllArgs(options::OPT_w);
 
   const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
-  if (llvm::sys::path::stem(Exec).equals_lower("lld")) {
-CmdArgs.push_back("-flavor");
-CmdArgs.push_back("gnu");
-
+  if (llvm::sys::path::filename(Exec).equals_lower("ld.lld") ||
+  llvm::sys::path::stem(Exec).equals_lower("ld.lld")) {
 CmdArgs.push_back("-z");
 CmdArgs.push_back("rodynamic");
   }


Index: test/Driver/fuchsia.cpp
===
--- test/Driver/fuchsia.cpp
+++ test/Driver/fuchsia.cpp
@@ -1,13 +1,12 @@
 // RUN: %clangxx %s -### -no-canonical-prefixes --target=x86_64-unknown-fuchsia \
-// RUN: --sysroot=%S/platform 2>&1 -fuse-ld=ld | FileCheck %s
+// RUN: --sysroot=%S/platform 2>&1 | FileCheck %s
 // CHECK: {{.*}}clang{{.*}}" "-cc1"
 // CHECK: "-triple" "x86_64-fuchsia"
 // CHECK: "-fuse-init-array"
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK: "-internal-isystem" "{{.*[/\\]}}x86_64-fuchsia{{/|}}include{{/|}}c++{{/|}}v1"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
-// CHECK: {{.*}}lld{{.*}}" "-flavor" "gnu"
-// CHECK: "-z" "rodynamic"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "rodynamic"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"
Index: test/Driver/fuchsia.c
===
--- test/Driver/fuchsia.c
+++ test/Driver/fuchsia.c
@@ -1,16 +1,15 @@
 // RUN: %clang %s -### -no-canonical-prefixes --target=x86_64-unknown-fuchsia \
-// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \
+// RUN: --sysroot=%S/platform 2>&1 \
 // RUN: | FileCheck -check-prefixes=CHECK,CHECK-X86_64 %s
 // RUN: %clang %s -### -no-canonical-prefixes --target=aarch64-unknown-fuchsia \
-// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \
+// RUN: --sysroot=%S/platform 2>&1 \
 // RUN: | FileCheck -check-prefixes=CHECK,CHECK-AARCH64 %s
 // CHECK: {{.*}}clang{{.*}}" "-cc1"
 // CHECK: "-munwind-tables"
 // CHECK: "-fuse-init-array"
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
-// CHECK: {{.*}}lld{{.*}}" "-flavor" "gnu"

[PATCH] D38704: [libunwind] Abstract rwlocks into a class, provide a SRW lock implementation for windows

2017-10-23 Thread Martin Storsjö via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316364: Abstract rwlocks into a class, provide a SRW lock 
implementation for windows (authored by mstorsjo).

Changed prior to commit:
  https://reviews.llvm.org/D38704?vs=119094=119914#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38704

Files:
  libunwind/trunk/src/CMakeLists.txt
  libunwind/trunk/src/RWMutex.hpp
  libunwind/trunk/src/UnwindCursor.hpp
  libunwind/trunk/src/config.h

Index: libunwind/trunk/src/CMakeLists.txt
===
--- libunwind/trunk/src/CMakeLists.txt
+++ libunwind/trunk/src/CMakeLists.txt
@@ -30,6 +30,7 @@
 DwarfParser.hpp
 libunwind_ext.h
 Registers.hpp
+RWMutex.hpp
 UnwindCursor.hpp
 ${CMAKE_CURRENT_SOURCE_DIR}/../include/libunwind.h
 ${CMAKE_CURRENT_SOURCE_DIR}/../include/unwind.h)
Index: libunwind/trunk/src/RWMutex.hpp
===
--- libunwind/trunk/src/RWMutex.hpp
+++ libunwind/trunk/src/RWMutex.hpp
@@ -0,0 +1,77 @@
+//===- Registers.hpp --===//
+//
+// 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.
+//
+//
+// Abstract interface to shared reader/writer log, hiding platform and
+// configuration differences.
+//
+//===--===//
+
+#ifndef __RWMUTEX_HPP__
+#define __RWMUTEX_HPP__
+
+#if defined(_WIN32)
+#include 
+#elif !defined(_LIBUNWIND_HAS_NO_THREADS)
+#include 
+#endif
+
+namespace libunwind {
+
+#if defined(_LIBUNWIND_HAS_NO_THREADS)
+
+class _LIBUNWIND_HIDDEN RWMutex {
+public:
+  bool lock_shared() { return true; }
+  bool unlock_shared() { return true; }
+  bool lock() { return true; }
+  bool unlock() { return true; }
+};
+
+#elif defined(_WIN32)
+
+class _LIBUNWIND_HIDDEN RWMutex {
+public:
+  bool lock_shared() {
+AcquireSRWLockShared(&_lock);
+return true;
+  }
+  bool unlock_shared() {
+ReleaseSRWLockShared(&_lock);
+return true;
+  }
+  bool lock() {
+AcquireSRWLockExclusive(&_lock);
+return true;
+  }
+  bool unlock() {
+ReleaseSRWLockExclusive(&_lock);
+return true;
+  }
+
+private:
+  SRWLOCK _lock = SRWLOCK_INIT;
+};
+
+#else
+
+class _LIBUNWIND_HIDDEN RWMutex {
+public:
+  bool lock_shared() { return pthread_rwlock_rdlock(&_lock) == 0; }
+  bool unlock_shared() { return pthread_rwlock_unlock(&_lock) == 0; }
+  bool lock() { return pthread_rwlock_wrlock(&_lock) == 0; }
+  bool unlock() { return pthread_rwlock_unlock(&_lock) == 0; }
+
+private:
+  pthread_rwlock_t _lock = PTHREAD_RWLOCK_INITIALIZER;
+};
+
+#endif
+
+} // namespace libunwind
+
+#endif // __RWMUTEX_HPP__
Index: libunwind/trunk/src/config.h
===
--- libunwind/trunk/src/config.h
+++ libunwind/trunk/src/config.h
@@ -93,20 +93,15 @@
   fprintf(stderr, "libunwind: " msg "\n", __VA_ARGS__)
 #endif
 
-#if defined(_LIBUNWIND_HAS_NO_THREADS)
-  // only used with pthread calls, not needed for the single-threaded builds
-  #define _LIBUNWIND_LOG_NON_ZERO(x)
+#if defined(NDEBUG)
+  #define _LIBUNWIND_LOG_IF_FALSE(x) x
 #else
-  #if defined(NDEBUG)
-#define _LIBUNWIND_LOG_NON_ZERO(x) x
-  #else
-#define _LIBUNWIND_LOG_NON_ZERO(x) \
-  do { \
-int _err = x;  \
-if (_err != 0) \
-  _LIBUNWIND_LOG("" #x "=%d in %s", _err, __FUNCTION__);   \
-  } while (0)
-  #endif
+  #define _LIBUNWIND_LOG_IF_FALSE(x)   \
+do {   \
+  bool _ret = x;   \
+  if (!_ret)   \
+_LIBUNWIND_LOG("" #x " failed in %s", __FUNCTION__);   \
+} while (0)
 #endif
 
 // Macros that define away in non-Debug builds
Index: libunwind/trunk/src/UnwindCursor.hpp
===
--- libunwind/trunk/src/UnwindCursor.hpp
+++ libunwind/trunk/src/UnwindCursor.hpp
@@ -16,9 +16,6 @@
 #include 
 #include 
 #include 
-#ifndef _LIBUNWIND_HAS_NO_THREADS
-  #include 
-#endif
 #include 
 
 #ifdef __APPLE__
@@ -34,6 +31,7 @@
 #include "EHHeaderParser.hpp"
 #include "libunwind.h"
 #include "Registers.hpp"
+#include "RWMutex.hpp"
 #include "Unwind-EHABI.h"
 
 namespace libunwind {
@@ -62,9 +60,7 @@
 
   // These fields are all static to avoid needing an initializer.
   // There is only one instance 

[libunwind] r316364 - Abstract rwlocks into a class, provide a SRW lock implementation for windows

2017-10-23 Thread Martin Storsjo via cfe-commits
Author: mstorsjo
Date: Mon Oct 23 12:29:36 2017
New Revision: 316364

URL: http://llvm.org/viewvc/llvm-project?rev=316364=rev
Log:
Abstract rwlocks into a class, provide a SRW lock implementation for windows

This requires _WIN32_WINNT >= 0x0600.

If someone wants to spend effort on supporting earlier versions,
one can easily add another fallback implementation based on
critical sections, or try to load SRW lock functions dynamically.

This makes sure that the FDE cache is thread safe on windows.

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

Added:
libunwind/trunk/src/RWMutex.hpp
Modified:
libunwind/trunk/src/CMakeLists.txt
libunwind/trunk/src/UnwindCursor.hpp
libunwind/trunk/src/config.h

Modified: libunwind/trunk/src/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/CMakeLists.txt?rev=316364=316363=316364=diff
==
--- libunwind/trunk/src/CMakeLists.txt (original)
+++ libunwind/trunk/src/CMakeLists.txt Mon Oct 23 12:29:36 2017
@@ -30,6 +30,7 @@ set(LIBUNWIND_HEADERS
 DwarfParser.hpp
 libunwind_ext.h
 Registers.hpp
+RWMutex.hpp
 UnwindCursor.hpp
 ${CMAKE_CURRENT_SOURCE_DIR}/../include/libunwind.h
 ${CMAKE_CURRENT_SOURCE_DIR}/../include/unwind.h)

Added: libunwind/trunk/src/RWMutex.hpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/RWMutex.hpp?rev=316364=auto
==
--- libunwind/trunk/src/RWMutex.hpp (added)
+++ libunwind/trunk/src/RWMutex.hpp Mon Oct 23 12:29:36 2017
@@ -0,0 +1,77 @@
+//===- Registers.hpp 
--===//
+//
+// 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.
+//
+//
+// Abstract interface to shared reader/writer log, hiding platform and
+// configuration differences.
+//
+//===--===//
+
+#ifndef __RWMUTEX_HPP__
+#define __RWMUTEX_HPP__
+
+#if defined(_WIN32)
+#include 
+#elif !defined(_LIBUNWIND_HAS_NO_THREADS)
+#include 
+#endif
+
+namespace libunwind {
+
+#if defined(_LIBUNWIND_HAS_NO_THREADS)
+
+class _LIBUNWIND_HIDDEN RWMutex {
+public:
+  bool lock_shared() { return true; }
+  bool unlock_shared() { return true; }
+  bool lock() { return true; }
+  bool unlock() { return true; }
+};
+
+#elif defined(_WIN32)
+
+class _LIBUNWIND_HIDDEN RWMutex {
+public:
+  bool lock_shared() {
+AcquireSRWLockShared(&_lock);
+return true;
+  }
+  bool unlock_shared() {
+ReleaseSRWLockShared(&_lock);
+return true;
+  }
+  bool lock() {
+AcquireSRWLockExclusive(&_lock);
+return true;
+  }
+  bool unlock() {
+ReleaseSRWLockExclusive(&_lock);
+return true;
+  }
+
+private:
+  SRWLOCK _lock = SRWLOCK_INIT;
+};
+
+#else
+
+class _LIBUNWIND_HIDDEN RWMutex {
+public:
+  bool lock_shared() { return pthread_rwlock_rdlock(&_lock) == 0; }
+  bool unlock_shared() { return pthread_rwlock_unlock(&_lock) == 0; }
+  bool lock() { return pthread_rwlock_wrlock(&_lock) == 0; }
+  bool unlock() { return pthread_rwlock_unlock(&_lock) == 0; }
+
+private:
+  pthread_rwlock_t _lock = PTHREAD_RWLOCK_INITIALIZER;
+};
+
+#endif
+
+} // namespace libunwind
+
+#endif // __RWMUTEX_HPP__

Modified: libunwind/trunk/src/UnwindCursor.hpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/UnwindCursor.hpp?rev=316364=316363=316364=diff
==
--- libunwind/trunk/src/UnwindCursor.hpp (original)
+++ libunwind/trunk/src/UnwindCursor.hpp Mon Oct 23 12:29:36 2017
@@ -16,9 +16,6 @@
 #include 
 #include 
 #include 
-#ifndef _LIBUNWIND_HAS_NO_THREADS
-  #include 
-#endif
 #include 
 
 #ifdef __APPLE__
@@ -34,6 +31,7 @@
 #include "EHHeaderParser.hpp"
 #include "libunwind.h"
 #include "Registers.hpp"
+#include "RWMutex.hpp"
 #include "Unwind-EHABI.h"
 
 namespace libunwind {
@@ -62,9 +60,7 @@ private:
 
   // These fields are all static to avoid needing an initializer.
   // There is only one instance of this class per process.
-#ifndef _LIBUNWIND_HAS_NO_THREADS
-  static pthread_rwlock_t _lock;
-#endif
+  static RWMutex _lock;
 #ifdef __APPLE__
   static void dyldUnloadHook(const struct mach_header *mh, intptr_t slide);
   static bool _registeredForDyldUnloads;
@@ -91,10 +87,8 @@ DwarfFDECache::_bufferEnd = &_initial
 template 
 typename DwarfFDECache::entry DwarfFDECache::_initialBuffer[64];
 
-#ifndef _LIBUNWIND_HAS_NO_THREADS
 template 
-pthread_rwlock_t DwarfFDECache::_lock = PTHREAD_RWLOCK_INITIALIZER;
-#endif
+RWMutex DwarfFDECache::_lock;
 
 #ifdef __APPLE__
 template 
@@ -104,7 +98,7 @@ bool DwarfFDECache::_registeredForDyl
 template 
 typename A::pint_t DwarfFDECache::findFDE(pint_t mh, pint_t pc) {
   pint_t result = 0;
-  

[PATCH] D39201: [Analyzer] Handle implicit function reference in bodyfarming std::call_once

2017-10-23 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov created this revision.
Herald added subscribers: szepet, kristof.beyls, xazax.hun, javed.absar, 
aemerson.

https://reviews.llvm.org/D39201

Files:
  lib/Analysis/BodyFarm.cpp
  test/Analysis/call_once.cpp


Index: test/Analysis/call_once.cpp
===
--- test/Analysis/call_once.cpp
+++ test/Analysis/call_once.cpp
@@ -290,3 +290,16 @@
   std::call_once(flag, _mutator, a);
   clang_analyzer_eval(a == 42); // expected-warning{{FALSE}}
 }
+
+// Function is implicitly treated as a function pointer
+// even when an ampersand is not explicitly set.
+void callbackn(int ) {
+  param = 42;
+};
+void test_implicit_funcptr() {
+  int x = 0;
+  static std::once_flag flagn;
+
+  std::call_once(flagn, callbackn, x);
+  clang_analyzer_eval(x == 42); // expected-warning{{TRUE}}
+}
Index: lib/Analysis/BodyFarm.cpp
===
--- lib/Analysis/BodyFarm.cpp
+++ lib/Analysis/BodyFarm.cpp
@@ -253,13 +253,23 @@
const ParmVarDecl *Callback,
ArrayRef CallArgs) {
 
-  return new (C) CallExpr(
-  /*ASTContext=*/C,
-  /*StmtClass=*/M.makeLvalueToRvalue(/*Expr=*/Callback),
-  /*args=*/CallArgs,
-  /*QualType=*/C.VoidTy,
-  /*ExprValueType=*/VK_RValue,
-  /*SourceLocation=*/SourceLocation());
+  QualType Ty = Callback->getType();
+  DeclRefExpr *Call = M.makeDeclRefExpr(Callback);
+  CastKind CK;
+  if (Ty->isRValueReferenceType()) {
+CK = CK_LValueToRValue;
+  } else {
+assert(Ty->isLValueReferenceType());
+CK = CK_FunctionToPointerDecay;
+Ty = C.getPointerType(Ty.getNonReferenceType());
+  }
+
+  return new (C)
+  CallExpr(C, M.makeImplicitCast(Call, Ty.getNonReferenceType(), CK),
+   /*args=*/CallArgs,
+   /*QualType=*/C.VoidTy,
+   /*ExprValueType=*/VK_RValue,
+   /*SourceLocation=*/SourceLocation());
 }
 
 static CallExpr *create_call_once_lambda_call(ASTContext , ASTMaker M,
@@ -366,9 +376,11 @@
 CallbackFunctionType = CallbackRecordDecl->getLambdaCallOperator()
->getType()
->getAs();
-  } else {
+  } else if (!CallbackType->getPointeeType().isNull()) {
 CallbackFunctionType =
 CallbackType->getPointeeType()->getAs();
+  } else {
+CallbackFunctionType = CallbackType->getAs();
   }
 
   if (!CallbackFunctionType)


Index: test/Analysis/call_once.cpp
===
--- test/Analysis/call_once.cpp
+++ test/Analysis/call_once.cpp
@@ -290,3 +290,16 @@
   std::call_once(flag, _mutator, a);
   clang_analyzer_eval(a == 42); // expected-warning{{FALSE}}
 }
+
+// Function is implicitly treated as a function pointer
+// even when an ampersand is not explicitly set.
+void callbackn(int ) {
+  param = 42;
+};
+void test_implicit_funcptr() {
+  int x = 0;
+  static std::once_flag flagn;
+
+  std::call_once(flagn, callbackn, x);
+  clang_analyzer_eval(x == 42); // expected-warning{{TRUE}}
+}
Index: lib/Analysis/BodyFarm.cpp
===
--- lib/Analysis/BodyFarm.cpp
+++ lib/Analysis/BodyFarm.cpp
@@ -253,13 +253,23 @@
const ParmVarDecl *Callback,
ArrayRef CallArgs) {
 
-  return new (C) CallExpr(
-  /*ASTContext=*/C,
-  /*StmtClass=*/M.makeLvalueToRvalue(/*Expr=*/Callback),
-  /*args=*/CallArgs,
-  /*QualType=*/C.VoidTy,
-  /*ExprValueType=*/VK_RValue,
-  /*SourceLocation=*/SourceLocation());
+  QualType Ty = Callback->getType();
+  DeclRefExpr *Call = M.makeDeclRefExpr(Callback);
+  CastKind CK;
+  if (Ty->isRValueReferenceType()) {
+CK = CK_LValueToRValue;
+  } else {
+assert(Ty->isLValueReferenceType());
+CK = CK_FunctionToPointerDecay;
+Ty = C.getPointerType(Ty.getNonReferenceType());
+  }
+
+  return new (C)
+  CallExpr(C, M.makeImplicitCast(Call, Ty.getNonReferenceType(), CK),
+   /*args=*/CallArgs,
+   /*QualType=*/C.VoidTy,
+   /*ExprValueType=*/VK_RValue,
+   /*SourceLocation=*/SourceLocation());
 }
 
 static CallExpr *create_call_once_lambda_call(ASTContext , ASTMaker M,
@@ -366,9 +376,11 @@
 CallbackFunctionType = CallbackRecordDecl->getLambdaCallOperator()
->getType()
->getAs();
-  } else {
+  } else if (!CallbackType->getPointeeType().isNull()) {
 CallbackFunctionType =
 CallbackType->getPointeeType()->getAs();
+  } else {
+CallbackFunctionType = CallbackType->getAs();
   }
 
   if (!CallbackFunctionType)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27607: [ubsan] Treat ObjC's BOOL as if its range is always {0, 1}

2017-10-23 Thread Francis Ricci via Phabricator via cfe-commits
fjricci added a comment.

Awesome, good to know. Thanks!


Repository:
  rL LLVM

https://reviews.llvm.org/D27607



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


[PATCH] D39079: New clang option -fno-plt to avoid PLT for external calls

2017-10-23 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

No tests?


https://reviews.llvm.org/D39079



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


[PATCH] D39136: [OpenMP] Avoid VLAs for some reductions on array sections

2017-10-23 Thread Jonas Hahnfeld via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316362: [OpenMP] Avoid VLAs for some reductions on array 
sections (authored by Hahnfeld).

Changed prior to commit:
  https://reviews.llvm.org/D39136?vs=119689=119909#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39136

Files:
  cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
  cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
  cfe/trunk/lib/Sema/SemaOpenMP.cpp
  cfe/trunk/test/OpenMP/for_reduction_codegen.cpp
  cfe/trunk/test/OpenMP/for_reduction_codegen_UDR.cpp

Index: cfe/trunk/test/OpenMP/for_reduction_codegen.cpp
===
--- cfe/trunk/test/OpenMP/for_reduction_codegen.cpp
+++ cfe/trunk/test/OpenMP/for_reduction_codegen.cpp
@@ -27,15 +27,16 @@
 // CHECK-DAG: [[REDUCTION_LOC:@.+]] = private unnamed_addr constant %{{.+}} { i32 0, i32 18, i32 0, i32 0, i8*
 // CHECK-DAG: [[REDUCTION_LOCK:@.+]] = common global [8 x i32] zeroinitializer
 
-template 
+template 
 T tmain() {
   T t;
   S test;
   T t_var = T(), t_var1;
   T vec[] = {1, 2};
   S s_arr[] = {1, 2};
   S  = test;
   S var1;
+  S arr[length];
 #pragma omp parallel
 #pragma omp for reduction(+:t_var) reduction(&:var) reduction(&& : var1) reduction(min: t_var1) nowait
   for (int i = 0; i < 2; ++i) {
@@ -48,6 +49,12 @@
 vec[i] = t_var;
 s_arr[i] = var;
   }
+#pragma omp parallel
+#pragma omp for reduction(+ : arr[1:length-2])
+  for (int i = 0; i < 2; ++i) {
+vec[i] = t_var;
+s_arr[i] = var;
+  }
   return T();
 }
 
@@ -180,12 +187,12 @@
   S test;
   float t_var = 0, t_var1;
   int vec[] = {1, 2};
-  S s_arr[] = {1, 2};
+  S s_arr[] = {1, 2, 3, 4};
   S  = test;
   S var1, arrs[10][4];
   S **var2 = foo();
-  S vvar2[2];
-  S ()[2] = s_arr;
+  S vvar2[5];
+  S ()[4] = s_arr;
 #pragma omp parallel
 #pragma omp for reduction(+:t_var) reduction(&:var) reduction(&& : var1) reduction(min: t_var1)
   for (int i = 0; i < 2; ++i) {
@@ -205,36 +212,62 @@
   for (int i = 0; i < 10; ++i)
 ;
 #pragma omp parallel
+#pragma omp for reduction(& : var2[1][1 : 6])
+  for (int i = 0; i < 10; ++i)
+;
+#pragma omp parallel
+#pragma omp for reduction(& : var2[1 : 1][1 : 6])
+  for (int i = 0; i < 10; ++i)
+;
+#pragma omp parallel
+#pragma omp for reduction(& : var2[1 : 1][1])
+  for (int i = 0; i < 10; ++i)
+;
+#pragma omp parallel
 #pragma omp for reduction(& : vvar2[0 : 5])
   for (int i = 0; i < 10; ++i)
 ;
 #pragma omp parallel
 #pragma omp for reduction(& : var3[1 : 2])
   for (int i = 0; i < 10; ++i)
 ;
 #pragma omp parallel
+#pragma omp for reduction(& : var3[ : 2])
+  for (int i = 0; i < 10; ++i)
+;
+  // TODO: The compiler should also be able to generate a constant sized array in this case!
+#pragma omp parallel
+#pragma omp for reduction(& : var3[2 : ])
+  for (int i = 0; i < 10; ++i)
+;
+#pragma omp parallel
 #pragma omp for reduction(& : var3)
   for (int i = 0; i < 10; ++i)
 ;
-  return tmain();
+  return tmain();
 #endif
 }
 
 // CHECK: define {{.*}}i{{[0-9]+}} @main()
 // CHECK: [[TEST:%.+]] = alloca [[S_FLOAT_TY]],
 // CHECK: call {{.*}} [[S_FLOAT_TY_CONSTR:@.+]]([[S_FLOAT_TY]]* [[TEST]])
-// CHECK: call void (%{{.+}}*, i{{[0-9]+}}, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)*, ...) @__kmpc_fork_call(%{{.+}}* @{{.+}}, i{{[0-9]+}} 6, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)* bitcast (void (i{{[0-9]+}}*, i{{[0-9]+}}*, float*, [[S_FLOAT_TY]]*, [[S_FLOAT_TY]]*, float*, [2 x i32]*, [2 x [[S_FLOAT_TY]]]*)* [[MAIN_MICROTASK:@.+]] to void
+// CHECK: call void (%{{.+}}*, i{{[0-9]+}}, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)*, ...) @__kmpc_fork_call(%{{.+}}* @{{.+}}, i{{[0-9]+}} 6, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)* bitcast (void (i{{[0-9]+}}*, i{{[0-9]+}}*, float*, [[S_FLOAT_TY]]*, [[S_FLOAT_TY]]*, float*, [2 x i32]*, [4 x [[S_FLOAT_TY]]]*)* [[MAIN_MICROTASK:@.+]] to void
 // CHECK: call void (%{{.+}}*, i{{[0-9]+}}, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)*, ...) @__kmpc_fork_call(%{{.+}}* @{{.+}}, i{{[0-9]+}} 5, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)* bitcast (void (i{{[0-9]+}}*, i{{[0-9]+}}*, i64, i64, i32*, [2 x i32]*, [10 x [4 x [[S_FLOAT_TY*)* [[MAIN_MICROTASK1:@.+]] to void
 // CHECK: call void (%{{.+}}*, i{{[0-9]+}}, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)*, ...) @__kmpc_fork_call(%{{.+}}* @{{.+}}, i{{[0-9]+}} 4, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)* bitcast (void (i{{[0-9]+}}*, i{{[0-9]+}}*, i64, i64, i32*, [10 x [4 x [[S_FLOAT_TY*)* [[MAIN_MICROTASK2:@.+]] to void
 // CHECK: call void (%{{.+}}*, i{{[0-9]+}}, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)*, ...) @__kmpc_fork_call(%{{.+}}* @{{.+}}, i{{[0-9]+}} 1, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)* bitcast (void (i{{[0-9]+}}*, i{{[0-9]+}}*, [[S_FLOAT_TY]]***)* [[MAIN_MICROTASK3:@.+]] to void
-// CHECK: call void (%{{.+}}*, i{{[0-9]+}}, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)*, ...) @__kmpc_fork_call(%{{.+}}* @{{.+}}, i{{[0-9]+}} 1, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)* bitcast (void (i{{[0-9]+}}*, 

r316362 - [OpenMP] Avoid VLAs for some reductions on array sections

2017-10-23 Thread Jonas Hahnfeld via cfe-commits
Author: hahnfeld
Date: Mon Oct 23 12:01:35 2017
New Revision: 316362

URL: http://llvm.org/viewvc/llvm-project?rev=316362=rev
Log:
[OpenMP] Avoid VLAs for some reductions on array sections

In some cases the compiler can deduce the length of an array section
as constants. With this information, VLAs can be avoided in place of
a constant sized array or even a scalar value if the length is 1.
Example:
int a[4], b[2];
pragma omp parallel reduction(+: a[1:2], b[1:1])
{ }

For chained array sections, this optimization is restricted to cases
where all array sections except the last have a constant length 1.
This trivially guarantees that there are no holes in the memory region
that needs to be privatized.
Example:
int c[3][4];
pragma omp parallel reduction(+: c[1:1][1:2])
{ }

This relands commit r316229 that I reverted in r316235 because it
failed on some bots. During investigation I found that this was because
Clang and GCC evaluate the two arguments to emplace_back() in
ReductionCodeGen::emitSharedLValue() in a different order, hence
leading to a different order of generated instructions in the final
LLVM IR. Fix this by passing in the arguments from temporary variables
that are evaluated in a defined order.

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

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/for_reduction_codegen.cpp
cfe/trunk/test/OpenMP/for_reduction_codegen_UDR.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=316362=316361=316362=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Mon Oct 23 12:01:35 2017
@@ -916,8 +916,9 @@ ReductionCodeGen::ReductionCodeGen(Array
 void ReductionCodeGen::emitSharedLValue(CodeGenFunction , unsigned N) {
   assert(SharedAddresses.size() == N &&
  "Number of generated lvalues must be exactly N.");
-  SharedAddresses.emplace_back(emitSharedLValue(CGF, ClausesData[N].Ref),
-   emitSharedLValueUB(CGF, ClausesData[N].Ref));
+  LValue First = emitSharedLValue(CGF, ClausesData[N].Ref);
+  LValue Second = emitSharedLValueUB(CGF, ClausesData[N].Ref);
+  SharedAddresses.emplace_back(First, Second);
 }
 
 void ReductionCodeGen::emitAggregateType(CodeGenFunction , unsigned N) {
@@ -925,7 +926,7 @@ void ReductionCodeGen::emitAggregateType
   cast(cast(ClausesData[N].Private)->getDecl());
   QualType PrivateType = PrivateVD->getType();
   bool AsArraySection = isa(ClausesData[N].Ref);
-  if (!AsArraySection && !PrivateType->isVariablyModifiedType()) {
+  if (!PrivateType->isVariablyModifiedType()) {
 Sizes.emplace_back(
 CGF.getTypeSize(
 SharedAddresses[N].first.getType().getNonReferenceType()),
@@ -963,10 +964,9 @@ void ReductionCodeGen::emitAggregateType
   auto *PrivateVD =
   cast(cast(ClausesData[N].Private)->getDecl());
   QualType PrivateType = PrivateVD->getType();
-  bool AsArraySection = isa(ClausesData[N].Ref);
-  if (!AsArraySection && !PrivateType->isVariablyModifiedType()) {
+  if (!PrivateType->isVariablyModifiedType()) {
 assert(!Size && !Sizes[N].second &&
-   "Size should be nullptr for non-variably modified redution "
+   "Size should be nullptr for non-variably modified reduction "
"items.");
 return;
   }
@@ -994,8 +994,7 @@ void ReductionCodeGen::emitInitializatio
CGF.ConvertTypeForMem(SharedType)),
   SharedType, SharedAddresses[N].first.getBaseInfo(),
   CGF.CGM.getTBAAAccessInfo(SharedType));
-  if (isa(ClausesData[N].Ref) ||
-  CGF.getContext().getAsArrayType(PrivateVD->getType())) {
+  if (CGF.getContext().getAsArrayType(PrivateVD->getType())) {
 emitAggregateInitialization(CGF, N, PrivateAddr, SharedLVal, DRD);
   } else if (DRD && (DRD->getInitializer() || !PrivateVD->hasInit())) {
 emitInitWithReductionInitializer(CGF, DRD, ClausesData[N].ReductionOp,

Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=316362=316361=316362=diff
==
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Mon Oct 23 12:01:35 2017
@@ -996,7 +996,9 @@ void CodeGenFunction::EmitOMPReductionCl
 
 auto *LHSVD = cast(cast(*ILHS)->getDecl());
 auto *RHSVD = cast(cast(*IRHS)->getDecl());
-if (isa(IRef)) {
+QualType Type = PrivateVD->getType();
+bool isaOMPArraySectionExpr = isa(IRef);
+if (isaOMPArraySectionExpr && Type->isVariablyModifiedType()) {
   // Store the address of the original variable associated with the LHS
   // 

[PATCH] D39079: New clang option -fno-plt to avoid PLT for external calls

2017-10-23 Thread Sriraman Tallam via Phabricator via cfe-commits
tmsriram added a comment.

Ping.


https://reviews.llvm.org/D39079



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


[PATCH] D27607: [ubsan] Treat ObjC's BOOL as if its range is always {0, 1}

2017-10-23 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

In https://reviews.llvm.org/D27607#901882, @fjricci wrote:

> On platforms where `BOOL` == `signed char`, is it actually undefined behavior 
> (or is it just bad programming practice) to store a value other than 0 or 1 
> in your `BOOL`? I can't find any language specs suggesting that it is, and 
> given that it's just a typedef for a `signed char`, I don't see why it would 
> be.


Treating BOOL as a regular 'signed char' creates bad interactions with 
bitfields. For example, this code calls panic:

  struct S {
BOOL b1 : 1;
  };
  
  S s;
  s.b1 = YES;
  if (s.b1 != YES)
panic();



> If it's not actually undefined behavior, could we make it controllable via a 
> separate fsanitize switch (like we have for unsigned integer overflow, which 
> is also potentially bad practice but not actually undefined behavior).

The only defined values for BOOL are 'YES' and 'NO' {1, 0}. We've documented 
that it's UB to load values outside of this range from a BOOL here:
https://developer.apple.com/documentation/code_diagnostics/undefined_behavior_sanitizer/invalid_boolean


Repository:
  rL LLVM

https://reviews.llvm.org/D27607



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


[PATCH] D39069: CodeGen: Fix missing debug loc due to alloca

2017-10-23 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In https://reviews.llvm.org/D39069#903344, @rjmccall wrote:

> If this is something we generally need to be doing in all the places we 
> temporarily save and restore the insertion point, we should fix the basic 
> behavior of saveIP instead of adding explicit code to a bunch of separate 
> places.  Can we just override saveIP() on CGBuilder to return a struct that 
> also includes the current debug location?


IRBuilderBase::InsertPointGuard does that. Will use it instead.


https://reviews.llvm.org/D39069



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


RE: [PATCH] D39069: CodeGen: Fix missing debug loc due to alloca

2017-10-23 Thread Liu, Yaxun (Sam) via cfe-commits
I will simplify the test. Thanks.

Sam

From: David Blaikie [mailto:dblai...@gmail.com]
Sent: Monday, October 23, 2017 2:08 PM
To: reviews+d39069+public+8da79e110d303...@reviews.llvm.org; Yaxun Liu via 
Phabricator ; Liu, Yaxun (Sam) ; 
rjmcc...@gmail.com
Cc: cfe-commits@lists.llvm.org
Subject: Re: [PATCH] D39069: CodeGen: Fix missing debug loc due to alloca

What John said, but also a narrower test would be good - checking that the 
appropriate call instruction gets a debug location, rather than checking that a 
bunch of inlining doesn't cause the assertion/verifier failure, would be good. 
(Clang tests should, as much as possible, not rely on or run the LLVM 
optimization passes - but check the IR coming directly from Clang before any of 
that)
On Wed, Oct 18, 2017 at 2:15 PM Yaxun Liu via Phabricator via cfe-commits 
> wrote:
yaxunl created this revision.

Builder save/restores insertion pointer when emitting addr space cast
for alloca, but does not save/restore debug loc, which causes verifier
failure for certain call instructions.

This patch fixes that.


https://reviews.llvm.org/D39069

Files:
  lib/CodeGen/CGExpr.cpp
  test/CodeGenOpenCL/func-call-dbg-loc.cl


Index: test/CodeGenOpenCL/func-call-dbg-loc.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/func-call-dbg-loc.cl
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -triple amdgcn---amdgizcl -debug-info-kind=limited 
-dwarf-version=2 -debugger-tuning=gdb -O0 -emit-llvm -o - %s | FileCheck %s
+// Checks the file compiles without verifier error: inlinable function call in 
a function with debug info must have a !dbg location.
+
+typedef struct
+{
+float m_max;
+} Struct;
+
+typedef struct
+{
+Struct m_volume;
+} Node;
+
+
+Struct buzz(Node node)
+{
+return node.m_volume;
+}
+
+__attribute__((always_inline))
+float bar(Struct aabb)
+{
+return 0.0f;
+}
+
+__attribute__((used))
+void foo()
+{
+Node node;
+// CHECK: store float 0.00e+00, float addrspace(5)* %f, align 4, !dbg 
!{{[0-9]+}}
+float f = bar(buzz(node));
+}
+
+
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -75,11 +75,13 @@
   if (CastToDefaultAddrSpace && getASTAllocaAddressSpace() != LangAS::Default) 
{
 auto DestAddrSpace = getContext().getTargetAddressSpace(LangAS::Default);
 auto CurIP = Builder.saveIP();
+auto DbgLoc = Builder.getCurrentDebugLocation();
 Builder.SetInsertPoint(AllocaInsertPt);
 V = getTargetHooks().performAddrSpaceCast(
 *this, V, getASTAllocaAddressSpace(), LangAS::Default,
 Ty->getPointerTo(DestAddrSpace), /*non-null*/ true);
 Builder.restoreIP(CurIP);
+Builder.SetCurrentDebugLocation(DbgLoc);
   }

   return Address(V, Align);


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


Re: [PATCH] D39069: CodeGen: Fix missing debug loc due to alloca

2017-10-23 Thread David Blaikie via cfe-commits
What John said, but also a narrower test would be good - checking that the
appropriate call instruction gets a debug location, rather than checking
that a bunch of inlining doesn't cause the assertion/verifier failure,
would be good. (Clang tests should, as much as possible, not rely on or run
the LLVM optimization passes - but check the IR coming directly from Clang
before any of that)

On Wed, Oct 18, 2017 at 2:15 PM Yaxun Liu via Phabricator via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> yaxunl created this revision.
>
> Builder save/restores insertion pointer when emitting addr space cast
> for alloca, but does not save/restore debug loc, which causes verifier
> failure for certain call instructions.
>
> This patch fixes that.
>
>
> https://reviews.llvm.org/D39069
>
> Files:
>   lib/CodeGen/CGExpr.cpp
>   test/CodeGenOpenCL/func-call-dbg-loc.cl
>
>
> Index: test/CodeGenOpenCL/func-call-dbg-loc.cl
> ===
> --- /dev/null
> +++ test/CodeGenOpenCL/func-call-dbg-loc.cl
> @@ -0,0 +1,34 @@
> +// RUN: %clang_cc1 -triple amdgcn---amdgizcl -debug-info-kind=limited
> -dwarf-version=2 -debugger-tuning=gdb -O0 -emit-llvm -o - %s | FileCheck %s
> +// Checks the file compiles without verifier error: inlinable function
> call in a function with debug info must have a !dbg location.
> +
> +typedef struct
> +{
> +float m_max;
> +} Struct;
> +
> +typedef struct
> +{
> +Struct m_volume;
> +} Node;
> +
> +
> +Struct buzz(Node node)
> +{
> +return node.m_volume;
> +}
> +
> +__attribute__((always_inline))
> +float bar(Struct aabb)
> +{
> +return 0.0f;
> +}
> +
> +__attribute__((used))
> +void foo()
> +{
> +Node node;
> +// CHECK: store float 0.00e+00, float addrspace(5)* %f, align 4,
> !dbg !{{[0-9]+}}
> +float f = bar(buzz(node));
> +}
> +
> +
> Index: lib/CodeGen/CGExpr.cpp
> ===
> --- lib/CodeGen/CGExpr.cpp
> +++ lib/CodeGen/CGExpr.cpp
> @@ -75,11 +75,13 @@
>if (CastToDefaultAddrSpace && getASTAllocaAddressSpace() !=
> LangAS::Default) {
>  auto DestAddrSpace =
> getContext().getTargetAddressSpace(LangAS::Default);
>  auto CurIP = Builder.saveIP();
> +auto DbgLoc = Builder.getCurrentDebugLocation();
>  Builder.SetInsertPoint(AllocaInsertPt);
>  V = getTargetHooks().performAddrSpaceCast(
>  *this, V, getASTAllocaAddressSpace(), LangAS::Default,
>  Ty->getPointerTo(DestAddrSpace), /*non-null*/ true);
>  Builder.restoreIP(CurIP);
> +Builder.SetCurrentDebugLocation(DbgLoc);
>}
>
>return Address(V, Align);
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39179: [AArch64] Fix PR34625 -mtune without -mcpu should not set -target-cpu

2017-10-23 Thread Eric Christopher via Phabricator via cfe-commits
echristo accepted this revision.
echristo added a comment.
This revision is now accepted and ready to land.

This should be fine for now. Thanks!

-eric


https://reviews.llvm.org/D39179



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


[PATCH] D39184: CodeGen: Fix invalid bitcast in partial initialization of automatic arrary variable

2017-10-23 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316353: CodeGen: Fix invalid bitcast in partial 
initialization of automatic arrary… (authored by yaxunl).

Changed prior to commit:
  https://reviews.llvm.org/D39184?vs=119861=119900#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39184

Files:
  cfe/trunk/lib/CodeGen/CGDecl.cpp
  cfe/trunk/test/CodeGenOpenCL/amdgcn-automatic-variable.cl


Index: cfe/trunk/lib/CodeGen/CGDecl.cpp
===
--- cfe/trunk/lib/CodeGen/CGDecl.cpp
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp
@@ -1266,7 +1266,7 @@
 llvm::ConstantInt::get(IntPtrTy,

getContext().getTypeSizeInChars(type).getQuantity());
 
-  llvm::Type *BP = Int8PtrTy;
+  llvm::Type *BP = AllocaInt8PtrTy;
   if (Loc.getType() != BP)
 Loc = Builder.CreateBitCast(Loc, BP);
 
Index: cfe/trunk/test/CodeGenOpenCL/amdgcn-automatic-variable.cl
===
--- cfe/trunk/test/CodeGenOpenCL/amdgcn-automatic-variable.cl
+++ cfe/trunk/test/CodeGenOpenCL/amdgcn-automatic-variable.cl
@@ -58,3 +58,11 @@
   const int lvc = 4;
   lv1 = lvc;
 }
+
+// CHECK-LABEL: define void @func3()
+// CHECK: %a = alloca [16 x [1 x float]], align 4, addrspace(5)
+// CHECK: %[[CAST:.+]] = bitcast [16 x [1 x float]] addrspace(5)* %a to i8 
addrspace(5)*
+// CHECK: call void @llvm.memset.p5i8.i64(i8 addrspace(5)* %[[CAST]], i8 0, 
i64 64, i32 4, i1 false)
+void func3(void) {
+  float a[16][1] = {{0.}};
+}


Index: cfe/trunk/lib/CodeGen/CGDecl.cpp
===
--- cfe/trunk/lib/CodeGen/CGDecl.cpp
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp
@@ -1266,7 +1266,7 @@
 llvm::ConstantInt::get(IntPtrTy,
getContext().getTypeSizeInChars(type).getQuantity());
 
-  llvm::Type *BP = Int8PtrTy;
+  llvm::Type *BP = AllocaInt8PtrTy;
   if (Loc.getType() != BP)
 Loc = Builder.CreateBitCast(Loc, BP);
 
Index: cfe/trunk/test/CodeGenOpenCL/amdgcn-automatic-variable.cl
===
--- cfe/trunk/test/CodeGenOpenCL/amdgcn-automatic-variable.cl
+++ cfe/trunk/test/CodeGenOpenCL/amdgcn-automatic-variable.cl
@@ -58,3 +58,11 @@
   const int lvc = 4;
   lv1 = lvc;
 }
+
+// CHECK-LABEL: define void @func3()
+// CHECK: %a = alloca [16 x [1 x float]], align 4, addrspace(5)
+// CHECK: %[[CAST:.+]] = bitcast [16 x [1 x float]] addrspace(5)* %a to i8 addrspace(5)*
+// CHECK: call void @llvm.memset.p5i8.i64(i8 addrspace(5)* %[[CAST]], i8 0, i64 64, i32 4, i1 false)
+void func3(void) {
+  float a[16][1] = {{0.}};
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r316353 - CodeGen: Fix invalid bitcast in partial initialization of automatic arrary variable

2017-10-23 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Mon Oct 23 10:49:26 2017
New Revision: 316353

URL: http://llvm.org/viewvc/llvm-project?rev=316353=rev
Log:
CodeGen: Fix invalid bitcast in partial initialization of automatic arrary 
variable

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

Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/test/CodeGenOpenCL/amdgcn-automatic-variable.cl

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=316353=316352=316353=diff
==
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Mon Oct 23 10:49:26 2017
@@ -1266,7 +1266,7 @@ void CodeGenFunction::EmitAutoVarInit(co
 llvm::ConstantInt::get(IntPtrTy,

getContext().getTypeSizeInChars(type).getQuantity());
 
-  llvm::Type *BP = Int8PtrTy;
+  llvm::Type *BP = AllocaInt8PtrTy;
   if (Loc.getType() != BP)
 Loc = Builder.CreateBitCast(Loc, BP);
 

Modified: cfe/trunk/test/CodeGenOpenCL/amdgcn-automatic-variable.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/amdgcn-automatic-variable.cl?rev=316353=316352=316353=diff
==
--- cfe/trunk/test/CodeGenOpenCL/amdgcn-automatic-variable.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/amdgcn-automatic-variable.cl Mon Oct 23 
10:49:26 2017
@@ -58,3 +58,11 @@ void func2(void) {
   const int lvc = 4;
   lv1 = lvc;
 }
+
+// CHECK-LABEL: define void @func3()
+// CHECK: %a = alloca [16 x [1 x float]], align 4, addrspace(5)
+// CHECK: %[[CAST:.+]] = bitcast [16 x [1 x float]] addrspace(5)* %a to i8 
addrspace(5)*
+// CHECK: call void @llvm.memset.p5i8.i64(i8 addrspace(5)* %[[CAST]], i8 0, 
i64 64, i32 4, i1 false)
+void func3(void) {
+  float a[16][1] = {{0.}};
+}


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


[PATCH] D38704: [libunwind] Abstract rwlocks into a class, provide a SRW lock implementation for windows

2017-10-23 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

BTW LLVM requires a minimum of Windows 7 according to 
https://releases.llvm.org/3.8.0/docs/ReleaseNotes.html, so you can rely on SRW 
locks always being present. If LLVM still has a fallback path for when SRW 
locks are absent, that could be cleaned up.


https://reviews.llvm.org/D38704



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


[PATCH] D38954: [Sema] -Wzero-as-null-pointer-constant: don't warn for system macros other than NULL.

2017-10-23 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: lib/Sema/Sema.cpp:445
+  // If it is a macro from system header, and if the macro name is not "NULL",
+  // do not warn.
+  SourceLocation MaybeMacroLoc = E->getLocStart();

Rakete wrote:
> That comment doesn't really add anything IMO. It just says what the code just 
> below says.
I don't disagree. It seems to be the common pattern for the code in this file.
Having both the code and the comment might help convey the idea better.


Repository:
  rL LLVM

https://reviews.llvm.org/D38954



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


[PATCH] D36347: Add new script to launch lldb and set breakpoints for diagnostics all diagnostics seen.

2017-10-23 Thread Don Hinton via Phabricator via cfe-commits
hintonda added a comment.

Thanks for all the feedback.  I'll report back once I've addressed all your 
suggestions.

Thanks again...


https://reviews.llvm.org/D36347



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


[PATCH] D38954: [Sema] -Wzero-as-null-pointer-constant: don't warn for system macros other than NULL.

2017-10-23 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 119892.
lebedev.ri marked an inline comment as done.
lebedev.ri added a comment.

Use `MaybeMacroLoc` variable in the other place too.


Repository:
  rL LLVM

https://reviews.llvm.org/D38954

Files:
  docs/ReleaseNotes.rst
  lib/Sema/Sema.cpp
  test/SemaCXX/Inputs/warn-zero-nullptr.h
  test/SemaCXX/warn-zero-nullptr.cpp

Index: test/SemaCXX/warn-zero-nullptr.cpp
===
--- test/SemaCXX/warn-zero-nullptr.cpp
+++ test/SemaCXX/warn-zero-nullptr.cpp
@@ -1,4 +1,9 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -Wzero-as-null-pointer-constant -std=c++11
+// RUN: %clang_cc1 -fsyntax-only -verify %s -isystem %S/Inputs -Wzero-as-null-pointer-constant -std=c++11
+
+#include 
+
+#define MACRO (0)
+#define MCRO(x) (x)
 
 struct S {};
 
@@ -15,13 +20,60 @@
 void (*fp2)() = __null; // expected-warning{{zero as null pointer constant}}
 int (S::*mp2) = __null; // expected-warning{{zero as null pointer constant}}
 
-void f0(void* v = 0); // expected-warning{{zero as null pointer constant}}
-void f1(void* v);
+void f0(void* v = MACRO); // expected-warning{{zero as null pointer constant}}
+void f1(void* v = NULL); // expected-warning{{zero as null pointer constant}}
+void f2(void* v = MCRO(0)); // expected-warning{{zero as null pointer constant}}
+void f3(void* v = MCRO(NULL)); // expected-warning{{zero as null pointer constant}}
+void f4(void* v = 0); // expected-warning{{zero as null pointer constant}}
+void f5(void* v);
 
 void g() {
   f1(0); // expected-warning{{zero as null pointer constant}}
 }
 
 // Warn on these too. Matches gcc and arguably makes sense.
 void* pp = (decltype(nullptr))0; // expected-warning{{zero as null pointer constant}}
 void* pp2 = static_cast(0); // expected-warning{{zero as null pointer constant}}
+
+template  void TmplFunc0(T var) {}
+void Func0Test() {
+  TmplFunc0(0);
+  TmplFunc0(0); // expected-warning {{zero as null pointer constant}}
+  TmplFunc0(0); // expected-warning {{zero as null pointer constant}}
+}
+
+// FIXME: this one should *NOT* warn.
+template  void TmplFunc1(int a, T default_value = 0) {} // expected-warning{{zero as null pointer constant}} expected-warning{{zero as null pointer constant}}
+void FuncTest() {
+  TmplFunc1(0);
+  TmplFunc1(0); // expected-note {{in instantiation of default function argument expression for 'TmplFunc1' required here}}
+  TmplFunc1(0);  // expected-note {{in instantiation of default function argument expression for 'TmplFunc1' required here}}
+}
+
+template
+class TemplateClass0 {
+ public:
+  explicit TemplateClass0(T var) {}
+};
+void TemplateClass0Test() {
+  TemplateClass0 a(0);
+  TemplateClass0 b(0); // expected-warning {{zero as null pointer constant}}
+  TemplateClass0 c(0); // expected-warning {{zero as null pointer constant}}
+}
+
+template
+class TemplateClass1 {
+ public:
+// FIXME: this one should *NOT* warn.
+  explicit TemplateClass1(int a, T default_value = 0) {} // expected-warning{{zero as null pointer constant}} expected-warning{{zero as null pointer constant}}
+};
+void IgnoreSubstTemplateType1() {
+  TemplateClass1 a(1);
+  TemplateClass1 b(1); // expected-note {{in instantiation of default function argument expression for 'TemplateClass1' required here}}
+  TemplateClass1 c(1); // expected-note {{in instantiation of default function argument expression for 'TemplateClass1' required here}}
+}
+
+// Do not warn on *any* other macros from system headers, even if they
+// expand to/their expansion contains NULL.
+void* sys_init = SYSTEM_MACRO;
+void* sys_init2 = OTHER_SYSTEM_MACRO;
Index: test/SemaCXX/Inputs/warn-zero-nullptr.h
===
--- /dev/null
+++ test/SemaCXX/Inputs/warn-zero-nullptr.h
@@ -0,0 +1,3 @@
+#define NULL (0)
+#define SYSTEM_MACRO (0)
+#define OTHER_SYSTEM_MACRO (NULL)
Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -440,6 +440,14 @@
 return;
   if (E->getType()->isNullPtrType())
 return;
+
+  // If it is a macro from system header, and if the macro name is not "NULL",
+  // do not warn.
+  SourceLocation MaybeMacroLoc = E->getLocStart();
+  if (SourceMgr.isInSystemMacro(MaybeMacroLoc) &&
+  !findMacroSpelling(MaybeMacroLoc, "NULL"))
+return;
+
   // nullptr only exists from C++11 on, so don't warn on its absence earlier.
   if (!getLangOpts().CPlusPlus11)
 return;
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -87,6 +87,9 @@
   offset is nonzero. It also now warns about arithmetic on a null pointer
   treated as a cast from integer to pointer (GNU extension).
 
+- ``-Wzero-as-null-pointer-constant`` was adjusted not to warn on null pointer
+  constants that 

[PATCH] D39184: CodeGen: Fix invalid bitcast in partial initialization of automatic arrary variable

2017-10-23 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM.


https://reviews.llvm.org/D39184



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


r316344 - [ASTMatchers] Expose forEachOverriden in dynamic AST matchers.

2017-10-23 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Mon Oct 23 09:48:46 2017
New Revision: 316344

URL: http://llvm.org/viewvc/llvm-project?rev=316344=rev
Log:
[ASTMatchers] Expose forEachOverriden in dynamic AST matchers.

Modified:
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp

Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=316344=316343=316344=diff
==
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Mon Oct 23 09:48:46 2017
@@ -196,6 +196,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(forEachArgumentWithParam);
   REGISTER_MATCHER(forEachConstructorInitializer);
   REGISTER_MATCHER(forEachDescendant);
+  REGISTER_MATCHER(forEachOverridden);
   REGISTER_MATCHER(forEachSwitchCase);
   REGISTER_MATCHER(forField);
   REGISTER_MATCHER(forFunction);


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


[PATCH] D38704: [libunwind] Abstract rwlocks into a class, provide a SRW lock implementation for windows

2017-10-23 Thread David Majnemer via Phabricator via cfe-commits
majnemer accepted this revision.
majnemer added a comment.

LGTM


https://reviews.llvm.org/D38704



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


[libcxx] r316343 - Fix misguided error message in debug mode. No functional change. Fixes PR#34966

2017-10-23 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Mon Oct 23 09:46:44 2017
New Revision: 316343

URL: http://llvm.org/viewvc/llvm-project?rev=316343=rev
Log:
Fix misguided error message in debug mode. No functional change. Fixes PR#34966

Modified:
libcxx/trunk/include/list

Modified: libcxx/trunk/include/list
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/list?rev=316343=316342=316343=diff
==
--- libcxx/trunk/include/list (original)
+++ libcxx/trunk/include/list Mon Oct 23 09:46:44 2017
@@ -481,7 +481,7 @@ public:
 {
 #if _LIBCPP_DEBUG_LEVEL >= 2
 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
-   "Attempted to dereference a non-dereferenceable 
list::iterator");
+   "Attempted to dereference a non-dereferenceable 
list::const_iterator");
 #endif
 return 
pointer_traits::pointer_to(__ptr_->__as_node()->__value_);
 }


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


  1   2   >