[PATCH] D76432: [clangd] Add a tweak for adding "using" statement.

2020-03-27 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz added inline comments.



Comment at: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp:34
+// True iff "using" already exists and we should not add it.
+bool IdenticalUsingFound = false;
+// Location to insert the "using" statement.

sammccall wrote:
> is this redundant with Loc.isValid()?
> 
> If so, I'd either just use Loc (with a comment), or use 
> optional with a comment, to emphasize the relationship.
Yes, it's redundant. I went back and forth on this one, original version used 
Loc.isValid(). I decided I like being explicit better than having slightly more 
complicated semantics of the Loc field, but I wasn't too confident about this. 
Having second opinion helps :-)

I switched to isValid()





Comment at: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp:37
+SourceLocation Loc;
+// Extra suffix to place after the "using" statement. Depending on what the
+// insertion point is anchored to, we may need one or more \n to ensure

sammccall wrote:
> can we get away with always inserting \n and relying on clang-format to clean 
> it up?
Nope, that doesn't work. Auto-formatting doesn't seem to remove blank lines 
between using statements, for example. It's likely to allow you grouping them 
in some way.



Comment at: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp:44
+  // SourceLocation if the "using" statement already exists.
+  llvm::Expected
+  findInsertionPoint(const Selection );

sammccall wrote:
> this doesn't use any state - make it static or a free function?
It uses Name and NNSL . Would you prefer this as free function, with both 
passed as arguments. My initial thought was that, since prepare() and apply() 
already share these via class members this was fine, but I'm certainly not 
against making this a free function.



Comment at: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp:56
+  return std::string(
+  llvm::formatv("Add using statement and remove full qualifier."));
+}

sammccall wrote:
> nit: not actually a statement :-(
> 
> If "using-declaration" is overly laywerly (and easily confused with 
> using-directive), then maybe we should just spell it out: `Add "using 
> foo::Bar" ...`
I think spelling it out may be too long sometimes, namespaces are often long.

Changed to using-declaration



Comment at: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp:71
+  return true;
+}
+if (D->getDeclContext()->Encloses(SelectionDeclContext)) {

sammccall wrote:
> nit: we conventionally leave out the {} on one-line if bodies etc.
Uhh...is that a hard rule? I personally hate that, it's just asking for Apple 
SSL-style bugs
https://www.imperialviolet.org/2014/02/22/applebug.html



Comment at: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp:89
+
+  // If we're looking at a type or NestedNameSpecifier, walk up the tree until
+  // we find the "main" node we care about, which would be ElaboratedTypeLoc or

sammccall wrote:
> I like the idea here, but I'm not sure it quite works. e.g. any typeloc has a 
> directly enclosing typeloc, the inner one can't be targeted. So what about 
> `x::S*`? (pointertypeloc > elaboratedtypeloc > recordtypeloc)?
> 
> - looping up from NNS until you get to something else makes sense
> - unwrapping typeloc -> elaboratedtypeloc makes sense, but I don't think you 
> ever want to unwrap multiple levels?
> - i don't think these cases overlap at all, you want one or the other
> 
> Am I missing something?
If you have a class foo::bar::cc and a struct st inside it, and then do:
foo::bar::c^c::st *p;
you end up with:
PointerTypeLoc -> ElaboratedTypeLoc ->NestedNameSpecifierLoc -> RecordTypeLoc
in which case you need to go up from type to NNSL and then up again, from NNSL 
to something that's not NNSL.

You have a good point with the PointerTypeLoc, that's a bug. We should stop 
going up the tree as soon as we find ElaboratedTypeLoc. I added a test for that.



Comment at: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp:132
+llvm::Expected
+AddUsing::findInsertionPoint(const Selection ) {
+  auto  = Inputs.AST->getSourceManager();

sammccall wrote:
> One possible hiccup is insertion splitting a comment from its target. Cases I 
> can think of:
> - `namespace { // anonymous` -> `namespace { using foo::bar; // anonymous`. 
> This seems rare/unimportant.
> - `/* docs */ int firstTopLevelDecl` -> `/* docs */ using foo::bar; int 
> firstTopLevelDecl`. This seems common/bad.
> - `/* for widgets */using foo::Qux;` -> `/* for widgets */ using foo::bar; 
> using foo::Qux`. This seems rare/unimportant.
> 
> I think you could handle the decl case by calling 
> `ASTContext::getLocalCommentForDeclUncached()` and using the getBeginLoc() of 
> the returned comment if any.
> 
> That said, 

[clang] c682488 - [AST][SVE] Treat built-in SVE types as trivial

2020-03-27 Thread Richard Sandiford via cfe-commits

Author: Richard Sandiford
Date: 2020-03-27T17:34:04Z
New Revision: c6824883cc9de7e46b2417d58463f9c4e02da195

URL: 
https://github.com/llvm/llvm-project/commit/c6824883cc9de7e46b2417d58463f9c4e02da195
DIFF: 
https://github.com/llvm/llvm-project/commit/c6824883cc9de7e46b2417d58463f9c4e02da195.diff

LOG: [AST][SVE] Treat built-in SVE types as trivial

Built-in SVE types are trivial, since they're trivially copyable
and support default construction.

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

Added: 


Modified: 
clang/lib/AST/Type.cpp
clang/test/SemaCXX/sizeless-1.cpp

Removed: 




diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 44d3dbc806d8..99005a33e5a9 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2249,6 +2249,9 @@ bool QualType::isTrivialType(const ASTContext ) 
const {
   if ((*this)->isArrayType())
 return Context.getBaseElementType(*this).isTrivialType(Context);
 
+  if ((*this)->isSizelessBuiltinType())
+return true;
+
   // Return false for incomplete types after skipping any incomplete array
   // types which are expressly allowed by the standard and thus our API.
   if ((*this)->isIncompleteType())

diff  --git a/clang/test/SemaCXX/sizeless-1.cpp 
b/clang/test/SemaCXX/sizeless-1.cpp
index 3d0f07ccc74a..a7c02343cb48 100644
--- a/clang/test/SemaCXX/sizeless-1.cpp
+++ b/clang/test/SemaCXX/sizeless-1.cpp
@@ -516,6 +516,7 @@ void cxx_only(int sel) {
   _Static_assert(!__is_literal(svint8_t), "");
   _Static_assert(__is_pod(svint8_t), "");
   _Static_assert(!__is_polymorphic(svint8_t), "");
+  _Static_assert(__is_trivial(svint8_t), "");
   _Static_assert(__is_object(svint8_t), "");
   _Static_assert(!__is_arithmetic(svint8_t), "");
   _Static_assert(!__is_floating_point(svint8_t), "");



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


[clang] 3539266 - [AST][SVE] Treat built-in SVE types as trivially copyable

2020-03-27 Thread Richard Sandiford via cfe-commits

Author: Richard Sandiford
Date: 2020-03-27T17:32:55Z
New Revision: 35392660e6d5cb8d47e1fd33995d660576eff5de

URL: 
https://github.com/llvm/llvm-project/commit/35392660e6d5cb8d47e1fd33995d660576eff5de
DIFF: 
https://github.com/llvm/llvm-project/commit/35392660e6d5cb8d47e1fd33995d660576eff5de.diff

LOG: [AST][SVE] Treat built-in SVE types as trivially copyable

SVE types are trivially copyable: they can be copied simply
by reproducing the byte representation of the source object.

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

Added: 


Modified: 
clang/lib/AST/Type.cpp
clang/test/SemaCXX/sizeless-1.cpp

Removed: 




diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index d21dcdf97d2a..44d3dbc806d8 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2303,6 +2303,9 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
) const {
   if (CanonicalType->isDependentType())
 return false;
 
+  if (CanonicalType->isSizelessBuiltinType())
+return true;
+
   // Return false for incomplete types after skipping any incomplete array 
types
   // which are expressly allowed by the standard and thus our API.
   if (CanonicalType->isIncompleteType())

diff  --git a/clang/test/SemaCXX/sizeless-1.cpp 
b/clang/test/SemaCXX/sizeless-1.cpp
index b472f1856f08..3d0f07ccc74a 100644
--- a/clang/test/SemaCXX/sizeless-1.cpp
+++ b/clang/test/SemaCXX/sizeless-1.cpp
@@ -478,6 +478,7 @@ void cxx_only(int sel) {
   (void)typeid(ref_int8);
   (void)typeid(static_int8_ptr);
 
+  _Static_assert(__is_trivially_copyable(svint8_t), "");
   _Static_assert(__is_trivially_destructible(svint8_t), "");
   _Static_assert(!__is_nothrow_assignable(svint8_t, svint8_t), "");
   _Static_assert(__is_nothrow_assignable(svint8_t &, svint8_t), "");
@@ -591,9 +592,7 @@ void cxx_only(int sel) {
   for (const svint8_t  : wrapper()) { // expected-warning {{loop 
variable 'x' binds to a temporary value produced by a range of type 
'wrapper'}} expected-note {{use non-reference type}}
 (void)x;
   }
-  // This warning is bogus and will be removed by a later patch.
-  // The point is to show that it's being removed for the right reasons.
-  for (const svint8_t x : wrapper()) { // expected-warning 
{{loop variable 'x' creates a copy from type 'const svint8_t'}} expected-note 
{{use reference type}}
+  for (const svint8_t x : wrapper()) {
 (void)x;
   }
 #endif



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


[PATCH] D75951: Keep a list of already-included pragma-once files for mods.

2020-03-27 Thread Vy Nguyen via Phabricator via cfe-commits
oontvoo updated this revision to Diff 253162.
oontvoo added a comment.

Add tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75951/new/

https://reviews.llvm.org/D75951

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/Inputs/dummy_pragma_once.h
  clang/test/Modules/Inputs/module.map
  clang/test/Modules/import-pragma-once.c

Index: clang/test/Modules/import-pragma-once.c
===
--- /dev/null
+++ clang/test/Modules/import-pragma-once.c
@@ -0,0 +1,5 @@
+
+#include "dummy_pragma_once.h"
+#include "dummy_pragma_once.h"  // Re-importing should be fine
+
+void *p = 
Index: clang/test/Modules/Inputs/module.map
===
--- clang/test/Modules/Inputs/module.map
+++ clang/test/Modules/Inputs/module.map
@@ -282,6 +282,10 @@
   header "dummy.h"
 }
 
+module dummy_pragma_once {
+  header "dummy_pragma_once.h"
+}
+
 module builtin {
   header "builtin.h"
   explicit module sub {
Index: clang/test/Modules/Inputs/dummy_pragma_once.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/dummy_pragma_once.h
@@ -0,0 +1,3 @@
+//#pragma once | dont need this
+
+int x = 5;
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1619,7 +1619,7 @@
   endian::Writer LE(Out, little);
   unsigned KeyLen = key.Filename.size() + 1 + 8 + 8;
   LE.write(KeyLen);
-  unsigned DataLen = 1 + 2 + 4 + 4;
+  unsigned DataLen = 1 + 2 + 4 + 4 + 4;
   for (auto ModInfo : Data.KnownHeaders)
 if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule()))
   DataLen += 4;
@@ -1676,6 +1676,9 @@
   }
   LE.write(Offset);
 
+  // Write this file UID.
+  LE.write(Data.HFI.UID);
+
   auto EmitModule = [&](Module *M, ModuleMap::ModuleHeaderRole Role) {
 if (uint32_t ModID = Writer.getLocalOrImportedSubmoduleID(M)) {
   uint32_t Value = (ModID << 2) | (unsigned)Role;
@@ -1703,7 +1706,7 @@
 /// Write the header search block for the list of files that
 ///
 /// \param HS The header search structure to save.
-void ASTWriter::WriteHeaderSearch(const HeaderSearch ) {
+void ASTWriter::WriteHeaderSearch(HeaderSearch ) {
   HeaderFileInfoTrait GeneratorTrait(*this);
   llvm::OnDiskChainedHashTableGenerator Generator;
   SmallVector SavedStrings;
@@ -1781,8 +1784,7 @@
 // changed since it was loaded. Also skip it if it's for a modular header
 // from a different module; in that case, we rely on the module(s)
 // containing the header to provide this information.
-const HeaderFileInfo *HFI =
-HS.getExistingFileInfo(File, /*WantExternal*/!Chain);
+HeaderFileInfo *HFI = HS.getExistingFileInfo(File, /*WantExternal*/ !Chain);
 if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader))
   continue;
 
@@ -1799,8 +1801,13 @@
 HeaderFileInfoTrait::key_type Key = {
   Filename, File->getSize(), getTimestampForOutput(File)
 };
+// Set the UID for this HFI so that its importers could use it
+// when serializing.
+HFI->UID = UID;
 HeaderFileInfoTrait::data_type Data = {
-  *HFI, HS.getModuleMap().findAllModulesForHeader(File), {}
+*HFI,
+HS.getModuleMap().findAllModulesForHeader(File),
+{},
 };
 Generator.insert(Key, Data, GeneratorTrait);
 ++NumHeaderSearchEntries;
@@ -2634,6 +2641,25 @@
   Stream.EmitRecord(SUBMODULE_IMPORTS, Record);
 }
 
+// Emit the imported header's UIDs.
+{
+  auto it = PP->Submodules.find(Mod);
+  if (it != PP->Submodules.end() && !it->second.IncludedFiles.empty()) {
+RecordData Record;
+for (unsigned UID : it->second.IncludedFiles) {
+  // Only save it if the header is actually import/pragma once.
+  // FIXME When we first see a header, it always goes into the mod's
+  // list of included, regardless of whether it was pragma-once or not.
+  // Maybe better to fix that earlier?
+  auto HFI = PP->getHeaderSearchInfo().FileInfo[UID];
+  if (HFI.isImport || HFI.isPragmaOnce) {
+Record.push_back(HFI.UID);
+  }
+}
+Stream.EmitRecord(SUBMODULE_IMPORTED_HEADERS, Record);
+  }
+}
+
 // Emit the exports.
 if (!Mod->Exports.empty()) {
   RecordData Record;
@@ -4715,6 +4741,24 @@
   if (WritingModule)
 WriteSubmodules(WritingModule);
 
+  // Write 

[PATCH] D76690: [AST][SVE] Treat built-in SVE types as POD

2020-03-27 Thread Richard Sandiford via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9dcb20a7d008: [AST][SVE] Treat built-in SVE types as POD 
(authored by rsandifo-arm).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76690/new/

https://reviews.llvm.org/D76690

Files:
  clang/lib/AST/Type.cpp
  clang/test/SemaCXX/sizeless-1.cpp


Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -266,6 +266,7 @@
   __builtin_va_list va;
 
   __builtin_va_start(va, first);
+  __builtin_va_arg(va, svint8_t);
   __builtin_va_end(va);
   return count;
 }
@@ -491,6 +492,16 @@
   _Static_assert(!__is_assignable(svint8_t, svint8_t), "");
   _Static_assert(__is_assignable(svint8_t &, svint8_t), "");
   _Static_assert(!__is_assignable(svint8_t &, svint16_t), "");
+  _Static_assert(__has_nothrow_assign(svint8_t), "");
+  _Static_assert(__has_nothrow_move_assign(svint8_t), "");
+  _Static_assert(__has_nothrow_copy(svint8_t), "");
+  _Static_assert(__has_nothrow_constructor(svint8_t), "");
+  _Static_assert(__has_trivial_assign(svint8_t), "");
+  _Static_assert(__has_trivial_move_assign(svint8_t), "");
+  _Static_assert(__has_trivial_copy(svint8_t), "");
+  _Static_assert(__has_trivial_constructor(svint8_t), "");
+  _Static_assert(__has_trivial_move_constructor(svint8_t), "");
+  _Static_assert(__has_trivial_destructor(svint8_t), "");
   _Static_assert(!__has_virtual_destructor(svint8_t), "");
   _Static_assert(!__is_abstract(svint8_t), "");
   _Static_assert(!__is_aggregate(svint8_t), "");
@@ -502,6 +513,7 @@
   _Static_assert(!__is_enum(svint8_t), "");
   _Static_assert(!__is_final(svint8_t), "");
   _Static_assert(!__is_literal(svint8_t), "");
+  _Static_assert(__is_pod(svint8_t), "");
   _Static_assert(!__is_polymorphic(svint8_t), "");
   _Static_assert(__is_object(svint8_t), "");
   _Static_assert(!__is_arithmetic(svint8_t), "");
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2496,6 +2496,9 @@
   const Type *BaseTy = ty->getBaseElementTypeUnsafe();
   assert(BaseTy && "NULL element type");
 
+  if (BaseTy->isSizelessBuiltinType())
+return true;
+
   // Return false for incomplete types after skipping any incomplete array
   // types which are expressly allowed by the standard and thus our API.
   if (BaseTy->isIncompleteType())


Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -266,6 +266,7 @@
   __builtin_va_list va;
 
   __builtin_va_start(va, first);
+  __builtin_va_arg(va, svint8_t);
   __builtin_va_end(va);
   return count;
 }
@@ -491,6 +492,16 @@
   _Static_assert(!__is_assignable(svint8_t, svint8_t), "");
   _Static_assert(__is_assignable(svint8_t &, svint8_t), "");
   _Static_assert(!__is_assignable(svint8_t &, svint16_t), "");
+  _Static_assert(__has_nothrow_assign(svint8_t), "");
+  _Static_assert(__has_nothrow_move_assign(svint8_t), "");
+  _Static_assert(__has_nothrow_copy(svint8_t), "");
+  _Static_assert(__has_nothrow_constructor(svint8_t), "");
+  _Static_assert(__has_trivial_assign(svint8_t), "");
+  _Static_assert(__has_trivial_move_assign(svint8_t), "");
+  _Static_assert(__has_trivial_copy(svint8_t), "");
+  _Static_assert(__has_trivial_constructor(svint8_t), "");
+  _Static_assert(__has_trivial_move_constructor(svint8_t), "");
+  _Static_assert(__has_trivial_destructor(svint8_t), "");
   _Static_assert(!__has_virtual_destructor(svint8_t), "");
   _Static_assert(!__is_abstract(svint8_t), "");
   _Static_assert(!__is_aggregate(svint8_t), "");
@@ -502,6 +513,7 @@
   _Static_assert(!__is_enum(svint8_t), "");
   _Static_assert(!__is_final(svint8_t), "");
   _Static_assert(!__is_literal(svint8_t), "");
+  _Static_assert(__is_pod(svint8_t), "");
   _Static_assert(!__is_polymorphic(svint8_t), "");
   _Static_assert(__is_object(svint8_t), "");
   _Static_assert(!__is_arithmetic(svint8_t), "");
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2496,6 +2496,9 @@
   const Type *BaseTy = ty->getBaseElementTypeUnsafe();
   assert(BaseTy && "NULL element type");
 
+  if (BaseTy->isSizelessBuiltinType())
+return true;
+
   // Return false for incomplete types after skipping any incomplete array
   // types which are expressly allowed by the standard and thus our API.
   if (BaseTy->isIncompleteType())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76365: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-27 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D76365#1946415 , @hliao wrote:

> That's a partial template specialization needs handling. I am revising that 
> patch. Please revert it first. Thanks.


Reverted in fe8063e1a0e983f1b4d 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76365/new/

https://reviews.llvm.org/D76365



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


[PATCH] D76365: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-27 Thread Michael Liao via Phabricator via cfe-commits
hliao added a comment.

In D76365#1946407 , @tra wrote:

> In D76365#1946345 , @tra wrote:
>
> > Looks like the change breaks compilation for us:
> >
> >   In file included from :1:
> >   In file included from 
> > llvm_unstable/toolchain/lib/clang/google3-trunk/include/__clang_cuda_runtime_wrapper.h:104:
> >   In file included from cuda/include/cuda_runtime.h:116: 
> > cuda/include/cuda_surface_types.h:91:42: error: illegal device builtin 
> > surface reference type 'surface' declared here
> >   struct  __device_builtin_surface_type__  surface : public 
> > surfaceReference
> >^
> >   cuda/include/cuda_surface_types.h:91:42: note: 'surface' needs 
> > to be instantiated from a class template with the 2nd template argument as 
> > an integral value
> >   1 error generated when compiling for sm_60.
> >
> >
> > I'm investigating, but we may need to roll back this patch. Stay tuned.
>
>
> It appears that the assumptions of what types the attributes can apply to are 
> not valid. In CUDA headers they are also used on non-templated 
> classes/structs. E.g in cuda/include/cuda_surface_types.h:74
>
>   struct __attribute__((device_builtin_surface_type)) surface : public 
> surfaceReference
>   {
>   ...
>   };
>
>
> I'll undo this patch until we can make it work.


That's a partial template specialization needs handling. I am revising that 
patch. Please revert it first. Thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76365/new/

https://reviews.llvm.org/D76365



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


[PATCH] D76365: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-27 Thread Michael Liao via Phabricator via cfe-commits
hliao added a comment.

In D76365#1946345 , @tra wrote:

> Looks like the change breaks compilation for us:
>
>   In file included from :1:
>   In file included from 
> llvm_unstable/toolchain/lib/clang/google3-trunk/include/__clang_cuda_runtime_wrapper.h:104:
>   In file included from cuda/include/cuda_runtime.h:116: 
> cuda/include/cuda_surface_types.h:91:42: error: illegal device builtin 
> surface reference type 'surface' declared here
>   struct  __device_builtin_surface_type__  surface : public 
> surfaceReference
>^
>   cuda/include/cuda_surface_types.h:91:42: note: 'surface' needs 
> to be instantiated from a class template with the 2nd template argument as an 
> integral value
>   1 error generated when compiling for sm_60.
>
>
> I'm investigating, but we may need to roll back this patch. Stay tuned.


I am looking into it as well. Thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76365/new/

https://reviews.llvm.org/D76365



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


[PATCH] D75951: Keep a list of already-included pragma-once files for mods.

2020-03-27 Thread Vy Nguyen via Phabricator via cfe-commits
oontvoo updated this revision to Diff 253157.
oontvoo added a comment.

.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75951/new/

https://reviews.llvm.org/D75951

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp

Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1619,7 +1619,7 @@
   endian::Writer LE(Out, little);
   unsigned KeyLen = key.Filename.size() + 1 + 8 + 8;
   LE.write(KeyLen);
-  unsigned DataLen = 1 + 2 + 4 + 4;
+  unsigned DataLen = 1 + 2 + 4 + 4 + 4;
   for (auto ModInfo : Data.KnownHeaders)
 if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule()))
   DataLen += 4;
@@ -1676,6 +1676,9 @@
   }
   LE.write(Offset);
 
+  // Write this file UID.
+  LE.write(Data.HFI.UID);
+
   auto EmitModule = [&](Module *M, ModuleMap::ModuleHeaderRole Role) {
 if (uint32_t ModID = Writer.getLocalOrImportedSubmoduleID(M)) {
   uint32_t Value = (ModID << 2) | (unsigned)Role;
@@ -1703,7 +1706,7 @@
 /// Write the header search block for the list of files that
 ///
 /// \param HS The header search structure to save.
-void ASTWriter::WriteHeaderSearch(const HeaderSearch ) {
+void ASTWriter::WriteHeaderSearch(HeaderSearch ) {
   HeaderFileInfoTrait GeneratorTrait(*this);
   llvm::OnDiskChainedHashTableGenerator Generator;
   SmallVector SavedStrings;
@@ -1781,8 +1784,7 @@
 // changed since it was loaded. Also skip it if it's for a modular header
 // from a different module; in that case, we rely on the module(s)
 // containing the header to provide this information.
-const HeaderFileInfo *HFI =
-HS.getExistingFileInfo(File, /*WantExternal*/!Chain);
+HeaderFileInfo *HFI = HS.getExistingFileInfo(File, /*WantExternal*/ !Chain);
 if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader))
   continue;
 
@@ -1799,8 +1801,13 @@
 HeaderFileInfoTrait::key_type Key = {
   Filename, File->getSize(), getTimestampForOutput(File)
 };
+// Set the UID for this HFI so that its importers could use it
+// when serializing.
+HFI->UID = UID;
 HeaderFileInfoTrait::data_type Data = {
-  *HFI, HS.getModuleMap().findAllModulesForHeader(File), {}
+*HFI,
+HS.getModuleMap().findAllModulesForHeader(File),
+{},
 };
 Generator.insert(Key, Data, GeneratorTrait);
 ++NumHeaderSearchEntries;
@@ -2634,6 +2641,25 @@
   Stream.EmitRecord(SUBMODULE_IMPORTS, Record);
 }
 
+// Emit the imported header's UIDs.
+{
+  auto it = PP->Submodules.find(Mod);
+  if (it != PP->Submodules.end() && !it->second.IncludedFiles.empty()) {
+RecordData Record;
+for (unsigned UID : it->second.IncludedFiles) {
+  // Only save it if the header is actually import/pragma once.
+  // FIXME When we first see a header, it always goes into the mod's
+  // list of included, regardless of whether it was pragma-once or not.
+  // Maybe better to fix that earlier?
+  auto HFI = PP->getHeaderSearchInfo().FileInfo[UID];
+  if (HFI.isImport || HFI.isPragmaOnce) {
+Record.push_back(HFI.UID);
+  }
+}
+Stream.EmitRecord(SUBMODULE_IMPORTED_HEADERS, Record);
+  }
+}
+
 // Emit the exports.
 if (!Mod->Exports.empty()) {
   RecordData Record;
@@ -4715,6 +4741,24 @@
   if (WritingModule)
 WriteSubmodules(WritingModule);
 
+  // Write the imported headers, only for the precompiled header (ie, no
+  // modules) because the modules will have emitted their own imported headers.
+  if ((!WritingModule || PP.Submodules.empty()) &&
+  !PP.CurSubmoduleState->IncludedFiles.empty()) {
+RecordData Record;
+for (unsigned UID : PP.CurSubmoduleState->IncludedFiles) {
+  // Only save it if the header is actually import/pragma once.
+  // FIXME When we first see a header, it always goes into the
+  // list of included, regardless of whether it was pragma-once or not.
+  // Maybe better to fix that earlier?
+  auto HFI = PP.getHeaderSearchInfo().FileInfo[UID];
+  if (HFI.isImport || HFI.isPragmaOnce) {
+Record.push_back(HFI.UID);
+  }
+}
+Stream.EmitRecord(PP_IMPORTED_HEADERS, Record);
+  }
+
   // We need to have information about submodules to correctly deserialize
   // decls from OpenCLExtensionDecls block
   WriteOpenCLExtensionDecls(SemaRef);
Index: clang/lib/Serialization/ASTReader.cpp

[PATCH] D76365: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-27 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D76365#1946345 , @tra wrote:

> Looks like the change breaks compilation for us:
>
>   In file included from :1:
>   In file included from 
> llvm_unstable/toolchain/lib/clang/google3-trunk/include/__clang_cuda_runtime_wrapper.h:104:
>   In file included from cuda/include/cuda_runtime.h:116: 
> cuda/include/cuda_surface_types.h:91:42: error: illegal device builtin 
> surface reference type 'surface' declared here
>   struct  __device_builtin_surface_type__  surface : public 
> surfaceReference
>^
>   cuda/include/cuda_surface_types.h:91:42: note: 'surface' needs 
> to be instantiated from a class template with the 2nd template argument as an 
> integral value
>   1 error generated when compiling for sm_60.
>
>
> I'm investigating, but we may need to roll back this patch. Stay tuned.


It appears that the assumptions of what types the attributes can apply to are 
not valid. In CUDA headers they are also used on non-templated classes/structs. 
E.g in cuda/include/cuda_surface_types.h:74

  struct __attribute__((device_builtin_surface_type)) surface : public 
surfaceReference
  {
  ...
  };

I'll undo this patch until we can make it work.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76365/new/

https://reviews.llvm.org/D76365



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


[PATCH] D75788: [OpenMP] Provide math functions in OpenMP device code via OpenMP variants

2020-03-27 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert updated this revision to Diff 253154.
jdoerfert added a comment.

Remove OpenMP from clang/lib/Headers/__clang_cuda_math_forward_declares.h


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75788/new/

https://reviews.llvm.org/D75788

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__clang_cuda_cmath.h
  clang/lib/Headers/__clang_cuda_device_functions.h
  clang/lib/Headers/__clang_cuda_math_forward_declares.h
  clang/lib/Headers/openmp_wrappers/__clang_openmp_math.h
  clang/lib/Headers/openmp_wrappers/__clang_openmp_math_declares.h
  clang/lib/Headers/openmp_wrappers/cmath
  clang/lib/Headers/openmp_wrappers/math.h
  clang/test/Headers/Inputs/include/climits
  clang/test/Headers/Inputs/include/cmath
  clang/test/Headers/Inputs/include/cstdlib
  clang/test/Headers/Inputs/include/math.h
  clang/test/Headers/Inputs/include/stdlib.h
  clang/test/Headers/nvptx_device_cmath_functions.c
  clang/test/Headers/nvptx_device_cmath_functions.cpp
  clang/test/Headers/nvptx_device_cmath_functions_cxx17.cpp
  clang/test/Headers/nvptx_device_math_complex.c
  clang/test/Headers/nvptx_device_math_functions.c
  clang/test/Headers/nvptx_device_math_functions.cpp
  clang/test/Headers/nvptx_device_math_functions_cxx17.cpp
  clang/test/Headers/nvptx_device_math_macro.cpp
  clang/test/Headers/nvptx_device_math_sin.c
  clang/test/Headers/nvptx_device_math_sin.cpp

Index: clang/test/Headers/nvptx_device_math_sin.cpp
===
--- /dev/null
+++ clang/test/Headers/nvptx_device_math_sin.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -x c++ -internal-isystem %S/Inputs/include -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -x c++ -include __clang_openmp_math_declares.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix=SLOW
+// RUN: %clang_cc1 -x c++ -internal-isystem %S/Inputs/include -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc -ffast-math
+// RUN: %clang_cc1 -x c++ -include __clang_openmp_math_declares.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - -ffast-math | FileCheck %s --check-prefix=FAST
+// expected-no-diagnostics
+
+#include 
+
+double math(float f, double d, long double ld) {
+  double r = 0;
+// SLOW:  call float @__nv_sinf(float
+// FAST:  call fast float @__nv_fast_sinf(float
+  r += sin(f);
+// SLOW:  call double @__nv_sin(double
+// FAST:  call fast double @__nv_sin(double
+  r += sin(d);
+  return r;
+}
+
+long double foo(float f, double d, long double ld) {
+  double r = ld;
+  r += math(f, d, ld);
+#pragma omp target map(r)
+  { r += math(f, d, ld); }
+  return r;
+}
Index: clang/test/Headers/nvptx_device_math_sin.c
===
--- /dev/null
+++ clang/test/Headers/nvptx_device_math_sin.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -x c -internal-isystem %S/Inputs/include -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -x c -include __clang_openmp_math_declares.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix=SLOW
+// RUN: %clang_cc1 -x c -internal-isystem %S/Inputs/include -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc -ffast-math
+// RUN: %clang_cc1 -x c -include __clang_openmp_math_declares.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - -ffast-math | FileCheck %s --check-prefix=FAST
+// expected-no-diagnostics
+
+#include 
+
+double math(float f, double d, long double ld) {
+  double r = 0;
+// SLOW:  call float @__nv_sinf(float
+// FAST:  call fast float @__nv_fast_sinf(float
+  r += sinf(f);
+// SLOW:  call double @__nv_sin(double
+// FAST:  call fast double @__nv_sin(double
+  r += sin(d);
+  return r;
+}
+
+long double foo(float f, 

[PATCH] D76916: [Darwin] Respect -fno-unroll-loops during LTO.

2020-03-27 Thread Francis Visoiu Mistrih via Phabricator via cfe-commits
thegameg accepted this revision.
thegameg added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76916/new/

https://reviews.llvm.org/D76916



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


[PATCH] D75951: Keep a list of already-included pragma-once files for mods.

2020-03-27 Thread Vy Nguyen via Phabricator via cfe-commits
oontvoo updated this revision to Diff 253155.
oontvoo added a comment.

Also serialise non-mods' imported headers


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75951/new/

https://reviews.llvm.org/D75951

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp

Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1619,7 +1619,7 @@
   endian::Writer LE(Out, little);
   unsigned KeyLen = key.Filename.size() + 1 + 8 + 8;
   LE.write(KeyLen);
-  unsigned DataLen = 1 + 2 + 4 + 4;
+  unsigned DataLen = 1 + 2 + 4 + 4 + 4;
   for (auto ModInfo : Data.KnownHeaders)
 if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule()))
   DataLen += 4;
@@ -1676,6 +1676,9 @@
   }
   LE.write(Offset);
 
+  // Write this file UID.
+  LE.write(Data.HFI.UID);
+
   auto EmitModule = [&](Module *M, ModuleMap::ModuleHeaderRole Role) {
 if (uint32_t ModID = Writer.getLocalOrImportedSubmoduleID(M)) {
   uint32_t Value = (ModID << 2) | (unsigned)Role;
@@ -1703,7 +1706,7 @@
 /// Write the header search block for the list of files that
 ///
 /// \param HS The header search structure to save.
-void ASTWriter::WriteHeaderSearch(const HeaderSearch ) {
+void ASTWriter::WriteHeaderSearch(HeaderSearch ) {
   HeaderFileInfoTrait GeneratorTrait(*this);
   llvm::OnDiskChainedHashTableGenerator Generator;
   SmallVector SavedStrings;
@@ -1781,8 +1784,7 @@
 // changed since it was loaded. Also skip it if it's for a modular header
 // from a different module; in that case, we rely on the module(s)
 // containing the header to provide this information.
-const HeaderFileInfo *HFI =
-HS.getExistingFileInfo(File, /*WantExternal*/!Chain);
+HeaderFileInfo *HFI = HS.getExistingFileInfo(File, /*WantExternal*/ !Chain);
 if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader))
   continue;
 
@@ -1799,8 +1801,13 @@
 HeaderFileInfoTrait::key_type Key = {
   Filename, File->getSize(), getTimestampForOutput(File)
 };
+// Set the UID for this HFI so that its importers could use it
+// when serializing.
+HFI->UID = UID;
 HeaderFileInfoTrait::data_type Data = {
-  *HFI, HS.getModuleMap().findAllModulesForHeader(File), {}
+*HFI,
+HS.getModuleMap().findAllModulesForHeader(File),
+{},
 };
 Generator.insert(Key, Data, GeneratorTrait);
 ++NumHeaderSearchEntries;
@@ -2634,6 +2641,25 @@
   Stream.EmitRecord(SUBMODULE_IMPORTS, Record);
 }
 
+// Emit the imported header's UIDs.
+{
+  auto it = PP->Submodules.find(Mod);
+  if (it != PP->Submodules.end() && !it->second.IncludedFiles.empty()) {
+RecordData Record;
+for (unsigned UID : it->second.IncludedFiles) {
+  // Only save it if the header is actually import/pragma once.
+  // FIXME When we first see a header, it always goes into the mod's
+  // list of included, regardless of whether it was pragma-once or not.
+  // Maybe better to fix that earlier?
+  auto HFI = PP->getHeaderSearchInfo().FileInfo[UID];
+  if (HFI.isImport || HFI.isPragmaOnce) {
+Record.push_back(HFI.UID);
+  }
+}
+Stream.EmitRecord(SUBMODULE_IMPORTED_HEADERS, Record);
+  }
+}
+
 // Emit the exports.
 if (!Mod->Exports.empty()) {
   RecordData Record;
@@ -4715,6 +4741,24 @@
   if (WritingModule)
 WriteSubmodules(WritingModule);
 
+  // Write the imported headers, only for the precompiled header (ie, no
+  // modules) because the modules will have emitted their own imported headers.
+  if ((!WritingModule || PP.Submodules.empty()) &&
+  !PP.CurSubmoduleState->IncludedFiles.empty()) {
+RecordData Record;
+for (unsigned UID : PP.CurSubmoduleState->IncludedFiles) {
+  // Only save it if the header is actually import/pragma once.
+  // FIXME When we first see a header, it always goes into the
+  // list of included, regardless of whether it was pragma-once or not.
+  // Maybe better to fix that earlier?
+  auto HFI = PP.getHeaderSearchInfo().FileInfo[UID];
+  if (HFI.isImport || HFI.isPragmaOnce) {
+Record.push_back(HFI.UID);
+  }
+}
+Stream.EmitRecord(PP_IMPORTED_HEADERS, Record);
+  }
+
   // We need to have information about submodules to correctly deserialize
   // decls from OpenCLExtensionDecls block
   WriteOpenCLExtensionDecls(SemaRef);
Index: clang/lib/Serialization/ASTReader.cpp

[PATCH] D59321: AMDGPU: Teach toolchain to link rocm device libs

2020-03-27 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm updated this revision to Diff 253156.
arsenm added a comment.

Cleanup wave64 check


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59321/new/

https://reviews.llvm.org/D59321

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/AMDGPU.h
  clang/test/CodeGenOpenCL/amdgpu-debug-info-pointer-address-space.cl
  clang/test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl
  clang/test/Driver/Inputs/rocm-device-libs/lib/hip.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/ockl.amdgcn.bc
  
clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_correctly_rounded_sqrt_off.amdgcn.bc
  
clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_correctly_rounded_sqrt_on.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_daz_opt_off.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_daz_opt_on.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_finite_only_off.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_finite_only_on.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_isa_version_1010.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_isa_version_1011.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_isa_version_1012.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_isa_version_803.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_isa_version_900.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_unsafe_math_off.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_unsafe_math_on.amdgcn.bc
  
clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_wavefrontsize64_off.amdgcn.bc
  
clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_wavefrontsize64_on.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/ocml.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/opencl.amdgcn.bc
  clang/test/Driver/amdgpu-visibility.cl
  clang/test/Driver/rocm-detect.cl
  clang/test/Driver/rocm-device-libs.cl
  clang/test/Driver/rocm-not-found.cl
  llvm/include/llvm/Support/TargetParser.h
  llvm/lib/Support/TargetParser.cpp

Index: llvm/lib/Support/TargetParser.cpp
===
--- llvm/lib/Support/TargetParser.cpp
+++ llvm/lib/Support/TargetParser.cpp
@@ -99,9 +99,9 @@
   {{"gfx906"},{"gfx906"},  GK_GFX906,  FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
   {{"gfx908"},{"gfx908"},  GK_GFX908,  FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
   {{"gfx909"},{"gfx909"},  GK_GFX909,  FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
-  {{"gfx1010"},   {"gfx1010"}, GK_GFX1010, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
-  {{"gfx1011"},   {"gfx1011"}, GK_GFX1011, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
-  {{"gfx1012"},   {"gfx1012"}, GK_GFX1012, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
+  {{"gfx1010"},   {"gfx1010"}, GK_GFX1010, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
+  {{"gfx1011"},   {"gfx1011"}, GK_GFX1011, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
+  {{"gfx1012"},   {"gfx1012"}, GK_GFX1012, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
 };
 
 const GPUInfo *getArchEntry(AMDGPU::GPUKind AK, ArrayRef Table) {
Index: llvm/include/llvm/Support/TargetParser.h
===
--- llvm/include/llvm/Support/TargetParser.h
+++ llvm/include/llvm/Support/TargetParser.h
@@ -151,7 +151,10 @@
 
   // Common features.
   FEATURE_FAST_FMA_F32 = 1 << 4,
-  FEATURE_FAST_DENORMAL_F32 = 1 << 5
+  FEATURE_FAST_DENORMAL_F32 = 1 << 5,
+
+  // Wavefront 32 is available.
+  FEATURE_WAVE32 = 1 << 6
 };
 
 StringRef getArchNameAMDGCN(GPUKind AK);
Index: clang/test/Driver/rocm-not-found.cl
===
--- /dev/null
+++ clang/test/Driver/rocm-not-found.cl
@@ -0,0 +1,11 @@
+// REQUIRES: clang-driver
+
+// Check that we raise an error if we're trying to compile OpenCL for amdhsa code but can't
+// find a ROCm install, unless -nogpulib was passed.
+
+// RUN: %clang -### --sysroot=%s/no-rocm-there -target amdgcn--amdhsa %s 2>&1 | FileCheck %s --check-prefix ERR
+// RUN: %clang -### --rocm-path=%s/no-rocm-there -target amdgcn--amdhsa %s 2>&1 | FileCheck %s --check-prefix ERR
+// ERR: cannot find ROCm installation. Provide its path via --rocm-path, or pass -nogpulib.
+
+// RUN: %clang -### -nogpulib --rocm-path=%s/no-rocm-there %s 2>&1 | FileCheck %s --check-prefix OK
+// OK-NOT: cannot find ROCm installation.
Index: clang/test/Driver/rocm-device-libs.cl
===
--- /dev/null
+++ clang/test/Driver/rocm-device-libs.cl
@@ -0,0 +1,163 @@
+// REQUIRES: clang-driver
+// REQUIRES: amdgpu-registered-target
+
+// Test flush-denormals-to-zero enabled uses 

[clang] 9dcb20a - [AST][SVE] Treat built-in SVE types as POD

2020-03-27 Thread Richard Sandiford via cfe-commits

Author: Richard Sandiford
Date: 2020-03-27T17:04:07Z
New Revision: 9dcb20a7d008ca179c5906ef3b2ef73d69964a94

URL: 
https://github.com/llvm/llvm-project/commit/9dcb20a7d008ca179c5906ef3b2ef73d69964a94
DIFF: 
https://github.com/llvm/llvm-project/commit/9dcb20a7d008ca179c5906ef3b2ef73d69964a94.diff

LOG: [AST][SVE] Treat built-in SVE types as POD

Built-in SVE types are POD in much the same that scalars and
fixed-length vectors are.

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

Added: 


Modified: 
clang/lib/AST/Type.cpp
clang/test/SemaCXX/sizeless-1.cpp

Removed: 




diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 69c942e46f72..d21dcdf97d2a 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2496,6 +2496,9 @@ bool QualType::isCXX11PODType(const ASTContext ) 
const {
   const Type *BaseTy = ty->getBaseElementTypeUnsafe();
   assert(BaseTy && "NULL element type");
 
+  if (BaseTy->isSizelessBuiltinType())
+return true;
+
   // Return false for incomplete types after skipping any incomplete array
   // types which are expressly allowed by the standard and thus our API.
   if (BaseTy->isIncompleteType())

diff  --git a/clang/test/SemaCXX/sizeless-1.cpp 
b/clang/test/SemaCXX/sizeless-1.cpp
index 5cbf1923d705..b472f1856f08 100644
--- a/clang/test/SemaCXX/sizeless-1.cpp
+++ b/clang/test/SemaCXX/sizeless-1.cpp
@@ -266,6 +266,7 @@ int vararg_receiver(int count, svint8_t first, ...) {
   __builtin_va_list va;
 
   __builtin_va_start(va, first);
+  __builtin_va_arg(va, svint8_t);
   __builtin_va_end(va);
   return count;
 }
@@ -491,6 +492,16 @@ void cxx_only(int sel) {
   _Static_assert(!__is_assignable(svint8_t, svint8_t), "");
   _Static_assert(__is_assignable(svint8_t &, svint8_t), "");
   _Static_assert(!__is_assignable(svint8_t &, svint16_t), "");
+  _Static_assert(__has_nothrow_assign(svint8_t), "");
+  _Static_assert(__has_nothrow_move_assign(svint8_t), "");
+  _Static_assert(__has_nothrow_copy(svint8_t), "");
+  _Static_assert(__has_nothrow_constructor(svint8_t), "");
+  _Static_assert(__has_trivial_assign(svint8_t), "");
+  _Static_assert(__has_trivial_move_assign(svint8_t), "");
+  _Static_assert(__has_trivial_copy(svint8_t), "");
+  _Static_assert(__has_trivial_constructor(svint8_t), "");
+  _Static_assert(__has_trivial_move_constructor(svint8_t), "");
+  _Static_assert(__has_trivial_destructor(svint8_t), "");
   _Static_assert(!__has_virtual_destructor(svint8_t), "");
   _Static_assert(!__is_abstract(svint8_t), "");
   _Static_assert(!__is_aggregate(svint8_t), "");
@@ -502,6 +513,7 @@ void cxx_only(int sel) {
   _Static_assert(!__is_enum(svint8_t), "");
   _Static_assert(!__is_final(svint8_t), "");
   _Static_assert(!__is_literal(svint8_t), "");
+  _Static_assert(__is_pod(svint8_t), "");
   _Static_assert(!__is_polymorphic(svint8_t), "");
   _Static_assert(__is_object(svint8_t), "");
   _Static_assert(!__is_arithmetic(svint8_t), "");



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


[clang] fe8063e - Revert "[cuda][hip] Add CUDA builtin surface/texture reference support."

2020-03-27 Thread Artem Belevich via cfe-commits

Author: Artem Belevich
Date: 2020-03-27T10:01:38-07:00
New Revision: fe8063e1a0e983f1b4d38530f4fb157a26c0771c

URL: 
https://github.com/llvm/llvm-project/commit/fe8063e1a0e983f1b4d38530f4fb157a26c0771c
DIFF: 
https://github.com/llvm/llvm-project/commit/fe8063e1a0e983f1b4d38530f4fb157a26c0771c.diff

LOG: Revert "[cuda][hip] Add CUDA builtin surface/texture reference support."

This reverts commit 6a9ad5f3f4ac66f0cae592e911f4baeb6ee5eca6.
The patch breaks CUDA copmilation.

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

Added: 


Modified: 
clang/include/clang/AST/Type.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/Type.cpp
clang/lib/CodeGen/CGCUDANV.cpp
clang/lib/CodeGen/CGCUDARuntime.h
clang/lib/CodeGen/CGExprAgg.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenTypes.cpp
clang/lib/CodeGen/TargetInfo.cpp
clang/lib/CodeGen/TargetInfo.h
clang/lib/Headers/__clang_cuda_runtime_wrapper.h
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/Misc/pragma-attribute-supported-attributes-list.test
clang/test/SemaCUDA/attr-declspec.cu
clang/test/SemaCUDA/attributes-on-non-cuda.cu
clang/test/SemaCUDA/bad-attributes.cu
llvm/include/llvm/IR/Operator.h

Removed: 
clang/test/CodeGenCUDA/surface.cu
clang/test/CodeGenCUDA/texture.cu



diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 6b46fc5ad312..3a2411b4ed29 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2111,11 +2111,6 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
   /// than implicitly __strong.
   bool isObjCARCImplicitlyUnretainedType() const;
 
-  /// Check if the type is the CUDA device builtin surface type.
-  bool isCUDADeviceBuiltinSurfaceType() const;
-  /// Check if the type is the CUDA device builtin texture type.
-  bool isCUDADeviceBuiltinTextureType() const;
-
   /// Return the implicit lifetime for this type, which must not be dependent.
   Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const;
 

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 96bfdd313f47..5a90b2be2cbf 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1064,20 +1064,16 @@ def CUDADeviceBuiltin : IgnoredAttr {
   let LangOpts = [CUDA];
 }
 
-def CUDADeviceBuiltinSurfaceType : InheritableAttr {
+def CUDADeviceBuiltinSurfaceType : IgnoredAttr {
   let Spellings = [GNU<"device_builtin_surface_type">,
Declspec<"__device_builtin_surface_type__">];
   let LangOpts = [CUDA];
-  let Subjects = SubjectList<[CXXRecord]>;
-  let Documentation = [CUDADeviceBuiltinSurfaceTypeDocs];
 }
 
-def CUDADeviceBuiltinTextureType : InheritableAttr {
+def CUDADeviceBuiltinTextureType : IgnoredAttr {
   let Spellings = [GNU<"device_builtin_texture_type">,
Declspec<"__device_builtin_texture_type__">];
   let LangOpts = [CUDA];
-  let Subjects = SubjectList<[CXXRecord]>;
-  let Documentation = [CUDADeviceBuiltinTextureTypeDocs];
 }
 
 def CUDAGlobal : InheritableAttr {

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 2c89dc6f4952..a1cf25ed3929 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4624,28 +4624,6 @@ the initializer on host side.
   }];
 }
 
-def CUDADeviceBuiltinSurfaceTypeDocs : Documentation {
-  let Category = DocCatType;
-  let Content = [{
-The ``device_builtin_surface_type`` attribute can be applied to a class
-template when declaring the surface reference. A surface reference variable
-could be accessed on the host side and, on the device side, might be translated
-into an internal surface object, which is established through surface bind and
-unbind runtime APIs.
-  }];
-}
-
-def CUDADeviceBuiltinTextureTypeDocs : Documentation {
-  let Category = DocCatType;
-  let Content = [{
-The ``device_builtin_texture_type`` attribute can be applied to a class
-template when declaring the texture reference. A texture reference variable
-could be accessed on the host side and, on the device side, might be translated
-into an internal texture object, which is established through texture bind and
-unbind runtime APIs.
-  }];
-}
-
 def LifetimeOwnerDocs : Documentation {
   let Category = DocCatDecl;
   let Content = [{

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 044d35f19e20..8e26aa91a761 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7967,29 +7967,6 @@ def err_cuda_ovl_target : Error<
 def note_cuda_ovl_candidate_target_mismatch : Note<
 

[PATCH] D75788: [OpenMP] Provide math functions in OpenMP device code via OpenMP variants

2020-03-27 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert updated this revision to Diff 253153.
jdoerfert added a comment.

Add and repair tests to show new features, e.g. math macro support


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75788/new/

https://reviews.llvm.org/D75788

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__clang_cuda_cmath.h
  clang/lib/Headers/__clang_cuda_device_functions.h
  clang/lib/Headers/__clang_cuda_math_forward_declares.h
  clang/lib/Headers/openmp_wrappers/__clang_openmp_math.h
  clang/lib/Headers/openmp_wrappers/__clang_openmp_math_declares.h
  clang/lib/Headers/openmp_wrappers/cmath
  clang/lib/Headers/openmp_wrappers/math.h
  clang/test/Headers/Inputs/include/climits
  clang/test/Headers/Inputs/include/cmath
  clang/test/Headers/Inputs/include/cstdlib
  clang/test/Headers/Inputs/include/math.h
  clang/test/Headers/Inputs/include/stdlib.h
  clang/test/Headers/nvptx_device_cmath_functions.c
  clang/test/Headers/nvptx_device_cmath_functions.cpp
  clang/test/Headers/nvptx_device_cmath_functions_cxx17.cpp
  clang/test/Headers/nvptx_device_math_complex.c
  clang/test/Headers/nvptx_device_math_functions.c
  clang/test/Headers/nvptx_device_math_functions.cpp
  clang/test/Headers/nvptx_device_math_functions_cxx17.cpp
  clang/test/Headers/nvptx_device_math_macro.cpp
  clang/test/Headers/nvptx_device_math_sin.c
  clang/test/Headers/nvptx_device_math_sin.cpp

Index: clang/test/Headers/nvptx_device_math_sin.cpp
===
--- /dev/null
+++ clang/test/Headers/nvptx_device_math_sin.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -x c++ -internal-isystem %S/Inputs/include -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -x c++ -include __clang_openmp_math_declares.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix=SLOW
+// RUN: %clang_cc1 -x c++ -internal-isystem %S/Inputs/include -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc -ffast-math
+// RUN: %clang_cc1 -x c++ -include __clang_openmp_math_declares.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - -ffast-math | FileCheck %s --check-prefix=FAST
+// expected-no-diagnostics
+
+#include 
+
+double math(float f, double d, long double ld) {
+  double r = 0;
+// SLOW:  call float @__nv_sinf(float
+// FAST:  call fast float @__nv_fast_sinf(float
+  r += sin(f);
+// SLOW:  call double @__nv_sin(double
+// FAST:  call fast double @__nv_sin(double
+  r += sin(d);
+  return r;
+}
+
+long double foo(float f, double d, long double ld) {
+  double r = ld;
+  r += math(f, d, ld);
+#pragma omp target map(r)
+  { r += math(f, d, ld); }
+  return r;
+}
Index: clang/test/Headers/nvptx_device_math_sin.c
===
--- /dev/null
+++ clang/test/Headers/nvptx_device_math_sin.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -x c -internal-isystem %S/Inputs/include -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -x c -include __clang_openmp_math_declares.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix=SLOW
+// RUN: %clang_cc1 -x c -internal-isystem %S/Inputs/include -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc -ffast-math
+// RUN: %clang_cc1 -x c -include __clang_openmp_math_declares.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - -ffast-math | FileCheck %s --check-prefix=FAST
+// expected-no-diagnostics
+
+#include 
+
+double math(float f, double d, long double ld) {
+  double r = 0;
+// SLOW:  call float @__nv_sinf(float
+// FAST:  call fast float @__nv_fast_sinf(float
+  r += sinf(f);
+// SLOW:  call double @__nv_sin(double
+// FAST:  call fast double @__nv_sin(double
+  r += sin(d);
+  return r;
+}
+
+long double foo(float f, double d, 

[PATCH] D76937: Fix infinite recursion in deferred diagnostic emitter

2020-03-27 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: rjmccall, ABataev.
Herald added a reviewer: jdoerfert.

Currently deferred diagnostic emitter checks variable decl in DeclRefExpr, which
causes infinite recursion for cases like `long a = (long)`.

Deferred diagnostic emitter does not need check variable decls in DeclRefExpr
since reference of a variable does not cause emission of functions directly or
indirectly. Therefore there is no need to check variable decls in DeclRefExpr.


https://reviews.llvm.org/D76937

Files:
  clang/lib/Sema/Sema.cpp
  clang/test/OpenMP/nvptx_target_exceptions_messages.cpp


Index: clang/test/OpenMP/nvptx_target_exceptions_messages.cpp
===
--- clang/test/OpenMP/nvptx_target_exceptions_messages.cpp
+++ clang/test/OpenMP/nvptx_target_exceptions_messages.cpp
@@ -1,5 +1,10 @@
-// RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc 
-fexceptions -fcxx-exceptions
-// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown 
-fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device 
-fopenmp-host-ir-file-path %t-ppc-host.bc -o - -fexceptions -fcxx-exceptions 
-ferror-limit 100
+// RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown \
+// RUN:   -verify=host -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc \
+// RUN:   %s -o %t-ppc-host.bc -fexceptions -fcxx-exceptions
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown \
+// RUN:   -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s \
+// RUN:   -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - \
+// RUN:   -fexceptions -fcxx-exceptions -ferror-limit 100
 
 #ifndef HEADER
 #define HEADER
@@ -81,4 +86,17 @@
 int foobar1() { throw 1; }
 int foobar2() { throw 1; } // expected-error {{cannot use 'throw' with 
exceptions disabled}}
 
+
+int foobar3();
+int (*C)() =  // expected-warning {{declaration is not declared in 
any declare target region}}
+   // host-warning@-1 {{declaration is not declared in any 
declare target region}}
+#pragma omp declare target
+int (*D)() = C; // expected-note {{used here}}
+// host-note@-1 {{used here}}
+#pragma omp end declare target
+int foobar3() { throw 1; }
+
+// Check no infinite recursion in deferred diagnostic emitter.
+long E = (long)
+
 #endif // HEADER
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -1494,6 +1494,13 @@
   DeferredDiagnosticsEmitter(Sema )
   : Inherited(S), ShouldEmit(false), InOMPDeviceContext(0) {}
 
+  void VisitDeclRefExpr(DeclRefExpr *E) {
+auto *D = E->getDecl();
+if (isa(D)) {
+  visitUsedDecl(E->getLocation(), D);
+}
+  }
+
   void VisitOMPTargetDirective(OMPTargetDirective *Node) {
 ++InOMPDeviceContext;
 Inherited::VisitOMPTargetDirective(Node);
@@ -1525,6 +1532,11 @@
   UseStack.pop_back();
   Visited.erase(D);
 } else if (auto *VD = dyn_cast(D)) {
+  assert(Visited.count(D) == 0 &&
+ "Variables should not recursively visited");
+  Visited.insert(D);
+  assert(VD->hasGlobalStorage() &&
+ "Should only check variables with global storage");
   if (auto *Init = VD->getInit()) {
 auto DevTy = OMPDeclareTargetDeclAttr::getDeviceType(VD);
 bool IsDev = DevTy && (*DevTy == OMPDeclareTargetDeclAttr::DT_NoHost ||
@@ -1535,6 +1547,7 @@
 if (IsDev)
   --InOMPDeviceContext;
   }
+  Visited.erase(D);
 } else
   Inherited::visitUsedDecl(Loc, D);
   }


Index: clang/test/OpenMP/nvptx_target_exceptions_messages.cpp
===
--- clang/test/OpenMP/nvptx_target_exceptions_messages.cpp
+++ clang/test/OpenMP/nvptx_target_exceptions_messages.cpp
@@ -1,5 +1,10 @@
-// RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc -fexceptions -fcxx-exceptions
-// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - -fexceptions -fcxx-exceptions -ferror-limit 100
+// RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown \
+// RUN:   -verify=host -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc \
+// RUN:   %s -o %t-ppc-host.bc -fexceptions -fcxx-exceptions
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown \
+// RUN:   -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s \
+// RUN:   -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - \
+// RUN:   -fexceptions -fcxx-exceptions -ferror-limit 100
 
 #ifndef HEADER
 #define HEADER
@@ -81,4 +86,17 @@
 int foobar1() { throw 

[PATCH] D76365: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-27 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

Looks like the change breaks compilation for us:

  In file included from :1:
  In file included from 
llvm_unstable/toolchain/lib/clang/google3-trunk/include/__clang_cuda_runtime_wrapper.h:104:
  In file included from cuda/include/cuda_runtime.h:116: 
cuda/include/cuda_surface_types.h:91:42: error: illegal device builtin surface 
reference type 'surface' declared here
  struct  __device_builtin_surface_type__  surface : public 
surfaceReference
   ^
  cuda/include/cuda_surface_types.h:91:42: note: 'surface' needs to 
be instantiated from a class template with the 2nd template argument as an 
integral value
  1 error generated when compiling for sm_60.

I'm investigating, but we may need to roll back this patch. Stay tuned.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76365/new/

https://reviews.llvm.org/D76365



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


[PATCH] D76927: [ARM,CDE] Improve CDE intrinsics testing

2020-03-27 Thread Mikhail Maltsev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbd722ef63f18: [ARM,CDE] Improve CDE intrinsics testing 
(authored by miyuki).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76927/new/

https://reviews.llvm.org/D76927

Files:
  clang/test/CodeGen/arm-cde-reinterpret.c
  clang/test/Headers/arm-cde-header.c

Index: clang/test/Headers/arm-cde-header.c
===
--- clang/test/Headers/arm-cde-header.c
+++ clang/test/Headers/arm-cde-header.c
@@ -1,7 +1,9 @@
 // RUN: %clang_cc1 -std=c89 -triple thumbv8.1m.main-arm-none-eabi -fallow-half-arguments-and-returns -target-feature +mve.fp -target-feature +cdecp0 -fsyntax-only %s
-// RUN: %clang_cc1 -std=c99 -triple thumbv8.1m.main-arm-none-eabi -fallow-half-arguments-and-returns -target-feature +mve.fp -target-feature +cdecp0 -fsyntax-only %s
-// RUN: %clang_cc1 -std=c11 -triple thumbv8.1m.main-arm-none-eabi -fallow-half-arguments-and-returns -target-feature +mve.fp -target-feature +cdecp0 -fsyntax-only %s
+// RUN: %clang_cc1 -std=c17 -triple thumbv8.1m.main-arm-none-eabi -fallow-half-arguments-and-returns -target-feature +mve -target-feature +cdecp0 -fsyntax-only %s
 // RUN: %clang_cc1 -triple thumbv8.1m.main-arm-none-eabi -fallow-half-arguments-and-returns -target-feature +mve.fp -target-feature +cdecp0 -fsyntax-only %s
+// RUN: %clang_cc1 -xc++ -std=c++98 -triple thumbv8.1m.main-arm-none-eabi -fallow-half-arguments-and-returns -target-feature +mve -target-feature +cdecp0 -fsyntax-only %s
+// RUN: %clang_cc1 -xc++ -std=c++20 -triple thumbv8.1m.main-arm-none-eabi -fallow-half-arguments-and-returns -target-feature +mve.fp -target-feature +cdecp0 -fsyntax-only %s
+// RUN: %clang_cc1 -xc++ -triple thumbv8.1m.main-arm-none-eabi -fallow-half-arguments-and-returns -target-feature +mve.fp -target-feature +cdecp0 -fsyntax-only %s
 
 // Check that the headers don't conflict with each other
 #include 
Index: clang/test/CodeGen/arm-cde-reinterpret.c
===
--- clang/test/CodeGen/arm-cde-reinterpret.c
+++ clang/test/CodeGen/arm-cde-reinterpret.c
@@ -1,8 +1,11 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // RUN: %clang_cc1 -triple thumbv8.1m.main-arm-none-eabi \
 // RUN:   -target-feature +cdecp0 -target-feature +mve.fp \
 // RUN:   -mfloat-abi hard -O0 -disable-O0-optnone \
-// RUN:   -S -emit-llvm -o - %s | opt -S -mem2reg | FileCheck %s
+// RUN:   -S -emit-llvm -o - %s | opt -S -mem2reg | FileCheck %s --check-prefixes=CHECK,CHECK-LE
+// RUN: %clang_cc1 -triple thumbebv8.1m.main-arm-none-eabi \
+// RUN:   -target-feature +cdecp0 -target-feature +mve.fp \
+// RUN:   -mfloat-abi hard -O0 -disable-O0-optnone \
+// RUN:   -S -emit-llvm -o - %s | opt -S -mem2reg | FileCheck %s --check-prefixes=CHECK,CHECK-BE
 
 #include 
 
@@ -16,7 +19,8 @@
 
 // CHECK-LABEL: @test_u16(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <8 x i16>
+// CHECK-LE-NEXT: [[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <8 x i16>
+// CHECK-BE-NEXT: [[TMP0:%.*]] = call <8 x i16> @llvm.arm.mve.vreinterpretq.v8i16.v16i8(<16 x i8> [[X:%.*]])
 // CHECK-NEXT:ret <8 x i16> [[TMP0]]
 //
 uint16x8_t test_u16(uint8x16_t x) {
@@ -25,7 +29,8 @@
 
 // CHECK-LABEL: @test_s32(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <4 x i32>
+// CHECK-LE-NEXT: [[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <4 x i32>
+// CHECK-BE-NEXT: [[TMP0:%.*]] = call <4 x i32> @llvm.arm.mve.vreinterpretq.v4i32.v16i8(<16 x i8> [[X:%.*]])
 // CHECK-NEXT:ret <4 x i32> [[TMP0]]
 //
 int32x4_t test_s32(uint8x16_t x) {
@@ -34,7 +39,8 @@
 
 // CHECK-LABEL: @test_u32(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <4 x i32>
+// CHECK-LE-NEXT: [[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <4 x i32>
+// CHECK-BE-NEXT: [[TMP0:%.*]] = call <4 x i32> @llvm.arm.mve.vreinterpretq.v4i32.v16i8(<16 x i8> [[X:%.*]])
 // CHECK-NEXT:ret <4 x i32> [[TMP0]]
 //
 uint32x4_t test_u32(uint8x16_t x) {
@@ -43,7 +49,8 @@
 
 // CHECK-LABEL: @test_s64(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <2 x i64>
+// CHECK-LE-NEXT: [[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <2 x i64>
+// CHECK-BE-NEXT: [[TMP0:%.*]] = call <2 x i64> @llvm.arm.mve.vreinterpretq.v2i64.v16i8(<16 x i8> [[X:%.*]])
 // CHECK-NEXT:ret <2 x i64> [[TMP0]]
 //
 int64x2_t test_s64(uint8x16_t x) {
@@ -52,7 +59,8 @@
 
 // CHECK-LABEL: @test_u64(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <2 x i64>
+// CHECK-LE-NEXT: [[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <2 x i64>
+// CHECK-BE-NEXT: [[TMP0:%.*]] = call <2 x i64> @llvm.arm.mve.vreinterpretq.v2i64.v16i8(<16 x i8> [[X:%.*]])
 // CHECK-NEXT:ret <2 x i64> [[TMP0]]
 //
 uint64x2_t 

[PATCH] D76360: [PPC][AIX] Emit correct Vaarg for 32BIT-AIX in clang

2020-03-27 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA marked 2 inline comments as done.
ZarkoCA added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:4205
 
-CharUnits PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
+CharUnits PowerPC32ABIInfo::getParamTypeAlignment(QualType Ty) const {
   // Complex types are passed just like their elements

jasonliu wrote:
> sfertile wrote:
> > jasonliu wrote:
> > > So for AIX we are taking PowerPC32ABIInfo right now. And we know 
> > > EmitVAArg of this target does the right thing on AIX after the change. 
> > > But for other functions, for example, getParamTypeAlignment, 
> > > initDwarfEHRegSizeTable... Are we sure it's doing the right thing on AIX?
> > > If we are not sure, is there anything we want to do (etc, put a comment 
> > > on where it gets used or at the function definition)? Or are we fine to 
> > > just leave it as it is and have a TODO in our head?
> > Looking at the values in `initDwarfEHRegSizeTable` it has the right sizes 
> > for all the registers. Even though the OS is different the underlying 
> > hardware is the same. I'm not sure it's something that makes sense to 
> > support for AIX though, in which case I think its valid to return `true` to 
> > indicate its not supported. 
> > 
> > `getParamTypeAlignment` is used only in the context of the alignment for 
> > vaarg, we should make sure its correct for AIX since supporting vaarg is 
> > the scope of this patch.
> In that case, is it better if we have lit test to actually exercise the path 
> in getParamTypeAlignment to show that we actually confirmed the behavior is 
> correct for AIX? And if it is some path we do not care for now(ComplexType? 
> VectorType?), then we would want TODOs on them to show we need further 
> investigation later. 
>But for other functions, for example, getParamTypeAlignment, 
>initDwarfEHRegSizeTable... Are we sure it's doing the right thing on AIX?

The AIX stdarg headers show that alignment for the va_list is dependent on 
mode, so 4 on 32 and 8 on 64-bit. getParamAlignment looks like it aligns 4 for 
non-complex non-struct args. 



>If we are not sure, is there anything we want to do (etc, put a comment on 
>where it gets used or at the function definition)? Or are we fine to just 
>leave it as it is and have a TODO in our head?

We already took this path before this patch and I'm correcting some of the 
behaviour so it's correct for varargs on AIX. I think that we will need to 
address this depending on when/if we add an AIXABIInfo class.  I added a TODO 
on line 4247 for just that so I think that implies we will investigate 
everything required for the correct implementation of the whatever remains 
after the vaarg handling.  


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76360/new/

https://reviews.llvm.org/D76360



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


[clang] bd722ef - [ARM,CDE] Improve CDE intrinsics testing

2020-03-27 Thread Mikhail Maltsev via cfe-commits

Author: Mikhail Maltsev
Date: 2020-03-27T16:05:18Z
New Revision: bd722ef63f18ee672d60358113431f9bb5c55380

URL: 
https://github.com/llvm/llvm-project/commit/bd722ef63f18ee672d60358113431f9bb5c55380
DIFF: 
https://github.com/llvm/llvm-project/commit/bd722ef63f18ee672d60358113431f9bb5c55380.diff

LOG: [ARM,CDE] Improve CDE intrinsics testing

Summary:
This patch:
* adds tests for vreinterpret intinsics in big-endian mode
* adds C++ runs to the CDE+MVE header compatibility test

Reviewers: simon_tatham, MarkMurrayARM, ostannard, dmgreen

Reviewed By: simon_tatham

Subscribers: kristof.beyls, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/test/CodeGen/arm-cde-reinterpret.c
clang/test/Headers/arm-cde-header.c

Removed: 




diff  --git a/clang/test/CodeGen/arm-cde-reinterpret.c 
b/clang/test/CodeGen/arm-cde-reinterpret.c
index 569b51bdfdbe..c169a88bc4e3 100644
--- a/clang/test/CodeGen/arm-cde-reinterpret.c
+++ b/clang/test/CodeGen/arm-cde-reinterpret.c
@@ -1,8 +1,11 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // RUN: %clang_cc1 -triple thumbv8.1m.main-arm-none-eabi \
 // RUN:   -target-feature +cdecp0 -target-feature +mve.fp \
 // RUN:   -mfloat-abi hard -O0 -disable-O0-optnone \
-// RUN:   -S -emit-llvm -o - %s | opt -S -mem2reg | FileCheck %s
+// RUN:   -S -emit-llvm -o - %s | opt -S -mem2reg | FileCheck %s 
--check-prefixes=CHECK,CHECK-LE
+// RUN: %clang_cc1 -triple thumbebv8.1m.main-arm-none-eabi \
+// RUN:   -target-feature +cdecp0 -target-feature +mve.fp \
+// RUN:   -mfloat-abi hard -O0 -disable-O0-optnone \
+// RUN:   -S -emit-llvm -o - %s | opt -S -mem2reg | FileCheck %s 
--check-prefixes=CHECK,CHECK-BE
 
 #include 
 
@@ -16,7 +19,8 @@ int8x16_t test_s8(uint8x16_t x) {
 
 // CHECK-LABEL: @test_u16(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <8 x i16>
+// CHECK-LE-NEXT: [[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <8 x i16>
+// CHECK-BE-NEXT: [[TMP0:%.*]] = call <8 x i16> 
@llvm.arm.mve.vreinterpretq.v8i16.v16i8(<16 x i8> [[X:%.*]])
 // CHECK-NEXT:ret <8 x i16> [[TMP0]]
 //
 uint16x8_t test_u16(uint8x16_t x) {
@@ -25,7 +29,8 @@ uint16x8_t test_u16(uint8x16_t x) {
 
 // CHECK-LABEL: @test_s32(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <4 x i32>
+// CHECK-LE-NEXT: [[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <4 x i32>
+// CHECK-BE-NEXT: [[TMP0:%.*]] = call <4 x i32> 
@llvm.arm.mve.vreinterpretq.v4i32.v16i8(<16 x i8> [[X:%.*]])
 // CHECK-NEXT:ret <4 x i32> [[TMP0]]
 //
 int32x4_t test_s32(uint8x16_t x) {
@@ -34,7 +39,8 @@ int32x4_t test_s32(uint8x16_t x) {
 
 // CHECK-LABEL: @test_u32(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <4 x i32>
+// CHECK-LE-NEXT: [[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <4 x i32>
+// CHECK-BE-NEXT: [[TMP0:%.*]] = call <4 x i32> 
@llvm.arm.mve.vreinterpretq.v4i32.v16i8(<16 x i8> [[X:%.*]])
 // CHECK-NEXT:ret <4 x i32> [[TMP0]]
 //
 uint32x4_t test_u32(uint8x16_t x) {
@@ -43,7 +49,8 @@ uint32x4_t test_u32(uint8x16_t x) {
 
 // CHECK-LABEL: @test_s64(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <2 x i64>
+// CHECK-LE-NEXT: [[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <2 x i64>
+// CHECK-BE-NEXT: [[TMP0:%.*]] = call <2 x i64> 
@llvm.arm.mve.vreinterpretq.v2i64.v16i8(<16 x i8> [[X:%.*]])
 // CHECK-NEXT:ret <2 x i64> [[TMP0]]
 //
 int64x2_t test_s64(uint8x16_t x) {
@@ -52,7 +59,8 @@ int64x2_t test_s64(uint8x16_t x) {
 
 // CHECK-LABEL: @test_u64(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <2 x i64>
+// CHECK-LE-NEXT: [[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <2 x i64>
+// CHECK-BE-NEXT: [[TMP0:%.*]] = call <2 x i64> 
@llvm.arm.mve.vreinterpretq.v2i64.v16i8(<16 x i8> [[X:%.*]])
 // CHECK-NEXT:ret <2 x i64> [[TMP0]]
 //
 uint64x2_t test_u64(uint8x16_t x) {
@@ -61,7 +69,8 @@ uint64x2_t test_u64(uint8x16_t x) {
 
 // CHECK-LABEL: @test_f16(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <8 x half>
+// CHECK-LE-NEXT: [[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <8 x half>
+// CHECK-BE-NEXT: [[TMP0:%.*]] = call <8 x half> 
@llvm.arm.mve.vreinterpretq.v8f16.v16i8(<16 x i8> [[X:%.*]])
 // CHECK-NEXT:ret <8 x half> [[TMP0]]
 //
 float16x8_t test_f16(uint8x16_t x) {
@@ -70,7 +79,8 @@ float16x8_t test_f16(uint8x16_t x) {
 
 // CHECK-LABEL: @test_f32(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <4 x float>
+// CHECK-LE-NEXT: [[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <4 x float>
+// CHECK-BE-NEXT: [[TMP0:%.*]] = call <4 x float> 
@llvm.arm.mve.vreinterpretq.v4f32.v16i8(<16 x i8> [[X:%.*]])
 // CHECK-NEXT:ret <4 x float> [[TMP0]]
 //
 float32x4_t 

[PATCH] D76932: [AIX] emit .extern and .weak directive linkage

2020-03-27 Thread Digger via Phabricator via cfe-commits
DiggerLin created this revision.
DiggerLin added reviewers: hubert.reinterpretcast, jasonliu, sfertile, daltenty.
Herald added subscribers: cfe-commits, kbarton, hiraditya, nemanjai.
Herald added a project: clang.
DiggerLin edited the summary of this revision.
Herald added a subscriber: wuzish.
DiggerLin edited the summary of this revision.
DiggerLin edited the summary of this revision.

1. emit .extern  and .weak directive linkage
2. delete -u option for as in clang.

the c source code for test case  aix-extern-weak.ll as 
bash> cat test_extern_weak_all.c

extern int bar_extern(int* ip);
extern int bar_ref();
extern int b_e;

__attribute__ ((weak)) void foo_weak(){
}

__attribute__ ((weak)) void foo_ref_weak(){
}

extern __attribute__ ((weak)) void foo_ext_weak(void);

void foo(){ }

int (*bar_p)() = bar_ref;
void (*foo_weak_p)() = foo_ref_weak;
void (*foo_ext_weak_p)() = foo_ext_weak;

int __attribute__ ((weak)) b;
int main() {

  bar_extern();
  foo();
  bar_p(_e);
  foo_weak_p();
  foo_ext_weak_p();
  foo_weak();

}


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76932

Files:
  clang/lib/Driver/ToolChains/AIX.cpp
  llvm/include/llvm/CodeGen/AsmPrinter.h
  llvm/include/llvm/MC/MCAsmInfo.h
  llvm/include/llvm/MC/MCDirectives.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/lib/MC/MCAsmInfoXCOFF.cpp
  llvm/lib/MC/MCAsmStreamer.cpp
  llvm/lib/MC/MCXCOFFStreamer.cpp
  llvm/lib/MC/XCOFFObjectWriter.cpp
  llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
  llvm/test/CodeGen/PowerPC/aix-extern-weak.ll
  llvm/test/CodeGen/PowerPC/aix-reference-func-addr-const.ll

Index: llvm/test/CodeGen/PowerPC/aix-reference-func-addr-const.ll
===
--- llvm/test/CodeGen/PowerPC/aix-reference-func-addr-const.ll
+++ llvm/test/CodeGen/PowerPC/aix-reference-func-addr-const.ll
@@ -15,6 +15,7 @@
 ;CHECK-NEXT: .globl  foo_ptr
 ;CHECK-NEXT: .align  2
 ;CHECK-NEXT: foo_ptr:
+;CHECK-NEXT: .extern foo[DS]
 ;CHECK-NEXT: .long   foo[DS]
 ;CHECK-NEXT: .globl  bar_ptr1
 ;CHECK-NEXT: .align  2
@@ -25,6 +26,7 @@
 ;CHECK64-NEXT: .globl  foo_ptr
 ;CHECK64-NEXT: .align  3
 ;CHECK64-NEXT:foo_ptr:
+;CHECK64-NEXT:  .extern foo[DS]
 ;CHECK64-NEXT: .llong  foo[DS]
 ;CHECK64-NEXT: .globl  bar_ptr1
 ;CHECK64-NEXT: .align  3
Index: llvm/test/CodeGen/PowerPC/aix-extern-weak.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/aix-extern-weak.ll
@@ -0,0 +1,628 @@
+; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff -mcpu=pwr4 \
+; RUN: -mattr=-altivec < %s | FileCheck --check-prefixes=COMMON,BIT32 %s
+
+; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff -mcpu=pwr4 \
+; RUN: -mattr=-altivec < %s | FileCheck --check-prefixes=COMMON,BIT64 %s
+
+; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff -mcpu=pwr4 \
+; RUN: -mattr=-altivec -filetype=obj -o %t.o < %s
+; RUN: llvm-readobj  --symbols %t.o | FileCheck --check-prefix=CHECKSYM %s
+
+@bar_p = global i32 (...)* @bar_ref, align 4
+@foo_weak_p = global void (...)* bitcast (void ()* @foo_ref_weak to void (...)*), align 4
+@foo_ext_weak_p = global void (...)* bitcast (void ()* @foo_ext_weak to void (...)*), align 4
+@b = weak global i32 0, align 4
+@b_e = external global i32, align 4
+
+define weak void @foo_weak() #0 {
+entry:
+  ret void
+}
+
+define weak void @foo_ref_weak() #0 {
+entry:
+  ret void
+}
+
+define void @foo() #0 {
+entry:
+  ret void
+}
+
+declare i32 @bar_ref(...) #1
+
+declare extern_weak void @foo_ext_weak() #1
+
+define i32 @main() #0 {
+entry:
+  %call = call i32 @bar_extern(i32* @b)
+  call void @foo()
+  %0 = load i32 (...)*, i32 (...)** @bar_p, align 4
+  %callee.knr.cast = bitcast i32 (...)* %0 to i32 (i32*)*
+  %call1 = call i32 %callee.knr.cast(i32* @b_e)
+  %1 = load void (...)*, void (...)** @foo_weak_p, align 4
+  %callee.knr.cast2 = bitcast void (...)* %1 to void ()*
+  call void %callee.knr.cast2()
+  %2 = load void (...)*, void (...)** @foo_ext_weak_p, align 4
+  %callee.knr.cast3 = bitcast void (...)* %2 to void ()*
+  call void %callee.knr.cast3()
+  call void @foo_weak()
+  ret i32 0
+}
+
+declare i32 @bar_extern(i32*) #1
+
+; COMMON:  	.weak	foo_weak[DS]# -- Begin function foo_weak
+; COMMON-NEXT:	.weak	.foo_weak
+; COMMON-NEXT:	.align	4
+; COMMON-NEXT:	.csect foo_weak[DS]
+; BIT32-NEXT:	.long	.foo_weak   # @foo_weak
+; BIT32-NEXT:	.long	TOC[TC0]
+; BIT32-NEXT:	.long	0
+; BIT64-NEXT:	.llong	.foo_weak   # @foo_weak
+; BIT64-NEXT:	.llong	TOC[TC0]
+; BIT64-NEXT:	.llong	0
+; COMMON-NEXT:	.csect .text[PR]
+; COMMON-NEXT:.foo_weak:
+
+; COMMON:	.weak	foo_ref_weak[DS]# -- Begin function foo_ref_weak
+; COMMON-NEXT:	.weak	.foo_ref_weak
+; COMMON-NEXT:	.align	4
+; COMMON-NEXT:	.csect foo_ref_weak[DS]
+; BIT32-NEXT:	.long	

[PATCH] D76360: [PPC][AIX] Emit correct Vaarg for 32BIT-AIX in clang

2020-03-27 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA updated this revision to Diff 253127.
ZarkoCA added a comment.

Created PPCAIX32TargetCodeGenInfo class so that initDwarfEHRegSizeTable now 
returns true on AIX and added a test.

Fixed formatting.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76360/new/

https://reviews.llvm.org/D76360

Files:
  clang/lib/Basic/Targets/PPC.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/aix-vararg.c
  clang/test/CodeGen/aix32-dwarf-error.c

Index: clang/test/CodeGen/aix32-dwarf-error.c
===
--- /dev/null
+++ clang/test/CodeGen/aix32-dwarf-error.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -verify -emit-llvm %s
+
+static unsigned char dwarf_reg_size_table[1024];
+
+int test() {
+  __builtin_init_dwarf_reg_size_table(dwarf_reg_size_table); //expected-error {{cannot compile this __builtin_init_dwarf_reg_size_table yet}}
+  return __builtin_dwarf_sp_column();
+}
Index: clang/test/CodeGen/aix-vararg.c
===
--- /dev/null
+++ clang/test/CodeGen/aix-vararg.c
@@ -0,0 +1,40 @@
+// REQUIRES: powerpc-registered-target
+// REQUIRES: asserts
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -emit-llvm -o - %s | FileCheck %s --check-prefix=32BIT
+#include 
+
+void aix_varg(int a, ...) {
+  va_list arg;
+  va_start(arg, a);
+  va_list arg2;
+  va_arg(arg, int);
+  va_copy(arg2, arg);
+  va_end(arg);
+  va_end(arg2);
+}
+
+// 32BIT:   define void @aix_varg(i32 %a, ...) #0 {
+// 32BIT-NEXT:  entry:
+// 32BIT-NEXT:%a.addr = alloca i32, align 4
+// 32BIT-NEXT:%arg = alloca i8*, align 4
+// 32BIT-NEXT:%arg2 = alloca i8*, align 4
+// 32BIT-NEXT:store i32 %a, i32* %a.addr, align 4
+// 32BIT-NEXT:%arg1 = bitcast i8** %arg to i8*
+// 32BIT-NEXT:call void @llvm.va_start(i8* %arg1)
+// 32BIT-NEXT:%argp.cur = load i8*, i8** %arg, align 4
+// 32BIT-NEXT:%argp.next = getelementptr inbounds i8, i8* %argp.cur, i32 4
+// 32BIT-NEXT:store i8* %argp.next, i8** %arg, align 4
+// 32BIT-NEXT:%0 = bitcast i8* %argp.cur to i32*
+// 32BIT-NEXT:%1 = load i32, i32* %0, align 4
+// 32BIT-NEXT:%2 = bitcast i8** %arg2 to i8*
+// 32BIT-NEXT:%3 = bitcast i8** %arg to i8*
+// 32BIT-NEXT:call void @llvm.va_copy(i8* %2, i8* %3)
+// 32BIT-NEXT:%arg3 = bitcast i8** %arg to i8*
+// 32BIT-NEXT:call void @llvm.va_end(i8* %arg3)
+// 32BIT-NEXT:%arg24 = bitcast i8** %arg2 to i8*
+// 32BIT-NEXT:call void @llvm.va_end(i8* %arg24)
+// 32BIT-NEXT:ret void
+// 32BIT-NEXT:  }
+// 32BIT: declare void @llvm.va_start(i8*) #1
+// 32BIT: declare void @llvm.va_copy(i8*, i8*) #1
+// 32BIT: declare void @llvm.va_end(i8*) #1
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -4173,14 +4173,15 @@
 
 // PowerPC-32
 namespace {
-/// PPC32_SVR4_ABIInfo - The 32-bit PowerPC ELF (SVR4) ABI information.
-class PPC32_SVR4_ABIInfo : public DefaultABIInfo {
+/// PowerPC32ABIInfo - The 32-bit PowerPC ABI information, used by PowerPC ELF
+/// (SVR4), Darwin and AIX.
+class PowerPC32ABIInfo : public DefaultABIInfo {
   bool IsSoftFloatABI;
 
   CharUnits getParamTypeAlignment(QualType Ty) const;
 
 public:
-  PPC32_SVR4_ABIInfo(CodeGen::CodeGenTypes , bool SoftFloatABI)
+  PowerPC32ABIInfo(CodeGen::CodeGenTypes , bool SoftFloatABI)
   : DefaultABIInfo(CGT), IsSoftFloatABI(SoftFloatABI) {}
 
   Address EmitVAArg(CodeGenFunction , Address VAListAddr,
@@ -4190,7 +4191,7 @@
 class PPC32TargetCodeGenInfo : public TargetCodeGenInfo {
 public:
   PPC32TargetCodeGenInfo(CodeGenTypes , bool SoftFloatABI)
-  : TargetCodeGenInfo(new PPC32_SVR4_ABIInfo(CGT, SoftFloatABI)) {}
+  : TargetCodeGenInfo(new PowerPC32ABIInfo(CGT, SoftFloatABI)) {}
 
   int getDwarfEHStackPointer(CodeGen::CodeGenModule ) const override {
 // This is recovered from gcc output.
@@ -4200,9 +4201,22 @@
   bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction ,
llvm::Value *Address) const override;
 };
+
+class PPCAIX32TargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  PPCAIX32TargetCodeGenInfo(CodeGenTypes , bool SoftFloatABI)
+  : TargetCodeGenInfo(new PowerPC32ABIInfo(CGT, SoftFloatABI)) {}
+
+  int getDwarfEHStackPointer(CodeGen::CodeGenModule ) const override {
+return 1; // r1 is the dedicated stack pointer
+  }
+
+  bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction ,
+   llvm::Value *Address) const override;
+};
 }
 
-CharUnits PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
+CharUnits PowerPC32ABIInfo::getParamTypeAlignment(QualType Ty) const {
   // Complex types are passed just like their elements
   if (const ComplexType *CTy = Ty->getAs())
 Ty = CTy->getElementType();
@@ 

[PATCH] D33029: [clang-format] add option for dangling parenthesis

2020-03-27 Thread Ryan Stringham via Phabricator via cfe-commits
stringham added a comment.

Here's a commit rebased as of yesterday that is still adding 
DanglingParenthesis option instead of extending the BracketAlignmentStyle 
configuration.

https://github.com/lucidsoftware/llvm-project/commit/3c04de1feffaa9787234da8fe3cf288eebc979d6


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D33029/new/

https://reviews.llvm.org/D33029



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


[clang] ee27df5 - Revert "[OPENMP50]Add basic support for inscan reduction modifier."

2020-03-27 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-03-27T11:25:47-04:00
New Revision: ee27df5552de5a9e9ac536dd193d927368248d17

URL: 
https://github.com/llvm/llvm-project/commit/ee27df5552de5a9e9ac536dd193d927368248d17
DIFF: 
https://github.com/llvm/llvm-project/commit/ee27df5552de5a9e9ac536dd193d927368248d17.diff

LOG: Revert "[OPENMP50]Add basic support for inscan reduction modifier."

This reverts commit 36ed0ceec7d3b0bff9de462d4f4f544d4b5285e4 to fix a
crash in scan_messages.cpp test.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/OpenMPKinds.def
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/nesting_of_regions.cpp
clang/test/OpenMP/parallel_for_reduction_messages.cpp
clang/test/OpenMP/parallel_reduction_messages.c
clang/test/OpenMP/scan_ast_print.cpp
clang/test/OpenMP/scan_messages.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 549ba4447a3f..044d35f19e20 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10101,19 +10101,6 @@ def err_omp_depobj_single_clause_expected : Error<
   "exactly one of 'depend', 'destroy', or 'update' clauses is expected">;
 def err_omp_scan_single_clause_expected : Error<
   "exactly one of 'inclusive' or 'exclusive' clauses is expected">;
-def err_omp_inclusive_exclusive_not_reduction : Error<
-  "the list item must appear in 'reduction' clause with the 'inscan' modifier "
-  "of the parent directive">;
-def err_omp_reduction_not_inclusive_exclusive : Error<
-  "the inscan reduction list item must appear as a list item in an 'inclusive' 
or"
-  " 'exclusive' clause on an inner 'omp scan' directive">;
-def err_omp_wrong_inscan_reduction : Error<
-  "'inscan' modifier can be used only in 'omp for', 'omp simd', 'omp for 
simd',"
-  " 'omp parallel for', or 'omp parallel for simd' directive">;
-def err_omp_inscan_reduction_expected : Error<
-  "expected 'reduction' clause with the 'inscan' modifier">;
-def note_omp_previous_inscan_reduction : Note<
-  "'reduction' clause with 'inscan' modifier is used here">;
 def err_omp_expected_predefined_allocator : Error<
   "expected one of the predefined allocators for the variables with the static 
"
   "storage: 'omp_default_mem_alloc', 'omp_large_cap_mem_alloc', "

diff  --git a/clang/include/clang/Basic/OpenMPKinds.def 
b/clang/include/clang/Basic/OpenMPKinds.def
index 3cf92ead9560..bfb41ab105ea 100644
--- a/clang/include/clang/Basic/OpenMPKinds.def
+++ b/clang/include/clang/Basic/OpenMPKinds.def
@@ -1112,7 +1112,6 @@ OPENMP_DEPOBJ_CLAUSE(update)
 
 // Modifiers for 'reduction' clause.
 OPENMP_REDUCTION_MODIFIER(default)
-OPENMP_REDUCTION_MODIFIER(inscan)
 
 #undef OPENMP_REDUCTION_MODIFIER
 #undef OPENMP_SCAN_CLAUSE

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index b10cdb4f3e40..318b075db8bd 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -62,15 +62,14 @@ class DSAStackTy {
   struct DSAVarData {
 OpenMPDirectiveKind DKind = OMPD_unknown;
 OpenMPClauseKind CKind = OMPC_unknown;
-unsigned Modifier = 0;
 const Expr *RefExpr = nullptr;
 DeclRefExpr *PrivateCopy = nullptr;
 SourceLocation ImplicitDSALoc;
 DSAVarData() = default;
 DSAVarData(OpenMPDirectiveKind DKind, OpenMPClauseKind CKind,
const Expr *RefExpr, DeclRefExpr *PrivateCopy,
-   SourceLocation ImplicitDSALoc, unsigned Modifier)
-: DKind(DKind), CKind(CKind), Modifier(Modifier), RefExpr(RefExpr),
+   SourceLocation ImplicitDSALoc)
+: DKind(DKind), CKind(CKind), RefExpr(RefExpr),
   PrivateCopy(PrivateCopy), ImplicitDSALoc(ImplicitDSALoc) {}
   };
   using OperatorOffsetTy =
@@ -81,7 +80,6 @@ class DSAStackTy {
 private:
   struct DSAInfo {
 OpenMPClauseKind Attributes = OMPC_unknown;
-unsigned Modifier = 0;
 /// Pointer to a reference expression and a flag which shows that the
 /// variable is marked as lastprivate(true) or not (false).
 llvm::PointerIntPair RefExpr;
@@ -166,8 +164,6 @@ class DSAStackTy {
 /// List of globals marked as declare target link in this target region
 /// (isOpenMPTargetExecutionDirective(Directive) == true).
 llvm::SmallVector DeclareTargetLinkVarDecls;
-/// List of decls used in inclusive/exclusive clauses of the scan 
directive.
-llvm::DenseSet> UsedInScanDirective;
 SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name,
  Scope *CurScope, SourceLocation Loc)
 : Directive(DKind), DirectiveName(Name), CurScope(CurScope),
@@ -473,20 +469,9 @@ class DSAStackTy {
   /// parent directive.
   const ValueDecl *getParentLoopControlVariable(unsigned I) const;
 
-  /// Marks the specified decl \p D as used 

[PATCH] D76929: [AArch64][SVE] Add SVE intrinsic for LD1RQ

2020-03-27 Thread Kerry McLaughlin via Phabricator via cfe-commits
kmclaughlin created this revision.
kmclaughlin added reviewers: andwar, sdesmalen, efriedma, cameron.mcinally, 
dancgr.
Herald added subscribers: danielkiss, psnobl, rkruppe, hiraditya, 
kristof.beyls, tschuett.
Herald added a reviewer: rengolin.
Herald added a project: LLVM.

Adds the following intrinsic for contiguous load & replicate:

- @llvm.aarch64.sve.ld1rq


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76929

Files:
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.h
  llvm/lib/Target/AArch64/AArch64InstrFormats.td
  llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
  llvm/test/CodeGen/AArch64/sve-intrinsics-loads.ll

Index: llvm/test/CodeGen/AArch64/sve-intrinsics-loads.ll
===
--- llvm/test/CodeGen/AArch64/sve-intrinsics-loads.ll
+++ llvm/test/CodeGen/AArch64/sve-intrinsics-loads.ll
@@ -1,6 +1,141 @@
 ; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s
 
 ;
+; LD1RQB
+;
+
+define  @ld1rqb_i8( %pred, i8* %addr) {
+; CHECK-LABEL: ld1rqb_i8:
+; CHECK: ld1rqb { z0.b }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %res = call  @llvm.aarch64.sve.ld1rq.nxv16i8( %pred, i8* %addr)
+  ret  %res
+}
+
+define  @ld1rqb_i8_imm( %pred, i8* %addr) {
+; CHECK-LABEL: ld1rqb_i8_imm:
+; CHECK: ld1rqb { z0.b }, p0/z, [x0, #16]
+; CHECK-NEXT: ret
+  %ptr = getelementptr inbounds i8, i8* %addr, i8 16
+  %res = call  @llvm.aarch64.sve.ld1rq.nxv16i8( %pred, i8* %ptr)
+  ret  %res
+}
+
+;
+; LD1RQH
+;
+
+define  @ld1rqh_i16( %pred, i16* %addr) {
+; CHECK-LABEL: ld1rqh_i16:
+; CHECK: ld1rqh { z0.h }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %res = call  @llvm.aarch64.sve.ld1rq.nxv8i16( %pred, i16* %addr)
+  ret  %res
+}
+
+define  @ld1rqh_f16( %pred, half* %addr) {
+; CHECK-LABEL: ld1rqh_f16:
+; CHECK: ld1rqh { z0.h }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %res = call  @llvm.aarch64.sve.ld1rq.nxv8f16( %pred, half* %addr)
+  ret  %res
+}
+
+define  @ld1rqh_i16_imm( %pred, i16* %addr) {
+; CHECK-LABEL: ld1rqh_i16_imm:
+; CHECK: ld1rqh { z0.h }, p0/z, [x0, #-64]
+; CHECK-NEXT: ret
+  %ptr = getelementptr inbounds i16, i16* %addr, i16 -32
+  %res = call  @llvm.aarch64.sve.ld1rq.nxv8i16( %pred, i16* %ptr)
+  ret  %res
+}
+
+define  @ld1rqh_f16_imm( %pred, half* %addr) {
+; CHECK-LABEL: ld1rqh_f16_imm:
+; CHECK: ld1rqh { z0.h }, p0/z, [x0, #-16]
+; CHECK-NEXT: ret
+  %ptr = getelementptr inbounds half, half* %addr, i16 -8
+  %res = call  @llvm.aarch64.sve.ld1rq.nxv8f16( %pred, half* %ptr)
+  ret  %res
+}
+
+;
+; LD1RQW
+;
+
+define  @ld1rqw_i32( %pred, i32* %addr) {
+; CHECK-LABEL: ld1rqw_i32:
+; CHECK: ld1rqw { z0.s }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %res = call  @llvm.aarch64.sve.ld1rq.nxv4i32( %pred, i32* %addr)
+  ret  %res
+}
+
+define  @ld1rqw_f32( %pred, float* %addr) {
+; CHECK-LABEL: ld1rqw_f32:
+; CHECK: ld1rqw { z0.s }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %res = call  @llvm.aarch64.sve.ld1rq.nxv4f32( %pred, float* %addr)
+  ret  %res
+}
+
+define  @ld1rqw_i32_imm( %pred, i32* %addr) {
+; CHECK-LABEL: ld1rqw_i32_imm:
+; CHECK: ld1rqw { z0.s }, p0/z, [x0, #112]
+; CHECK-NEXT: ret
+  %ptr = getelementptr inbounds i32, i32* %addr, i32 28
+  %res = call  @llvm.aarch64.sve.ld1rq.nxv4i32( %pred, i32* %ptr)
+  ret  %res
+}
+
+define  @ld1rqw_f32_imm( %pred, float* %addr) {
+; CHECK-LABEL: ld1rqw_f32_imm:
+; CHECK: ld1rqw { z0.s }, p0/z, [x0, #32]
+; CHECK-NEXT: ret
+  %ptr = getelementptr inbounds float, float* %addr, i32 8
+  %res = call  @llvm.aarch64.sve.ld1rq.nxv4f32( %pred, float* %ptr)
+  ret  %res
+}
+
+;
+; LD1RQD
+;
+
+define  @ld1rqd_i64( %pred, i64* %addr) {
+; CHECK-LABEL: ld1rqd_i64:
+; CHECK: ld1rqd { z0.d }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %res = call  @llvm.aarch64.sve.ld1rq.nxv2i64( %pred, i64* %addr)
+  ret  %res
+}
+
+define  @ld1rqd_f64( %pred, double* %addr) {
+; CHECK-LABEL: ld1rqd_f64:
+; CHECK: ld1rqd { z0.d }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %res = call  @llvm.aarch64.sve.ld1rq.nxv2f64( %pred, double* %addr)
+  ret  %res
+}
+
+define  @ld1rqd_i64_imm( %pred, i64* %addr) {
+; CHECK-LABEL: ld1rqd_i64_imm:
+; CHECK: ld1rqd { z0.d }, p0/z, [x0, #64]
+; CHECK-NEXT: ret
+  %ptr = getelementptr inbounds i64, i64* %addr, i64 8
+  %res = call  @llvm.aarch64.sve.ld1rq.nxv2i64( %pred, i64* %ptr)
+  ret  %res
+}
+
+define  @ld1rqd_f64_imm( %pred, double* %addr) {
+; CHECK-LABEL: ld1rqd_f64_imm:
+; CHECK: ld1rqd { z0.d }, p0/z, [x0, #-128]
+; CHECK-NEXT: ret
+  %ptr = getelementptr inbounds double, double* %addr, i64 -16
+  %res = call  @llvm.aarch64.sve.ld1rq.nxv2f64( %pred, double* %ptr)
+  ret  %res
+}
+
+;
 ; LDNT1B
 ;
 
@@ -79,6 +214,14 @@
   ret  %res
 }
 
+declare  @llvm.aarch64.sve.ld1rq.nxv16i8(, i8*)
+declare  @llvm.aarch64.sve.ld1rq.nxv8i16(, i16*)
+declare  @llvm.aarch64.sve.ld1rq.nxv4i32(, i32*)
+declare  @llvm.aarch64.sve.ld1rq.nxv2i64(, i64*)
+declare  @llvm.aarch64.sve.ld1rq.nxv8f16(, half*)
+declare  @llvm.aarch64.sve.ld1rq.nxv4f32(, 

[PATCH] D75286: [clangd] Handle clang-tidy suppression comments for diagnostics inside macro expansions

2020-03-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Thanks a lot!




Comment at: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp:301
+bool AllowIO) {
+  // This is similar to the implementation of 
SourceManager::getCharacterData(),
+  // but uses ContentCache::getRawBuffer() rather than getBuffer() if

nit: the peer function to reference is SourceManager::getBufferData


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75286/new/

https://reviews.llvm.org/D75286



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


[PATCH] D76922: [Syntax] Remove delayed folding from tree building.

2020-03-27 Thread Marcel Hlopko via Phabricator via cfe-commits
hlopko updated this revision to Diff 253122.
hlopko added a comment.

Polish


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76922/new/

https://reviews.llvm.org/D76922

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -224,6 +224,59 @@
 )txt");
 }
 
+TEST_F(SyntaxTreeTest, SimpleVariable) {
+  expectTreeDumpEqual(
+  R"cpp(
+int a;
+int b = 42;
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | `-a
+| `-;
+`-SimpleDeclaration
+  |-int
+  |-SimpleDeclarator
+  | |-b
+  | |-=
+  | `-UnknownExpression
+  |   `-42
+  `-;
+)txt");
+}
+
+TEST_F(SyntaxTreeTest, SimpleFunction) {
+  expectTreeDumpEqual(
+  R"cpp(
+void foo(int a, int b) {}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-foo
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-b
+  |   `-)
+  `-CompoundStatement
+|-{
+`-}
+)txt");
+}
+
 TEST_F(SyntaxTreeTest, If) {
   expectTreeDumpEqual(
   R"cpp(
@@ -541,20 +594,32 @@
 TEST_F(SyntaxTreeTest, MultipleDeclaratorsGrouping) {
   expectTreeDumpEqual(
   R"cpp(
-  int *a, b;
+  int *a, b; int *c, d;
   )cpp",
   R"txt(
 *: TranslationUnit
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-*
+| | `-a
+| |-,
+| |-SimpleDeclarator
+| | `-b
+| `-;
 `-SimpleDeclaration
   |-int
   |-SimpleDeclarator
   | |-*
-  | `-a
+  | `-c
   |-,
   |-SimpleDeclarator
-  | `-b
+  | `-d
   `-;
   )txt");
+}
+
+TEST_F(SyntaxTreeTest, MultipleDeclaratorsGroupingTypedef) {
   expectTreeDumpEqual(
   R"cpp(
 typedef int *a, b;
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -645,8 +645,8 @@
 }
 
 std::string syntax::Token::dumpForTests(const SourceManager ) const {
-  return std::string(
-  llvm::formatv("{0}   {1}", tok::getTokenName(kind()), text(SM)));
+  return std::string(llvm::formatv("Token(`{0}`, {1}, length = {2})", text(SM),
+   tok::getTokenName(kind()), length()));
 }
 
 std::string TokenBuffer::dumpForTests() const {
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -44,15 +44,6 @@
 LLVM_ATTRIBUTE_UNUSED
 static bool isImplicitExpr(clang::Expr *E) { return E->IgnoreImplicit() != E; }
 
-static SourceLocation getQualifiedNameStart(DeclaratorDecl *D) {
-  auto DN = D->getDeclName();
-  bool IsAnonymous = DN.isIdentifier() && !DN.getAsIdentifierInfo();
-  if (IsAnonymous)
-return SourceLocation();
-  return D->getQualifierLoc() ? D->getQualifierLoc().getBeginLoc()
-  : D->getLocation();
-}
-
 namespace {
 /// Get start location of the Declarator from the TypeLoc.
 /// E.g.:
@@ -212,10 +203,6 @@
 foldNode(Range, New, nullptr);
   }
 
-  /// Must be called with the range of each `DeclaratorDecl`. Ensures the
-  /// corresponding declarator nodes are covered by `SimpleDeclaration`.
-  void noticeDeclRange(llvm::ArrayRef Range);
-
   /// Notifies that we should not consume trailing semicolon when computing
   /// token range of \p D.
   void noticeDeclWithoutSemicolon(Decl *D);
@@ -237,11 +224,6 @@
   void markChild(syntax::Node *N, NodeRole R);
   /// Set role for the syntax node matching \p N.
   void markChild(ASTPtr N, NodeRole R);
-  /// Set role for the delayed node that spans exactly \p Range.
-  void markDelayedChild(llvm::ArrayRef Range, NodeRole R);
-  /// Set role for the node that may or may not be delayed. Node must span
-  /// exactly \p Range.
-  void markMaybeDelayedChild(llvm::ArrayRef Range, NodeRole R);
 
   /// Finish building the tree and consume the root node.
   syntax::TranslationUnit *finalize() && {
@@ -285,7 +267,43 @@
 return maybeAppendSemicolon(Tokens, D);
   }
 
-  llvm::ArrayRef getDeclRange(const Decl *D) const {
+  /// Returns true if \p D is the last declarator in a chain and is thus
+  /// reponsible for creating SimpleDeclaration for the whole chain.
+  template 
+  bool isResponsibleForCreatingDeclaration(const T *D) const {
+static_assert((std::is_base_of::value ||
+   std::is_base_of::value),
+  "only DeclaratorDecl and TypedefNameDecl are supported.");
+
+const auto *TD = llvm::dyn_cast(D);
+if (TD == 

[PATCH] D76927: [ARM,CDE] Improve CDE intrinsics testing

2020-03-27 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki created this revision.
miyuki added reviewers: simon_tatham, MarkMurrayARM, ostannard, dmgreen.
Herald added subscribers: cfe-commits, kristof.beyls.
Herald added a project: clang.

This patch:

- adds tests for vreinterpret intinsics in big-endian mode
- adds C++ runs to the CDE+MVE header compatibility test


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76927

Files:
  clang/test/CodeGen/arm-cde-reinterpret.c
  clang/test/Headers/arm-cde-header.c

Index: clang/test/Headers/arm-cde-header.c
===
--- clang/test/Headers/arm-cde-header.c
+++ clang/test/Headers/arm-cde-header.c
@@ -1,7 +1,9 @@
 // RUN: %clang_cc1 -std=c89 -triple thumbv8.1m.main-arm-none-eabi -fallow-half-arguments-and-returns -target-feature +mve.fp -target-feature +cdecp0 -fsyntax-only %s
-// RUN: %clang_cc1 -std=c99 -triple thumbv8.1m.main-arm-none-eabi -fallow-half-arguments-and-returns -target-feature +mve.fp -target-feature +cdecp0 -fsyntax-only %s
-// RUN: %clang_cc1 -std=c11 -triple thumbv8.1m.main-arm-none-eabi -fallow-half-arguments-and-returns -target-feature +mve.fp -target-feature +cdecp0 -fsyntax-only %s
+// RUN: %clang_cc1 -std=c17 -triple thumbv8.1m.main-arm-none-eabi -fallow-half-arguments-and-returns -target-feature +mve -target-feature +cdecp0 -fsyntax-only %s
 // RUN: %clang_cc1 -triple thumbv8.1m.main-arm-none-eabi -fallow-half-arguments-and-returns -target-feature +mve.fp -target-feature +cdecp0 -fsyntax-only %s
+// RUN: %clang_cc1 -xc++ -std=c++98 -triple thumbv8.1m.main-arm-none-eabi -fallow-half-arguments-and-returns -target-feature +mve -target-feature +cdecp0 -fsyntax-only %s
+// RUN: %clang_cc1 -xc++ -std=c++20 -triple thumbv8.1m.main-arm-none-eabi -fallow-half-arguments-and-returns -target-feature +mve.fp -target-feature +cdecp0 -fsyntax-only %s
+// RUN: %clang_cc1 -xc++ -triple thumbv8.1m.main-arm-none-eabi -fallow-half-arguments-and-returns -target-feature +mve.fp -target-feature +cdecp0 -fsyntax-only %s
 
 // Check that the headers don't conflict with each other
 #include 
Index: clang/test/CodeGen/arm-cde-reinterpret.c
===
--- clang/test/CodeGen/arm-cde-reinterpret.c
+++ clang/test/CodeGen/arm-cde-reinterpret.c
@@ -1,8 +1,11 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // RUN: %clang_cc1 -triple thumbv8.1m.main-arm-none-eabi \
 // RUN:   -target-feature +cdecp0 -target-feature +mve.fp \
 // RUN:   -mfloat-abi hard -O0 -disable-O0-optnone \
-// RUN:   -S -emit-llvm -o - %s | opt -S -mem2reg | FileCheck %s
+// RUN:   -S -emit-llvm -o - %s | opt -S -mem2reg | FileCheck %s --check-prefixes=CHECK,CHECK-LE
+// RUN: %clang_cc1 -triple thumbebv8.1m.main-arm-none-eabi \
+// RUN:   -target-feature +cdecp0 -target-feature +mve.fp \
+// RUN:   -mfloat-abi hard -O0 -disable-O0-optnone \
+// RUN:   -S -emit-llvm -o - %s | opt -S -mem2reg | FileCheck %s --check-prefixes=CHECK,CHECK-BE
 
 #include 
 
@@ -16,7 +19,8 @@
 
 // CHECK-LABEL: @test_u16(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <8 x i16>
+// CHECK-LE-NEXT: [[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <8 x i16>
+// CHECK-BE-NEXT: [[TMP0:%.*]] = call <8 x i16> @llvm.arm.mve.vreinterpretq.v8i16.v16i8(<16 x i8> [[X:%.*]])
 // CHECK-NEXT:ret <8 x i16> [[TMP0]]
 //
 uint16x8_t test_u16(uint8x16_t x) {
@@ -25,7 +29,8 @@
 
 // CHECK-LABEL: @test_s32(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <4 x i32>
+// CHECK-LE-NEXT: [[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <4 x i32>
+// CHECK-BE-NEXT: [[TMP0:%.*]] = call <4 x i32> @llvm.arm.mve.vreinterpretq.v4i32.v16i8(<16 x i8> [[X:%.*]])
 // CHECK-NEXT:ret <4 x i32> [[TMP0]]
 //
 int32x4_t test_s32(uint8x16_t x) {
@@ -34,7 +39,8 @@
 
 // CHECK-LABEL: @test_u32(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <4 x i32>
+// CHECK-LE-NEXT: [[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <4 x i32>
+// CHECK-BE-NEXT: [[TMP0:%.*]] = call <4 x i32> @llvm.arm.mve.vreinterpretq.v4i32.v16i8(<16 x i8> [[X:%.*]])
 // CHECK-NEXT:ret <4 x i32> [[TMP0]]
 //
 uint32x4_t test_u32(uint8x16_t x) {
@@ -43,7 +49,8 @@
 
 // CHECK-LABEL: @test_s64(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <2 x i64>
+// CHECK-LE-NEXT: [[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <2 x i64>
+// CHECK-BE-NEXT: [[TMP0:%.*]] = call <2 x i64> @llvm.arm.mve.vreinterpretq.v2i64.v16i8(<16 x i8> [[X:%.*]])
 // CHECK-NEXT:ret <2 x i64> [[TMP0]]
 //
 int64x2_t test_s64(uint8x16_t x) {
@@ -52,7 +59,8 @@
 
 // CHECK-LABEL: @test_u64(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <2 x i64>
+// CHECK-LE-NEXT: [[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <2 x i64>
+// CHECK-BE-NEXT: [[TMP0:%.*]] = call <2 x i64> @llvm.arm.mve.vreinterpretq.v2i64.v16i8(<16 x 

[PATCH] D76922: [Syntax] Remove delayed folding from tree building.

2020-03-27 Thread Marcel Hlopko via Phabricator via cfe-commits
hlopko updated this revision to Diff 253123.
hlopko added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76922/new/

https://reviews.llvm.org/D76922

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -224,6 +224,59 @@
 )txt");
 }
 
+TEST_F(SyntaxTreeTest, SimpleVariable) {
+  expectTreeDumpEqual(
+  R"cpp(
+int a;
+int b = 42;
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | `-a
+| `-;
+`-SimpleDeclaration
+  |-int
+  |-SimpleDeclarator
+  | |-b
+  | |-=
+  | `-UnknownExpression
+  |   `-42
+  `-;
+)txt");
+}
+
+TEST_F(SyntaxTreeTest, SimpleFunction) {
+  expectTreeDumpEqual(
+  R"cpp(
+void foo(int a, int b) {}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-foo
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-b
+  |   `-)
+  `-CompoundStatement
+|-{
+`-}
+)txt");
+}
+
 TEST_F(SyntaxTreeTest, If) {
   expectTreeDumpEqual(
   R"cpp(
@@ -541,20 +594,32 @@
 TEST_F(SyntaxTreeTest, MultipleDeclaratorsGrouping) {
   expectTreeDumpEqual(
   R"cpp(
-  int *a, b;
+  int *a, b; int *c, d;
   )cpp",
   R"txt(
 *: TranslationUnit
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-*
+| | `-a
+| |-,
+| |-SimpleDeclarator
+| | `-b
+| `-;
 `-SimpleDeclaration
   |-int
   |-SimpleDeclarator
   | |-*
-  | `-a
+  | `-c
   |-,
   |-SimpleDeclarator
-  | `-b
+  | `-d
   `-;
   )txt");
+}
+
+TEST_F(SyntaxTreeTest, MultipleDeclaratorsGroupingTypedef) {
   expectTreeDumpEqual(
   R"cpp(
 typedef int *a, b;
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -645,8 +645,8 @@
 }
 
 std::string syntax::Token::dumpForTests(const SourceManager ) const {
-  return std::string(
-  llvm::formatv("{0}   {1}", tok::getTokenName(kind()), text(SM)));
+  return std::string(llvm::formatv("Token(`{0}`, {1}, length = {2})", text(SM),
+   tok::getTokenName(kind()), length()));
 }
 
 std::string TokenBuffer::dumpForTests() const {
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -44,15 +44,6 @@
 LLVM_ATTRIBUTE_UNUSED
 static bool isImplicitExpr(clang::Expr *E) { return E->IgnoreImplicit() != E; }
 
-static SourceLocation getQualifiedNameStart(DeclaratorDecl *D) {
-  auto DN = D->getDeclName();
-  bool IsAnonymous = DN.isIdentifier() && !DN.getAsIdentifierInfo();
-  if (IsAnonymous)
-return SourceLocation();
-  return D->getQualifierLoc() ? D->getQualifierLoc().getBeginLoc()
-  : D->getLocation();
-}
-
 namespace {
 /// Get start location of the Declarator from the TypeLoc.
 /// E.g.:
@@ -212,10 +203,6 @@
 foldNode(Range, New, nullptr);
   }
 
-  /// Must be called with the range of each `DeclaratorDecl`. Ensures the
-  /// corresponding declarator nodes are covered by `SimpleDeclaration`.
-  void noticeDeclRange(llvm::ArrayRef Range);
-
   /// Notifies that we should not consume trailing semicolon when computing
   /// token range of \p D.
   void noticeDeclWithoutSemicolon(Decl *D);
@@ -237,11 +224,6 @@
   void markChild(syntax::Node *N, NodeRole R);
   /// Set role for the syntax node matching \p N.
   void markChild(ASTPtr N, NodeRole R);
-  /// Set role for the delayed node that spans exactly \p Range.
-  void markDelayedChild(llvm::ArrayRef Range, NodeRole R);
-  /// Set role for the node that may or may not be delayed. Node must span
-  /// exactly \p Range.
-  void markMaybeDelayedChild(llvm::ArrayRef Range, NodeRole R);
 
   /// Finish building the tree and consume the root node.
   syntax::TranslationUnit *finalize() && {
@@ -285,7 +267,43 @@
 return maybeAppendSemicolon(Tokens, D);
   }
 
-  llvm::ArrayRef getDeclRange(const Decl *D) const {
+  /// Returns true if \p D is the last declarator in a chain and is thus
+  /// reponsible for creating SimpleDeclaration for the whole chain.
+  template 
+  bool isResponsibleForCreatingDeclaration(const T *D) const {
+static_assert((std::is_base_of::value ||
+   std::is_base_of::value),
+  "only DeclaratorDecl and TypedefNameDecl are supported.");
+
+const auto *TD = llvm::dyn_cast(D);
+if (TD == 

[clang] 36ed0ce - [OPENMP50]Add basic support for inscan reduction modifier.

2020-03-27 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-03-27T10:38:25-04:00
New Revision: 36ed0ceec7d3b0bff9de462d4f4f544d4b5285e4

URL: 
https://github.com/llvm/llvm-project/commit/36ed0ceec7d3b0bff9de462d4f4f544d4b5285e4
DIFF: 
https://github.com/llvm/llvm-project/commit/36ed0ceec7d3b0bff9de462d4f4f544d4b5285e4.diff

LOG: [OPENMP50]Add basic support for inscan reduction modifier.

Added basic support (parsing/sema checks) for the inscan modifier in the
reduction clauses.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/OpenMPKinds.def
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/nesting_of_regions.cpp
clang/test/OpenMP/parallel_for_reduction_messages.cpp
clang/test/OpenMP/parallel_reduction_messages.c
clang/test/OpenMP/scan_ast_print.cpp
clang/test/OpenMP/scan_messages.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 044d35f19e20..549ba4447a3f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10101,6 +10101,19 @@ def err_omp_depobj_single_clause_expected : Error<
   "exactly one of 'depend', 'destroy', or 'update' clauses is expected">;
 def err_omp_scan_single_clause_expected : Error<
   "exactly one of 'inclusive' or 'exclusive' clauses is expected">;
+def err_omp_inclusive_exclusive_not_reduction : Error<
+  "the list item must appear in 'reduction' clause with the 'inscan' modifier "
+  "of the parent directive">;
+def err_omp_reduction_not_inclusive_exclusive : Error<
+  "the inscan reduction list item must appear as a list item in an 'inclusive' 
or"
+  " 'exclusive' clause on an inner 'omp scan' directive">;
+def err_omp_wrong_inscan_reduction : Error<
+  "'inscan' modifier can be used only in 'omp for', 'omp simd', 'omp for 
simd',"
+  " 'omp parallel for', or 'omp parallel for simd' directive">;
+def err_omp_inscan_reduction_expected : Error<
+  "expected 'reduction' clause with the 'inscan' modifier">;
+def note_omp_previous_inscan_reduction : Note<
+  "'reduction' clause with 'inscan' modifier is used here">;
 def err_omp_expected_predefined_allocator : Error<
   "expected one of the predefined allocators for the variables with the static 
"
   "storage: 'omp_default_mem_alloc', 'omp_large_cap_mem_alloc', "

diff  --git a/clang/include/clang/Basic/OpenMPKinds.def 
b/clang/include/clang/Basic/OpenMPKinds.def
index bfb41ab105ea..3cf92ead9560 100644
--- a/clang/include/clang/Basic/OpenMPKinds.def
+++ b/clang/include/clang/Basic/OpenMPKinds.def
@@ -1112,6 +1112,7 @@ OPENMP_DEPOBJ_CLAUSE(update)
 
 // Modifiers for 'reduction' clause.
 OPENMP_REDUCTION_MODIFIER(default)
+OPENMP_REDUCTION_MODIFIER(inscan)
 
 #undef OPENMP_REDUCTION_MODIFIER
 #undef OPENMP_SCAN_CLAUSE

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 318b075db8bd..b10cdb4f3e40 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -62,14 +62,15 @@ class DSAStackTy {
   struct DSAVarData {
 OpenMPDirectiveKind DKind = OMPD_unknown;
 OpenMPClauseKind CKind = OMPC_unknown;
+unsigned Modifier = 0;
 const Expr *RefExpr = nullptr;
 DeclRefExpr *PrivateCopy = nullptr;
 SourceLocation ImplicitDSALoc;
 DSAVarData() = default;
 DSAVarData(OpenMPDirectiveKind DKind, OpenMPClauseKind CKind,
const Expr *RefExpr, DeclRefExpr *PrivateCopy,
-   SourceLocation ImplicitDSALoc)
-: DKind(DKind), CKind(CKind), RefExpr(RefExpr),
+   SourceLocation ImplicitDSALoc, unsigned Modifier)
+: DKind(DKind), CKind(CKind), Modifier(Modifier), RefExpr(RefExpr),
   PrivateCopy(PrivateCopy), ImplicitDSALoc(ImplicitDSALoc) {}
   };
   using OperatorOffsetTy =
@@ -80,6 +81,7 @@ class DSAStackTy {
 private:
   struct DSAInfo {
 OpenMPClauseKind Attributes = OMPC_unknown;
+unsigned Modifier = 0;
 /// Pointer to a reference expression and a flag which shows that the
 /// variable is marked as lastprivate(true) or not (false).
 llvm::PointerIntPair RefExpr;
@@ -164,6 +166,8 @@ class DSAStackTy {
 /// List of globals marked as declare target link in this target region
 /// (isOpenMPTargetExecutionDirective(Directive) == true).
 llvm::SmallVector DeclareTargetLinkVarDecls;
+/// List of decls used in inclusive/exclusive clauses of the scan 
directive.
+llvm::DenseSet> UsedInScanDirective;
 SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name,
  Scope *CurScope, SourceLocation Loc)
 : Directive(DKind), DirectiveName(Name), CurScope(CurScope),
@@ -469,9 +473,20 @@ class DSAStackTy {
   /// parent directive.
   const ValueDecl *getParentLoopControlVariable(unsigned I) const;
 
+  /// Marks the specified decl \p D as used in scan directive.
+  

[PATCH] D33029: [clang-format] add option for dangling parenthesis

2020-03-27 Thread Andrew Somerville via Phabricator via cfe-commits
catskul added a comment.

@bbassi @MyDeveloperDay I'll buy whoever manages to land this feature a case of 
their favorite beer/beverage (max $50). Or $50 worth of girlscout cookies. : )

Just ping me when it lands and we can arrange the shipment.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D33029/new/

https://reviews.llvm.org/D33029



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


[PATCH] D75153: [ThinLTO] Allow usage of all SMT threads in the system

2020-03-27 Thread Alexandre Ganea via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
aganea marked an inline comment as done.
Closed by commit rG09158252f777: [ThinLTO] Allow usage of all hardware threads 
in the system (authored by aganea).

Changed prior to commit:
  https://reviews.llvm.org/D75153?vs=248254=253116#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75153/new/

https://reviews.llvm.org/D75153

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  lld/COFF/Config.h
  lld/COFF/Driver.cpp
  lld/COFF/LTO.cpp
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/LTO.cpp
  lld/test/COFF/thinlto.ll
  lld/test/ELF/basic.s
  lld/test/ELF/lto/thinlto.ll
  lld/test/wasm/lto/thinlto.ll
  lld/wasm/Config.h
  lld/wasm/Driver.cpp
  lld/wasm/LTO.cpp
  llvm/include/llvm/LTO/LTO.h
  llvm/include/llvm/Support/Threading.h
  llvm/lib/LTO/LTO.cpp
  llvm/lib/Support/Threading.cpp
  llvm/lib/Support/Unix/Threading.inc
  llvm/lib/Support/Windows/Threading.inc
  llvm/tools/gold/gold-plugin.cpp
  llvm/tools/llvm-lto2/llvm-lto2.cpp

Index: llvm/tools/llvm-lto2/llvm-lto2.cpp
===
--- llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -68,9 +68,10 @@
"distributed backend case"));
 
 // Default to using all available threads in the system, but using only one
-// thread per core, as indicated by the usage of
-// heavyweight_hardware_concurrency() in the InProcessThinBackend constructor.
-static cl::opt Threads("thinlto-threads", cl::init(0));
+// thread per core (no SMT).
+// Use -thinlto-threads=all to use hardware_concurrency() instead, which means
+// to use all hardware threads or cores in the system.
+static cl::opt Threads("thinlto-threads");
 
 static cl::list SymbolResolutions(
 "r",
@@ -286,7 +287,8 @@
 /* LinkedObjectsFile */ nullptr,
 /* OnWrite */ {});
   else
-Backend = createInProcessThinBackend(Threads);
+Backend = createInProcessThinBackend(
+llvm::heavyweight_hardware_concurrency(Threads));
   LTO Lto(std::move(Conf), std::move(Backend));
 
   bool HasErrors = false;
Index: llvm/tools/gold/gold-plugin.cpp
===
--- llvm/tools/gold/gold-plugin.cpp
+++ llvm/tools/gold/gold-plugin.cpp
@@ -28,6 +28,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TargetSelect.h"
+#include "llvm/Support/Threading.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -134,11 +135,9 @@
   };
   static OutputType TheOutputType = OT_NORMAL;
   static unsigned OptLevel = 2;
-  // Default parallelism of 0 used to indicate that user did not specify.
-  // Actual parallelism default value depends on implementation.
   // Currently only affects ThinLTO, where the default is the max cores in the
-  // system.
-  static unsigned Parallelism = 0;
+  // system. See llvm::get_threadpool_strategy() for acceptable values.
+  static std::string Parallelism;
   // Default regular LTO codegen parallelism (number of partitions).
   static unsigned ParallelCodeGenParallelismLevel = 1;
 #ifdef NDEBUG
@@ -272,8 +271,10 @@
 message(LDPL_FATAL, "Optimization level must be between 0 and 3");
   OptLevel = opt[1] - '0';
 } else if (opt.startswith("jobs=")) {
-  if (StringRef(opt_ + 5).getAsInteger(10, Parallelism))
-message(LDPL_FATAL, "Invalid parallelism level: %s", opt_ + 5);
+  StringRef Num(opt_ + 5);
+  if (!get_threadpool_strategy(Num))
+message(LDPL_FATAL, "Invalid parallelism level: %s", Num.data());
+  Parallelism = Num;
 } else if (opt.startswith("lto-partitions=")) {
   if (opt.substr(strlen("lto-partitions="))
   .getAsInteger(10, ParallelCodeGenParallelismLevel))
@@ -877,14 +878,15 @@
   Conf.PTO.LoopVectorization = options::OptLevel > 1;
   Conf.PTO.SLPVectorization = options::OptLevel > 1;
 
-  if (options::Parallelism)
-Backend = createInProcessThinBackend(options::Parallelism);
   if (options::thinlto_index_only) {
 std::string OldPrefix, NewPrefix;
 getThinLTOOldAndNewPrefix(OldPrefix, NewPrefix);
 Backend = createWriteIndexesThinBackend(OldPrefix, NewPrefix,
 options::thinlto_emit_imports_files,
 LinkedObjectsFile, OnIndexWrite);
+  } else {
+Backend = createInProcessThinBackend(
+llvm::heavyweight_hardware_concurrency(options::Parallelism));
   }
 
   Conf.OverrideTriple = options::triple;
Index: llvm/lib/Support/Windows/Threading.inc
===
--- llvm/lib/Support/Windows/Threading.inc
+++ 

[PATCH] D76234: [AST] Simplify implementation of Type::isXXXType()

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

In D76234#1945989 , @yannic wrote:

> Thank you! I don't have commit access, would you mind committing this for me?


Happy to do so, thank you for the patch! I've commit on your behalf in 
848112cca4e0d173d371271015fd16b998b94e56 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76234/new/

https://reviews.llvm.org/D76234



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


[PATCH] D72467: Remove "mask" operand from shufflevector.

2020-03-27 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added a comment.

Looks like D76649  landed and added another 
IRBuilder call that needs updating:

  [2974/5437] Building CXX object 
lib/Target/X86/CMakeFiles/LLVMX86CodeGen.dir/X86PartialReduction.cpp.o
  FAILED: 
lib/Target/X86/CMakeFiles/LLVMX86CodeGen.dir/X86PartialReduction.cpp.o 
  CCACHE_DIR=/mnt/disks/ssd0/ccache CCACHE_MAXSIZE=20G CCACHE_CPP2=yes 
CCACHE_HASHDIR=yes /usr/bin/ccache /usr/bin/clang++  -DGTEST_HAS_RTTI=0 
-D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS 
-D__STDC_LIMIT_MACROS -Ilib/Target/X86 
-I/mnt/disks/ssd0/agent/workspace/amd64_debian_testing_clang8/llvm/lib/Target/X86
 -I/usr/include/libxml2 -Iinclude 
-I/mnt/disks/ssd0/agent/workspace/amd64_debian_testing_clang8/llvm/include 
-gmlt -fPIC -fvisibility-inlines-hidden -Werror=date-time 
-Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
-Wno-long-long -Wimplicit-fallthrough -Wcovered-switch-default 
-Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor 
-Wstring-conversion -fdiagnostics-color -ffunction-sections -fdata-sections -O3 
 -fvisibility=hidden-fno-exceptions -fno-rtti -UNDEBUG -std=c++14 -MD -MT 
lib/Target/X86/CMakeFiles/LLVMX86CodeGen.dir/X86PartialReduction.cpp.o -MF 
lib/Target/X86/CMakeFiles/LLVMX86CodeGen.dir/X86PartialReduction.cpp.o.d -o 
lib/Target/X86/CMakeFiles/LLVMX86CodeGen.dir/X86PartialReduction.cpp.o -c 
/mnt/disks/ssd0/agent/workspace/amd64_debian_testing_clang8/llvm/lib/Target/X86/X86PartialReduction.cpp
  
/mnt/disks/ssd0/agent/workspace/amd64_debian_testing_clang8/llvm/lib/Target/X86/X86PartialReduction.cpp:387:22:
 error: call to member function 'CreateShuffleVector' is ambiguous
  Ops[0] = Builder.CreateShuffleVector(Ops[0], Ops[0], {0, 1});
   ^~~
  
/mnt/disks/ssd0/agent/workspace/amd64_debian_testing_clang8/llvm/include/llvm/IR/IRBuilder.h:2625:10:
 note: candidate function
Value *CreateShuffleVector(Value *V1, Value *V2, ArrayRef Mask,
   ^
  
/mnt/disks/ssd0/agent/workspace/amd64_debian_testing_clang8/llvm/include/llvm/IR/IRBuilder.h:2633:10:
 note: candidate function
Value *CreateShuffleVector(Value *V1, Value *V2, ArrayRef Mask,
   ^
  
/mnt/disks/ssd0/agent/workspace/amd64_debian_testing_clang8/llvm/include/llvm/IR/IRBuilder.h:2618:10:
 note: candidate function not viable: cannot convert initializer list argument 
to 'llvm::Value *'
Value *CreateShuffleVector(Value *V1, Value *V2, Value *Mask,


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72467/new/

https://reviews.llvm.org/D72467



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


[clang] 848112c - Simplify implementation of Type::isXXXType(); NFC

2020-03-27 Thread Aaron Ballman via cfe-commits

Author: Yannic Bonenberger
Date: 2020-03-27T10:24:59-04:00
New Revision: 848112cca4e0d173d371271015fd16b998b94e56

URL: 
https://github.com/llvm/llvm-project/commit/848112cca4e0d173d371271015fd16b998b94e56
DIFF: 
https://github.com/llvm/llvm-project/commit/848112cca4e0d173d371271015fd16b998b94e56.diff

LOG: Simplify implementation of Type::isXXXType(); NFC

Added: 


Modified: 
clang/include/clang/AST/Type.h

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 673d37109eb6..6b46fc5ad312 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -6679,9 +6679,9 @@ inline bool Type::isTemplateTypeParmType() const {
 }
 
 inline bool Type::isSpecificBuiltinType(unsigned K) const {
-  if (const BuiltinType *BT = getAs())
-if (BT->getKind() == (BuiltinType::Kind) K)
-  return true;
+  if (const BuiltinType *BT = getAs()) {
+return BT->getKind() == static_cast(K);
+  }
   return false;
 }
 
@@ -6700,9 +6700,7 @@ inline const BuiltinType *Type::getAsPlaceholderType() 
const {
 
 inline bool Type::isSpecificPlaceholderType(unsigned K) const {
   assert(BuiltinType::isPlaceholderTypeKind((BuiltinType::Kind) K));
-  if (const auto *BT = dyn_cast(this))
-return (BT->getKind() == (BuiltinType::Kind) K);
-  return false;
+  return isSpecificBuiltinType(K);
 }
 
 inline bool Type::isNonOverloadPlaceholderType() const {
@@ -6712,34 +6710,24 @@ inline bool Type::isNonOverloadPlaceholderType() const {
 }
 
 inline bool Type::isVoidType() const {
-  if (const auto *BT = dyn_cast(CanonicalType))
-return BT->getKind() == BuiltinType::Void;
-  return false;
+  return isSpecificBuiltinType(BuiltinType::Void);
 }
 
 inline bool Type::isHalfType() const {
-  if (const auto *BT = dyn_cast(CanonicalType))
-return BT->getKind() == BuiltinType::Half;
   // FIXME: Should we allow complex __fp16? Probably not.
-  return false;
+  return isSpecificBuiltinType(BuiltinType::Half);
 }
 
 inline bool Type::isFloat16Type() const {
-  if (const auto *BT = dyn_cast(CanonicalType))
-return BT->getKind() == BuiltinType::Float16;
-  return false;
+  return isSpecificBuiltinType(BuiltinType::Float16);
 }
 
 inline bool Type::isFloat128Type() const {
-  if (const auto *BT = dyn_cast(CanonicalType))
-return BT->getKind() == BuiltinType::Float128;
-  return false;
+  return isSpecificBuiltinType(BuiltinType::Float128);
 }
 
 inline bool Type::isNullPtrType() const {
-  if (const auto *BT = getAs())
-return BT->getKind() == BuiltinType::NullPtr;
-  return false;
+  return isSpecificBuiltinType(BuiltinType::NullPtr);
 }
 
 bool IsEnumDeclComplete(EnumDecl *);



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


[clang] 0915825 - [ThinLTO] Allow usage of all hardware threads in the system

2020-03-27 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2020-03-27T10:20:58-04:00
New Revision: 09158252f777c2e2f06a86b154c44abcbcf9bb74

URL: 
https://github.com/llvm/llvm-project/commit/09158252f777c2e2f06a86b154c44abcbcf9bb74
DIFF: 
https://github.com/llvm/llvm-project/commit/09158252f777c2e2f06a86b154c44abcbcf9bb74.diff

LOG: [ThinLTO] Allow usage of all hardware threads in the system

Before this patch, it wasn't possible to extend the ThinLTO threads to all 
SMT/CMT threads in the system. Only one thread per core was allowed, instructed 
by usage of llvm::heavyweight_hardware_concurrency() in the ThinLTO code. Any 
number passed to the LLD flag /opt:lldltojobs=..., or any other 
ThinLTO-specific flag, was previously interpreted in the context of 
llvm::heavyweight_hardware_concurrency(), which means SMT disabled.

One can now say in LLD:
/opt:lldltojobs=0 -- Use one std::thread / hardware core in the system (no 
SMT). Default value if flag not specified.
/opt:lldltojobs=N -- Limit usage to N threads, regardless of usage of 
heavyweight_hardware_concurrency().
/opt:lldltojobs=all -- Use all hardware threads in the system. Equivalent to 
/opt:lldltojobs=$(nproc) on Linux and /opt:lldltojobs=%NUMBER_OF_PROCESSORS% on 
Windows. When an affinity mask is set for the process, threads will be created 
only for the cores selected by the mask.

When N > number-of-hardware-threads-in-the-system, the threads in the thread 
pool will be dispatched equally on all CPU sockets (tested only on Windows).
When N <= number-of-hardware-threads-on-a-CPU-socket, the threads will remain 
on the CPU socket where the process started (only on Windows).

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/CommonArgs.h
clang/lib/Driver/ToolChains/Darwin.cpp
lld/COFF/Config.h
lld/COFF/Driver.cpp
lld/COFF/LTO.cpp
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/LTO.cpp
lld/test/COFF/thinlto.ll
lld/test/ELF/basic.s
lld/test/ELF/lto/thinlto.ll
lld/test/wasm/lto/thinlto.ll
lld/wasm/Config.h
lld/wasm/Driver.cpp
lld/wasm/LTO.cpp
llvm/include/llvm/LTO/LTO.h
llvm/include/llvm/Support/Threading.h
llvm/lib/LTO/LTO.cpp
llvm/lib/Support/Threading.cpp
llvm/lib/Support/Unix/Threading.inc
llvm/lib/Support/Windows/Threading.inc
llvm/tools/gold/gold-plugin.cpp
llvm/tools/llvm-lto2/llvm-lto2.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 51b2e5f3c34d..303ced52454c 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -50,6 +50,7 @@
 #include "llvm/Support/Program.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetParser.h"
+#include "llvm/Support/Threading.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/YAMLParser.h"
 
@@ -338,14 +339,14 @@ std::string tools::getCPUName(const ArgList , const 
llvm::Triple ,
   }
 }
 
-unsigned tools::getLTOParallelism(const ArgList , const Driver ) {
-  unsigned Parallelism = 0;
+llvm::StringRef tools::getLTOParallelism(const ArgList , const Driver ) 
{
   Arg *LtoJobsArg = Args.getLastArg(options::OPT_flto_jobs_EQ);
-  if (LtoJobsArg &&
-  StringRef(LtoJobsArg->getValue()).getAsInteger(10, Parallelism))
-D.Diag(diag::err_drv_invalid_int_value) << LtoJobsArg->getAsString(Args)
-<< LtoJobsArg->getValue();
-  return Parallelism;
+  if (!LtoJobsArg)
+return {};
+  if (!llvm::get_threadpool_strategy(LtoJobsArg->getValue()))
+D.Diag(diag::err_drv_invalid_int_value)
+<< LtoJobsArg->getAsString(Args) << LtoJobsArg->getValue();
+  return LtoJobsArg->getValue();
 }
 
 // CloudABI uses -ffunction-sections and -fdata-sections by default.
@@ -410,7 +411,8 @@ void tools::addLTOOptions(const ToolChain , const 
ArgList ,
   if (IsThinLTO)
 CmdArgs.push_back("-plugin-opt=thinlto");
 
-  if (unsigned Parallelism = getLTOParallelism(Args, ToolChain.getDriver()))
+  StringRef Parallelism = getLTOParallelism(Args, ToolChain.getDriver());
+  if (!Parallelism.empty())
 CmdArgs.push_back(
 Args.MakeArgString("-plugin-opt=jobs=" + Twine(Parallelism)));
 

diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.h 
b/clang/lib/Driver/ToolChains/CommonArgs.h
index 984f3ee98af1..c94b2b828c9b 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.h
+++ b/clang/lib/Driver/ToolChains/CommonArgs.h
@@ -88,7 +88,8 @@ llvm::opt::Arg *getLastProfileSampleUseArg(const 
llvm::opt::ArgList );
 
 bool isObjCAutoRefCount(const llvm::opt::ArgList );
 
-unsigned getLTOParallelism(const llvm::opt::ArgList , const Driver );
+llvm::StringRef getLTOParallelism(const llvm::opt::ArgList ,
+  const Driver );
 
 bool 

[PATCH] D75271: [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions.

2020-03-27 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbda3dd0d986b: [analyzer][NFC] Change LangOptions to 
CheckerManager in the shouldRegister*… (authored by Szelethus).
Herald added a subscriber: ASDenysPetrov.

Changed prior to commit:
  https://reviews.llvm.org/D75271?vs=247292=253111#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75271/new/

https://reviews.llvm.org/D75271

Files:
  clang/include/clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h
  clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
  clang/include/clang/StaticAnalyzer/Frontend/FrontendActions.h
  clang/lib/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandling.cpp
  clang/lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/AnalyzerStatsChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
  clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
  clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/CXXSelfAssignmentChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
  clang/lib/StaticAnalyzer/Checkers/CheckObjCInstMethSignature.cpp
  clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp
  clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
  clang/lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp
  clang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/CloneChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
  clang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/DebugIteratorModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp
  clang/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/DynamicTypeChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
  clang/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/GTestChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/InvalidatedIteratorChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPIChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/NSAutoreleasePoolChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/NonnullGlobalConstantsChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/OSObjectCStyleCast.cpp
  clang/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/ObjCAutoreleaseWriteChecker.cpp
  

[PATCH] D76922: [Syntax] Remove delayed folding from tree building.

2020-03-27 Thread Marcel Hlopko via Phabricator via cfe-commits
hlopko updated this revision to Diff 253108.
hlopko added a comment.

Reformat


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76922/new/

https://reviews.llvm.org/D76922

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -224,6 +224,59 @@
 )txt");
 }
 
+TEST_F(SyntaxTreeTest, SimpleVariable) {
+  expectTreeDumpEqual(
+  R"cpp(
+int a;
+int b = 42;
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | `-a
+| `-;
+`-SimpleDeclaration
+  |-int
+  |-SimpleDeclarator
+  | |-b
+  | |-=
+  | `-UnknownExpression
+  |   `-42
+  `-;
+)txt");
+}
+
+TEST_F(SyntaxTreeTest, SimpleFunction) {
+  expectTreeDumpEqual(
+  R"cpp(
+void foo(int a, int b) {}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-foo
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-b
+  |   `-)
+  `-CompoundStatement
+|-{
+`-}
+)txt");
+}
+
 TEST_F(SyntaxTreeTest, If) {
   expectTreeDumpEqual(
   R"cpp(
@@ -541,20 +594,32 @@
 TEST_F(SyntaxTreeTest, MultipleDeclaratorsGrouping) {
   expectTreeDumpEqual(
   R"cpp(
-  int *a, b;
+  int *a, b; int *c, d;
   )cpp",
   R"txt(
 *: TranslationUnit
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-*
+| | `-a
+| |-,
+| |-SimpleDeclarator
+| | `-b
+| `-;
 `-SimpleDeclaration
   |-int
   |-SimpleDeclarator
   | |-*
-  | `-a
+  | `-c
   |-,
   |-SimpleDeclarator
-  | `-b
+  | `-d
   `-;
   )txt");
+}
+
+TEST_F(SyntaxTreeTest, MultipleDeclaratorsGroupingTypedef) {
   expectTreeDumpEqual(
   R"cpp(
 typedef int *a, b;
@@ -1800,7 +1865,7 @@
 }
 
 TEST_F(SyntaxTreeTest, SynthesizedNodes) {
-  buildTree("");
+  buildTree(";");
 
   auto *C = syntax::createPunctuation(*Arena, tok::comma);
   ASSERT_NE(C, nullptr);
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -645,8 +645,8 @@
 }
 
 std::string syntax::Token::dumpForTests(const SourceManager ) const {
-  return std::string(
-  llvm::formatv("{0}   {1}", tok::getTokenName(kind()), text(SM)));
+  return std::string(llvm::formatv("Token(`{0}`, {1}, length = {2})", text(SM),
+   tok::getTokenName(kind()), length()));
 }
 
 std::string TokenBuffer::dumpForTests() const {
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -44,15 +44,6 @@
 LLVM_ATTRIBUTE_UNUSED
 static bool isImplicitExpr(clang::Expr *E) { return E->IgnoreImplicit() != E; }
 
-static SourceLocation getQualifiedNameStart(DeclaratorDecl *D) {
-  auto DN = D->getDeclName();
-  bool IsAnonymous = DN.isIdentifier() && !DN.getAsIdentifierInfo();
-  if (IsAnonymous)
-return SourceLocation();
-  return D->getQualifierLoc() ? D->getQualifierLoc().getBeginLoc()
-  : D->getLocation();
-}
-
 namespace {
 /// Get start location of the Declarator from the TypeLoc.
 /// E.g.:
@@ -212,10 +203,6 @@
 foldNode(Range, New, nullptr);
   }
 
-  /// Must be called with the range of each `DeclaratorDecl`. Ensures the
-  /// corresponding declarator nodes are covered by `SimpleDeclaration`.
-  void noticeDeclRange(llvm::ArrayRef Range);
-
   /// Notifies that we should not consume trailing semicolon when computing
   /// token range of \p D.
   void noticeDeclWithoutSemicolon(Decl *D);
@@ -237,11 +224,6 @@
   void markChild(syntax::Node *N, NodeRole R);
   /// Set role for the syntax node matching \p N.
   void markChild(ASTPtr N, NodeRole R);
-  /// Set role for the delayed node that spans exactly \p Range.
-  void markDelayedChild(llvm::ArrayRef Range, NodeRole R);
-  /// Set role for the node that may or may not be delayed. Node must span
-  /// exactly \p Range.
-  void markMaybeDelayedChild(llvm::ArrayRef Range, NodeRole R);
 
   /// Finish building the tree and consume the root node.
   syntax::TranslationUnit *finalize() && {
@@ -285,18 +267,54 @@
 return maybeAppendSemicolon(Tokens, D);
   }
 
-  llvm::ArrayRef getDeclRange(const Decl *D) const {
+  template 
+  bool isResponsibleForCreatingDeclaration(const T *D) const {
+static_assert((std::is_base_of::value ||
+   std::is_base_of::value),
+  "only DeclaratorDecl and TypedefNameDecl are supported.");
+

[PATCH] D76922: [Syntax] Remove delayed folding from tree building.

2020-03-27 Thread Marcel Hlopko via Phabricator via cfe-commits
hlopko created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
hlopko updated this revision to Diff 253108.
hlopko added a comment.
hlopko edited the summary of this revision.

Reformat


This patch removes delayed folding and replaces it with forward peeking.

Delayed folding was previously used as a solution to the problem that
declaration doesn't have a representation in the AST. For example following
code:

  int a,b;

is expressed in the AST as:

  TranslationUnitDecl
  |-...
  |-VarDecl `int a`
  `-VarDecl `int b`

And in the syntax tree we need:

  *: TranslationUnit
  `-SimpleDeclaration
|-int
|-SimpleDeclarator
| `-a
|-,
|-SimpleDeclarator
| `-b
|-;

So in words, we need to create SimpleDeclaration to be a parent of
SimpleDeclarator nodes. Previously we used delayed folding to make sure 
SimpleDeclarations will be
eventually created. And in case multiple declarators requested declaration
creation, declaration range was extended to cover all declarators.

This design started to be hard to reason about, so we decided to replace it with
forward peeking. The last declarator node in the chain is responsible for 
creating
SimpleDeclaration for the whole chain. Range of the declaration corresponds to
the source range of the declarator node. Declarator decides whether its the last
one by peeking to the next AST node (see `isResponsibleForCreatingDeclaration`).

This patch does following:

- Removed delayed folding logic
- Tweaks Token.dumpForTests
- Moves getQualifiedNameStart inside BuildTreeVisitor
- Extracts BuildTreeVisitor.ProcessDeclaratorAndDeclaration
- Renames Builder.getDeclRange to Builder.getDeclarationRange and uses the 
method in all places.
- Adds a bunch of tests


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76922

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -224,6 +224,59 @@
 )txt");
 }
 
+TEST_F(SyntaxTreeTest, SimpleVariable) {
+  expectTreeDumpEqual(
+  R"cpp(
+int a;
+int b = 42;
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | `-a
+| `-;
+`-SimpleDeclaration
+  |-int
+  |-SimpleDeclarator
+  | |-b
+  | |-=
+  | `-UnknownExpression
+  |   `-42
+  `-;
+)txt");
+}
+
+TEST_F(SyntaxTreeTest, SimpleFunction) {
+  expectTreeDumpEqual(
+  R"cpp(
+void foo(int a, int b) {}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-foo
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-b
+  |   `-)
+  `-CompoundStatement
+|-{
+`-}
+)txt");
+}
+
 TEST_F(SyntaxTreeTest, If) {
   expectTreeDumpEqual(
   R"cpp(
@@ -541,20 +594,32 @@
 TEST_F(SyntaxTreeTest, MultipleDeclaratorsGrouping) {
   expectTreeDumpEqual(
   R"cpp(
-  int *a, b;
+  int *a, b; int *c, d;
   )cpp",
   R"txt(
 *: TranslationUnit
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-*
+| | `-a
+| |-,
+| |-SimpleDeclarator
+| | `-b
+| `-;
 `-SimpleDeclaration
   |-int
   |-SimpleDeclarator
   | |-*
-  | `-a
+  | `-c
   |-,
   |-SimpleDeclarator
-  | `-b
+  | `-d
   `-;
   )txt");
+}
+
+TEST_F(SyntaxTreeTest, MultipleDeclaratorsGroupingTypedef) {
   expectTreeDumpEqual(
   R"cpp(
 typedef int *a, b;
@@ -1800,7 +1865,7 @@
 }
 
 TEST_F(SyntaxTreeTest, SynthesizedNodes) {
-  buildTree("");
+  buildTree(";");
 
   auto *C = syntax::createPunctuation(*Arena, tok::comma);
   ASSERT_NE(C, nullptr);
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -645,8 +645,8 @@
 }
 
 std::string syntax::Token::dumpForTests(const SourceManager ) const {
-  return std::string(
-  llvm::formatv("{0}   {1}", tok::getTokenName(kind()), text(SM)));
+  return std::string(llvm::formatv("Token(`{0}`, {1}, length = {2})", text(SM),
+   tok::getTokenName(kind()), length()));
 }
 
 std::string TokenBuffer::dumpForTests() const {
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -44,15 +44,6 @@
 LLVM_ATTRIBUTE_UNUSED
 static bool isImplicitExpr(clang::Expr *E) { return E->IgnoreImplicit() != E; }
 
-static SourceLocation getQualifiedNameStart(DeclaratorDecl *D) {
-  auto DN = D->getDeclName();
-  bool IsAnonymous = DN.isIdentifier() && 

[PATCH] D76605: [analyzer] Display the checker name in the text output

2020-03-27 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus marked an inline comment as done.
Szelethus added inline comments.



Comment at: clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def:313-316
+ANALYZER_OPTION(bool, ShouldDisplayCheckerNameForText, "display-checker-name",
+"Display the checker name for textual outputs",
+true)
+

NoQ wrote:
> Szelethus wrote:
> > NoQ wrote:
> > > Why do we need an option? Is it just for tests? Is it for clang-tidy to 
> > > avoid printing the checker name twice?
> > > 
> > > Why do we need an option?
> > 
> > Well, we don't, but there is just no reason not to make this configurable, 
> > as seen in the debug checker test file. It would be unnecessary noise in 
> > their case.
> > 
> > > Is it just for tests?
> > 
> > Tests are a big motivating factor, but it just doesn't hurt to know (just 
> > like in clang-tidy!). I suspect this change affects developers or 
> > powerusers more than any others, and could accelerate debugging and/or 
> > configuring just a tiny bit more.
> > 
> > > Is it for clang-tidy to avoid printing the checker name twice?
> > 
> > Clang-tidy isnt affected, as they use the PD_NONE output type, not PD_TEXT.
> > Clang-tidy isnt affected, as they use the PD_NONE output type, not PD_TEXT.
> 
> But they do have path notes printed out. It would have been terrible if they 
> didn't have path notes.
https://github.com/llvm/llvm-project/blob/master/clang-tools-extra/clang-tidy/ClangTidy.cpp#L68

Clang-tidy implements its own `PathDiagnosticConsumer`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76605/new/

https://reviews.llvm.org/D76605



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


[PATCH] D76234: [AST] Simplify implementation of Type::isXXXType()

2020-03-27 Thread Yannic Bonenberger via Phabricator via cfe-commits
yannic added a comment.

Thank you! I don't have commit access, would you mind committing this for me?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76234/new/

https://reviews.llvm.org/D76234



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


[clang] bda3dd0 - [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions

2020-03-27 Thread Kirstóf Umann via cfe-commits

Author: Kirstóf Umann
Date: 2020-03-27T14:34:09+01:00
New Revision: bda3dd0d986b33c3a327c0ee0eb8ba43aa140699

URL: 
https://github.com/llvm/llvm-project/commit/bda3dd0d986b33c3a327c0ee0eb8ba43aa140699
DIFF: 
https://github.com/llvm/llvm-project/commit/bda3dd0d986b33c3a327c0ee0eb8ba43aa140699.diff

LOG: [analyzer][NFC] Change LangOptions to CheckerManager in the 
shouldRegister* functions

Some checkers may not only depend on language options but also analyzer options.
To make this possible this patch changes the parameter of the shouldRegister*
function to CheckerManager to be able to query the analyzer options when
deciding whether the checker should be registered.

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h
clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
clang/include/clang/StaticAnalyzer/Frontend/FrontendActions.h
clang/lib/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandling.cpp
clang/lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp
clang/lib/StaticAnalyzer/Checkers/AnalyzerStatsChecker.cpp
clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp
clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
clang/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp
clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
clang/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
clang/lib/StaticAnalyzer/Checkers/CXXSelfAssignmentChecker.cpp
clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
clang/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp
clang/lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp
clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
clang/lib/StaticAnalyzer/Checkers/CheckObjCInstMethSignature.cpp
clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp
clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
clang/lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp
clang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp
clang/lib/StaticAnalyzer/Checkers/CloneChecker.cpp
clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
clang/lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
clang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp
clang/lib/StaticAnalyzer/Checkers/DebugIteratorModeling.cpp
clang/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp
clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
clang/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp
clang/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp
clang/lib/StaticAnalyzer/Checkers/DynamicTypeChecker.cpp
clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
clang/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp
clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp
clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
clang/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp
clang/lib/StaticAnalyzer/Checkers/GTestChecker.cpp
clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
clang/lib/StaticAnalyzer/Checkers/InvalidatedIteratorChecker.cpp
clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
clang/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp
clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPIChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
clang/lib/StaticAnalyzer/Checkers/NSAutoreleasePoolChecker.cpp
clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
clang/lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp
clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp

[PATCH] D75677: [Analyzer] Only add iterator note tags to the operations of the affected iterators

2020-03-27 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware marked an inline comment as done.
baloghadamsoftware added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp:541-542
+BR.markInteresting(It1);
+if (const auto  = It1.getAs()) {
+  BR.markInteresting(LCV1->getRegion());
+}

baloghadamsoftware wrote:
> baloghadamsoftware wrote:
> > baloghadamsoftware wrote:
> > > Szelethus wrote:
> > > > NoQ wrote:
> > > > > baloghadamsoftware wrote:
> > > > > > NoQ wrote:
> > > > > > > I'm opposed to this code for the same reason that i'm opposed to 
> > > > > > > it in the debug checker. Parent region is an undocumented 
> > > > > > > implementation detail of `RegionStore`. It is supposed to be 
> > > > > > > immaterial to the user. You should not rely on its exact value.
> > > > > > > 
> > > > > > > @baloghadamsoftware Can we eliminate all such code from iterator 
> > > > > > > checkers and instead identify all iterators by regions in which 
> > > > > > > they're stored? Does my improved C++ support help with this 
> > > > > > > anyhow whenever it kicks in?
> > > > > > How to find the region where it is stored? I am open to find better 
> > > > > > solutions, but it was the only one I could find so far. If we 
> > > > > > ignore `LazyCompoundVal` then everything falls apart, we can remove 
> > > > > > all the iterator-related checkers.
> > > > > It's the region from which you loaded it. If you obtained it as 
> > > > > `Call.getArgSVal()` then it's the parameter region for the call. If 
> > > > > you obtained it as `Call.getReturnValue()` then it's the target 
> > > > > region can be obtained by looking at the //construction context// for 
> > > > > the call.
> > > > `LazyCompoundVal` and friends seem to be a constantly emerging headache 
> > > > for almost everyone. For how long I've spent in the analyzer, and have 
> > > > religiously studied conversations and your workbook about it, I still 
> > > > feel anxious whenever it comes up.
> > > > 
> > > > It would be great to have this documented in the code sometime.
> > > Do you mean `CallEvent::getParameterLocation()` for arguments? What is 
> > > the //construction context// for the call? How can it be obtained?
> > I do not know exactly how many place `LazyCompoundVal`  appears, but one 
> > place for sure is in `MaterializeTemporaryExpr::getSubExpr()`. What to use 
> > there instead?
> I also get it in the `Val` parameter of `checkBind()`.
Now I spent a whole day in vain. You probably mean 
`ExprEngine::getObjectUnderConstruction()`, (which takes 
`ConstructionContextItem` as its argument) but it turned out that there are no 
objects under construction in `checkPostCall()`. (Stack dump says 
`constructing_objects` as `null`.) It seems that the //only working solution// 
is the current one. I am not opposed to find better working solutions, but we 
cannot spend months to completely rewrite parts of the analyzer for such a 
simple patch. And note tags are definitely needed for iterator checkers.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75677/new/

https://reviews.llvm.org/D75677



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


[PATCH] D74387: [SYCL] Defer __float128 type usage diagnostics

2020-03-27 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74387/new/

https://reviews.llvm.org/D74387



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


[PATCH] D76234: [AST] Simplify implementation of Type::isXXXType()

2020-03-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76234/new/

https://reviews.llvm.org/D76234



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


[PATCH] D76917: [analyzer][MallocChecker] Fix that kfree only takes a single argument

2020-03-27 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG30a8b77080b9: [analyzer][MallocChecker] Fix that kfree only 
takes a single argument (authored by Szelethus).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76917/new/

https://reviews.llvm.org/D76917

Files:
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/test/Analysis/kmalloc-linux.c


Index: clang/test/Analysis/kmalloc-linux.c
===
--- clang/test/Analysis/kmalloc-linux.c
+++ clang/test/Analysis/kmalloc-linux.c
@@ -1,4 +1,7 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux %s
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux %s -verify \
+// RUN:   -Wno-incompatible-library-redeclaration \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=unix.Malloc
 
 #define __GFP_ZERO 0x8000
 #define NULL ((void *)0)
@@ -6,6 +9,7 @@
 typedef __typeof(sizeof(int)) size_t;
 
 void *kmalloc(size_t, int);
+void kfree(void *);
 
 struct test {
 };
@@ -61,6 +65,8 @@
 
 struct malloc_type;
 
+// 3 parameter malloc:
+// https://www.freebsd.org/cgi/man.cgi?query=malloc=9
 void *malloc(unsigned long size, struct malloc_type *mtp, int flags);
 
 void test_3arg_malloc(struct malloc_type *mtp) {
@@ -97,7 +103,7 @@
   struct test **list, *t;
   int i;
 
-  list = alloc(sizeof(*list) * 10, mtp, flags);
+  list = malloc(sizeof(*list) * 10, mtp, flags);
   if (list == NULL)
 return;
 
@@ -107,3 +113,11 @@
   }
   kfree(list);
 }
+
+void test_3arg_malloc_leak(struct malloc_type *mtp, int flags) {
+  struct test **list;
+
+  list = malloc(sizeof(*list) * 10, mtp, flags);
+  if (list == NULL)
+return;
+} // expected-warning{{Potential leak of memory pointed to by 'list'}}
Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -285,7 +285,7 @@
   CD_strdup{{"strdup"}, 1}, CD_win_strdup{{"_strdup"}, 1},
   CD_kmalloc{{"kmalloc"}, 2}, CD_if_nameindex{{"if_nameindex"}, 1},
   CD_if_freenameindex{{"if_freenameindex"}, 1}, CD_wcsdup{{"wcsdup"}, 1},
-  CD_win_wcsdup{{"_wcsdup"}, 1}, CD_kfree{{"kfree"}, 2},
+  CD_win_wcsdup{{"_wcsdup"}, 1}, CD_kfree{{"kfree"}, 1},
   CD_g_malloc{{"g_malloc"}, 1}, CD_g_malloc0{{"g_malloc0"}, 1},
   CD_g_realloc{{"g_realloc"}, 2}, CD_g_try_malloc{{"g_try_malloc"}, 1},
   CD_g_try_malloc0{{"g_try_malloc0"}, 1},


Index: clang/test/Analysis/kmalloc-linux.c
===
--- clang/test/Analysis/kmalloc-linux.c
+++ clang/test/Analysis/kmalloc-linux.c
@@ -1,4 +1,7 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux %s
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux %s -verify \
+// RUN:   -Wno-incompatible-library-redeclaration \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=unix.Malloc
 
 #define __GFP_ZERO 0x8000
 #define NULL ((void *)0)
@@ -6,6 +9,7 @@
 typedef __typeof(sizeof(int)) size_t;
 
 void *kmalloc(size_t, int);
+void kfree(void *);
 
 struct test {
 };
@@ -61,6 +65,8 @@
 
 struct malloc_type;
 
+// 3 parameter malloc:
+// https://www.freebsd.org/cgi/man.cgi?query=malloc=9
 void *malloc(unsigned long size, struct malloc_type *mtp, int flags);
 
 void test_3arg_malloc(struct malloc_type *mtp) {
@@ -97,7 +103,7 @@
   struct test **list, *t;
   int i;
 
-  list = alloc(sizeof(*list) * 10, mtp, flags);
+  list = malloc(sizeof(*list) * 10, mtp, flags);
   if (list == NULL)
 return;
 
@@ -107,3 +113,11 @@
   }
   kfree(list);
 }
+
+void test_3arg_malloc_leak(struct malloc_type *mtp, int flags) {
+  struct test **list;
+
+  list = malloc(sizeof(*list) * 10, mtp, flags);
+  if (list == NULL)
+return;
+} // expected-warning{{Potential leak of memory pointed to by 'list'}}
Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -285,7 +285,7 @@
   CD_strdup{{"strdup"}, 1}, CD_win_strdup{{"_strdup"}, 1},
   CD_kmalloc{{"kmalloc"}, 2}, CD_if_nameindex{{"if_nameindex"}, 1},
   CD_if_freenameindex{{"if_freenameindex"}, 1}, CD_wcsdup{{"wcsdup"}, 1},
-  CD_win_wcsdup{{"_wcsdup"}, 1}, CD_kfree{{"kfree"}, 2},
+  CD_win_wcsdup{{"_wcsdup"}, 1}, CD_kfree{{"kfree"}, 1},
   CD_g_malloc{{"g_malloc"}, 1}, CD_g_malloc0{{"g_malloc0"}, 1},
   CD_g_realloc{{"g_realloc"}, 2}, CD_g_try_malloc{{"g_try_malloc"}, 1},
   CD_g_try_malloc0{{"g_try_malloc0"}, 1},
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76790: [analyzer] StdLibraryFunctionsChecker: fix bug with arg constraints

2020-03-27 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

The fix looks great!

In D76790#1941857 , @martong wrote:

> I was thinking about the below test, but then I reverted back because I don't 
> want to add "fake" summaries for testing purposes. Perhaps adding a new 
> checker option could enable these "fake" summaries, @Szelethus what's your 
> opinion?


The fake summary sounds great. You could hide it behind a debug checker, if we 
are to be that cautious.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76790/new/

https://reviews.llvm.org/D76790



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


[PATCH] D76234: [AST] Simplify implementation of Type::isXXXType()

2020-03-27 Thread Yannic Bonenberger via Phabricator via cfe-commits
yannic added a comment.

sammccall, hokein: you've recently created or reviewed changes in this area. 
Can you help review this change?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76234/new/

https://reviews.llvm.org/D76234



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


[PATCH] D63279: [Analyzer] Unroll for-loops where the upper boundary is a variable with know value

2020-03-27 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

In D63279#1939435 , @xazax.hun wrote:

> In D63279#1939349 , @Szelethus wrote:
>
> > (note: I forgot to submit this a couple weeks ago)
> >
> > LLVM is crashing on me due to the issue mentioned in D75678 
> > , but on Bitcoin, Xerces, CppCheck and 
> > Rtags I observed no difference in between the 2 runs. I recall that others 
> > mentioned that @szepet used to run his analyses with other configurations. 
> > I'll read final report and take another look later.
> >
> > http://lists.llvm.org/pipermail/cfe-dev/2017-August/055259.html
>
>
> You mean no difference in the reports? It is very unlikely to get lucky and 
> gain/loose reports. Peter used to check the statistics emitted by the 
> analyzer such as basic block coverage.


I'll be honest, I don't see myself redoing his evaluation anytime soon -- since 
its not crashing, I guess we could just enable it?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63279/new/

https://reviews.llvm.org/D63279



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


[clang] 30a8b77 - [analyzer][MallocChecker] Fix that kfree only takes a single argument

2020-03-27 Thread Kirstóf Umann via cfe-commits

Author: Kirstóf Umann
Date: 2020-03-27T13:17:35+01:00
New Revision: 30a8b77080b98ffdd1837d2ea2e74f91e40cc867

URL: 
https://github.com/llvm/llvm-project/commit/30a8b77080b98ffdd1837d2ea2e74f91e40cc867
DIFF: 
https://github.com/llvm/llvm-project/commit/30a8b77080b98ffdd1837d2ea2e74f91e40cc867.diff

LOG: [analyzer][MallocChecker] Fix that kfree only takes a single argument

Exactly what it says on the tin!

https://www.kernel.org/doc/htmldocs/kernel-api/API-kfree.html

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/test/Analysis/kmalloc-linux.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index 23b4abc67079..0f007955abc8 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -285,7 +285,7 @@ struct MemFunctionInfoTy {
   CD_strdup{{"strdup"}, 1}, CD_win_strdup{{"_strdup"}, 1},
   CD_kmalloc{{"kmalloc"}, 2}, CD_if_nameindex{{"if_nameindex"}, 1},
   CD_if_freenameindex{{"if_freenameindex"}, 1}, CD_wcsdup{{"wcsdup"}, 1},
-  CD_win_wcsdup{{"_wcsdup"}, 1}, CD_kfree{{"kfree"}, 2},
+  CD_win_wcsdup{{"_wcsdup"}, 1}, CD_kfree{{"kfree"}, 1},
   CD_g_malloc{{"g_malloc"}, 1}, CD_g_malloc0{{"g_malloc0"}, 1},
   CD_g_realloc{{"g_realloc"}, 2}, CD_g_try_malloc{{"g_try_malloc"}, 1},
   CD_g_try_malloc0{{"g_try_malloc0"}, 1},

diff  --git a/clang/test/Analysis/kmalloc-linux.c 
b/clang/test/Analysis/kmalloc-linux.c
index ccb6188a51b3..6b17ef2d5a79 100644
--- a/clang/test/Analysis/kmalloc-linux.c
+++ b/clang/test/Analysis/kmalloc-linux.c
@@ -1,4 +1,7 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux %s
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux %s -verify \
+// RUN:   -Wno-incompatible-library-redeclaration \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=unix.Malloc
 
 #define __GFP_ZERO 0x8000
 #define NULL ((void *)0)
@@ -6,6 +9,7 @@
 typedef __typeof(sizeof(int)) size_t;
 
 void *kmalloc(size_t, int);
+void kfree(void *);
 
 struct test {
 };
@@ -61,6 +65,8 @@ typedef unsigned long long uint64_t;
 
 struct malloc_type;
 
+// 3 parameter malloc:
+// https://www.freebsd.org/cgi/man.cgi?query=malloc=9
 void *malloc(unsigned long size, struct malloc_type *mtp, int flags);
 
 void test_3arg_malloc(struct malloc_type *mtp) {
@@ -97,7 +103,7 @@ void test_3arg_malloc_indeterminate(struct malloc_type *mtp, 
int flags) {
   struct test **list, *t;
   int i;
 
-  list = alloc(sizeof(*list) * 10, mtp, flags);
+  list = malloc(sizeof(*list) * 10, mtp, flags);
   if (list == NULL)
 return;
 
@@ -107,3 +113,11 @@ void test_3arg_malloc_indeterminate(struct malloc_type 
*mtp, int flags) {
   }
   kfree(list);
 }
+
+void test_3arg_malloc_leak(struct malloc_type *mtp, int flags) {
+  struct test **list;
+
+  list = malloc(sizeof(*list) * 10, mtp, flags);
+  if (list == NULL)
+return;
+} // expected-warning{{Potential leak of memory pointed to by 'list'}}



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


[PATCH] D76830: [Analyzer][MallocChecker] No warning for kfree of ZERO_SIZE_PTR.

2020-03-27 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 253088.
balazske added a comment.

Applied the code reformattings.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76830/new/

https://reviews.llvm.org/D76830

Files:
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
  clang/test/Analysis/kmalloc-linux-1.c

Index: clang/test/Analysis/kmalloc-linux-1.c
===
--- /dev/null
+++ clang/test/Analysis/kmalloc-linux-1.c
@@ -0,0 +1,27 @@
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux -analyzer-checker=unix.Malloc -verify %s
+
+#define ZERO_SIZE_PTR ((void *)16)
+
+void *__kmalloc(int size, int flags);
+
+// Linux kmalloc looks like this.
+// (simplified)
+void *kmalloc(int size, int flags) {
+  if (size == 0)
+return ZERO_SIZE_PTR;
+  return __kmalloc(size, flags);
+}
+
+// FIXME: malloc checker expects kfree with 2 arguments, is this correct?
+// (recent kernel source code contains a `kfree(const void *)`)
+void kfree(void *, int);
+
+void test_kmalloc_zero_sized_block_fixed_value_address() {
+  void *ptr = kmalloc(0, 0); // kmalloc returns a constant address
+  kfree(ptr, 0); // no warning about freeing a constant value
+}
+
+void test_kfree_constant_value() {
+  void *ptr = (void *)1;
+  kfree(ptr, 0); // expected-warning{{Argument to kfree() is a constant address (1)}}
+}
Index: clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
===
--- clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
@@ -126,9 +126,6 @@
 if (!T.isOneOf(tok::l_paren, tok::r_paren))
   FilteredTokens.push_back(T);
 
-  if (FilteredTokens.size() > 2)
-return llvm::None;
-
   // Parse an integer at the end of the macro definition.
   const Token  = FilteredTokens.back();
   if (!T.isLiteral())
@@ -140,11 +137,10 @@
 return llvm::None;
 
   // Parse an optional minus sign.
-  if (FilteredTokens.size() == 2) {
-if (FilteredTokens.front().is(tok::minus))
+  size_t Size = FilteredTokens.size();
+  if (Size >= 2) {
+if (FilteredTokens[Size - 2].is(tok::minus))
   IntValue = -IntValue;
-else
-  return llvm::None;
   }
 
   return IntValue.getSExtValue();
Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -58,6 +58,7 @@
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
@@ -389,6 +390,13 @@
   // TODO: Remove mutable by moving the initializtaion to the registry function.
   mutable Optional KernelZeroFlagVal;
 
+  using KernelZeroSizePtrValueTy = Optional;
+  /// Store the value of macro called `ZERO_SIZE_PTR`.
+  /// The value is initialized at first use, before first use the outer
+  /// Optional is empty, afterwards it contains another Optional that indicates
+  /// if the macro value could be determined, and if yes the value itself.
+  mutable Optional KernelZeroSizePtrValue;
+
   /// Process C++ operator new()'s allocation, which is the part of C++
   /// new-expression that goes before the constructor.
   void processNewAllocation(const CXXNewExpr *NE, CheckerContext ,
@@ -658,6 +666,10 @@
 CheckerContext );
 
   void reportLeak(SymbolRef Sym, ExplodedNode *N, CheckerContext ) const;
+
+  /// Test if value in ArgVal equals to value in macro `ZERO_SIZE_PTR`.
+  bool isArgZERO_SIZE_PTR(ProgramStateRef State, CheckerContext ,
+  SVal ArgVal) const;
 };
 
 //===--===//
@@ -1677,7 +1689,12 @@
   // Nonlocs can't be freed, of course.
   // Non-region locations (labels and fixed addresses) also shouldn't be freed.
   if (!R) {
-ReportBadFree(C, ArgVal, ArgExpr->getSourceRange(), ParentExpr, Family);
+// Exception:
+// If there is a macro called ZERO_SIZE_PTR, it could be a kernel source
+// code and this value indicates a special value used for a zero-sized
+// memory block. It is a constant value that is allowed to be freed.
+if (!isArgZERO_SIZE_PTR(State, C, ArgVal))
+  ReportBadFree(C, ArgVal, ArgExpr->getSourceRange(), ParentExpr, Family);
 return nullptr;
   }
 
@@ -3023,6 +3040,18 @@
   return State;
 }
 
+bool MallocChecker::isArgZERO_SIZE_PTR(ProgramStateRef State, 

[PATCH] D76830: [Analyzer][MallocChecker] No warning for kfree of ZERO_SIZE_PTR.

2020-03-27 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus marked 2 inline comments as done.
Szelethus added a comment.

LGTM! Mind that I just published D76917 , you 
can, if you prefer, rebase on top of that. Also, a test case for `delete`ing a 
`ZERO_SIZE_PTR` valued pointer might be nice :)

If you prefer, feel free to commit without another round of reviews.




Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:396
+  /// yes was the value obtained or not.
+  mutable Optional> KernelZeroSizePtrValue;
+

balazske wrote:
> martong wrote:
> > balazske wrote:
> > > martong wrote:
> > > > Which one is referred to the lazy initialization? The inner or the 
> > > > outer?
> > > > These questions actually made me to come up with a more explanatory 
> > > > construct here:
> > > > Could we do something like this?
> > > > ```
> > > > using LazyInitialized = Optional;
> > > > mutable Optional KernelZeroSizePtrValue; // Or 
> > > > Lazy>
> > > > ```
> > > Probably use a `std::unique_ptr>` instead (like at the bug 
> > > types, they could be optional too)?
> > > If there is a code like
> > > ```
> > > bool IsSomethingInitialized;
> > > int Something;
> > > ```
> > > that looks as a clear case to use an optional (or unique_ptr)? And if 
> > > yes, is a reason for not using this construct if `int` is replaced by 
> > > `Optional`?
> > Now I see that the lazy initialization is represented by the outer optional.
> > So IMHO a using template could be the best to describe cleanly this 
> > construct:
> > ```
> > template 
> > using LazyInitialized = Optional;
> > mutable LazyInitialized> KernelZeroSizePtrValue;
> > ```
> > 
> With this I would wait for opinion of somebody else.
What @martong is saying is indeed nice, but the comments explain whats 
happening as well -- I'll leave it up to you how you want to commit this.



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:1687
+  if (ArgValKnown) {
+if (!KernelZeroSizePtrValue)
+  KernelZeroSizePtrValue =

balazske wrote:
> Szelethus wrote:
> > balazske wrote:
> > > Szelethus wrote:
> > > > Szelethus wrote:
> > > > > martong wrote:
> > > > > > balazske wrote:
> > > > > > > martong wrote:
> > > > > > > > martong wrote:
> > > > > > > > > This is a bit confusing for me. Perhaps alternatively we 
> > > > > > > > > could have a free function `isInitialized(KernelZero...)` 
> > > > > > > > > instead. Or maybe having a separate bool variable to indicate 
> > > > > > > > > whether it was initialized could be cleaner?
> > > > > > > > Another idea: Adding a helper struct to contain the bool 
> > > > > > > > `initialized`? E.g. (draft):
> > > > > > > > ```
> > > > > > > > struct LazyOptional {
> > > > > > > >   bool initialized = false;
> > > > > > > >   Opt value;
> > > > > > > >   Opt& get();
> > > > > > > >   void set(const Opt&);
> > > > > > > > };
> > > > > > > > ```
> > > > > > > It may be OK to have a function `lazyInitKernelZeroSizePtrValue`?
> > > > > > I don't insist, given we have a better described type for 
> > > > > > `KernelZeroSizePtrValue` (e.g. having a `using` `template`)
> > > > > `AnalysisManager` has access to the `Preprocessor`, and it is also 
> > > > > responsible for the construction of the `CheckerManager` object. This 
> > > > > would make moving such code to the checker registry function! I'll 
> > > > > gladly take this issue off your hand and patch it in once 
> > > > > rG2aac0c47aed8d1eff7ab6d858173c532b881d948 settles :)
> > > > Just pushed rG4dc8472942ce60f29de9587b9451cc3d49df7abf. It it settles 
> > > > (no buildbots complain), you could rebase and the lazy initialization 
> > > > could be a thing of the past! :)
> > > This makes it possible to have a generic one-time initialization function 
> > > in the checker (`CheckerBase`)? The functionality is needed in more than 
> > > one checker, at least for the bug types it can be used in almost every 
> > > checker (that has bugtypes).
> > I'm not sure I understand what you mean -- do you want to add 
> > `CheckerManager` to `CheckerBase`'s constructor?
> > 
> > In any case, I remember reading something around `CheckerBase`'s or 
> > `BugType`'s implementation the way the checker receives its name is a bit 
> > tricky and not a part of the construction.
> Initialization in register function does not work: The `MacroInfo` is not 
> found in the preprocessor. Probably the code is not parsed normally at that 
> time. For now only the lazy initialization is working.
> Initialization in register function does not work: The MacroInfo is not found 
> in the preprocessor. Probably the code is not parsed normally at that time. 
> For now only the lazy initialization is working.

Well that is super annoying. I don't object to the lazy initialization then.



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:1692-1694
+// If there is a macro called 

[PATCH] D76830: [Analyzer][MallocChecker] No warning for kfree of ZERO_SIZE_PTR.

2020-03-27 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: clang/test/Analysis/kmalloc-linux-1.c:15
+
+// FIXME: malloc checker expects kfree with 2 arguments, is this correct?
+// (recent kernel source code contains a `kfree(const void *)`)

balazske wrote:
> Szelethus wrote:
> > balazske wrote:
> > > Szelethus wrote:
> > > > martong wrote:
> > > > > Do you plan to sniff around a bit about the arguments (as part of 
> > > > > another patch)? Would be good to handle both old and new signature 
> > > > > kernel allocation functions.
> > > > I'll take a quick look as well, I am quite familiar with MallocChecker.
> > > I found that `kfree` has one argument, not two (even in the 2.6 kernel). 
> > > Probably argument count was wrong in the last change when 
> > > `CallDescription` was introduced.
> > Yup, you're totally right, this was on me :) I'll get that fixed.
> Is it better to add these tests to **kmalloc-linux.c**?
I think so, yea.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76830/new/

https://reviews.llvm.org/D76830



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


[PATCH] D75682: [Analyzer][StreamChecker] Introduction of stream error handling.

2020-03-27 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

In D75682#1940901 , @balazske wrote:

> So what is missing or wrong in this change to be accepted?


This change is functional but is not testable. But the high level idea is 
great! I think we should maybe merge this with the followup, as you originally 
intended to.

Also, judging from the fact that how differently we imagined this to go (even 
though imo your idea is superior to mine), we should explain what our state 
splitting ideology is in the code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75682/new/

https://reviews.llvm.org/D75682



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


[PATCH] D76917: [analyzer][MallocChecker] Fix that kfree only takes a single argument

2020-03-27 Thread Balázs Kéri via Phabricator via cfe-commits
balazske accepted this revision.
balazske added a comment.
This revision is now accepted and ready to land.

And the test file is corrected.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76917/new/

https://reviews.llvm.org/D76917



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


[PATCH] D76830: [Analyzer][MallocChecker] No warning for kfree of ZERO_SIZE_PTR.

2020-03-27 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked an inline comment as done.
balazske added inline comments.



Comment at: clang/test/Analysis/kmalloc-linux-1.c:15
+
+// FIXME: malloc checker expects kfree with 2 arguments, is this correct?
+// (recent kernel source code contains a `kfree(const void *)`)

Szelethus wrote:
> balazske wrote:
> > Szelethus wrote:
> > > martong wrote:
> > > > Do you plan to sniff around a bit about the arguments (as part of 
> > > > another patch)? Would be good to handle both old and new signature 
> > > > kernel allocation functions.
> > > I'll take a quick look as well, I am quite familiar with MallocChecker.
> > I found that `kfree` has one argument, not two (even in the 2.6 kernel). 
> > Probably argument count was wrong in the last change when `CallDescription` 
> > was introduced.
> Yup, you're totally right, this was on me :) I'll get that fixed.
Is it better to add these tests to **kmalloc-linux.c**?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76830/new/

https://reviews.llvm.org/D76830



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


[PATCH] D76917: [analyzer][MallocChecker] Fix that kfree only takes a single argument

2020-03-27 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: balazske, NoQ, martong, baloghadamsoftware.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, ASDenysPetrov, steakhal, Charusso, 
gamesh411, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, 
xazax.hun, whisperity.

Exactly what it says on the tin!

https://www.kernel.org/doc/htmldocs/kernel-api/API-kfree.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76917

Files:
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/test/Analysis/kmalloc-linux.c


Index: clang/test/Analysis/kmalloc-linux.c
===
--- clang/test/Analysis/kmalloc-linux.c
+++ clang/test/Analysis/kmalloc-linux.c
@@ -1,4 +1,7 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux %s
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux %s -verify \
+// RUN:   -Wno-incompatible-library-redeclaration \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=unix.Malloc
 
 #define __GFP_ZERO 0x8000
 #define NULL ((void *)0)
@@ -6,6 +9,7 @@
 typedef __typeof(sizeof(int)) size_t;
 
 void *kmalloc(size_t, int);
+void kfree(void *);
 
 struct test {
 };
@@ -61,6 +65,8 @@
 
 struct malloc_type;
 
+// 3 parameter malloc:
+// https://www.freebsd.org/cgi/man.cgi?query=malloc=9
 void *malloc(unsigned long size, struct malloc_type *mtp, int flags);
 
 void test_3arg_malloc(struct malloc_type *mtp) {
@@ -97,7 +103,7 @@
   struct test **list, *t;
   int i;
 
-  list = alloc(sizeof(*list) * 10, mtp, flags);
+  list = malloc(sizeof(*list) * 10, mtp, flags);
   if (list == NULL)
 return;
 
@@ -107,3 +113,11 @@
   }
   kfree(list);
 }
+
+void test_3arg_malloc_leak(struct malloc_type *mtp, int flags) {
+  struct test **list;
+
+  list = malloc(sizeof(*list) * 10, mtp, flags);
+  if (list == NULL)
+return;
+} // expected-warning{{Potential leak of memory pointed to by 'list'}}
Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -285,7 +285,7 @@
   CD_strdup{{"strdup"}, 1}, CD_win_strdup{{"_strdup"}, 1},
   CD_kmalloc{{"kmalloc"}, 2}, CD_if_nameindex{{"if_nameindex"}, 1},
   CD_if_freenameindex{{"if_freenameindex"}, 1}, CD_wcsdup{{"wcsdup"}, 1},
-  CD_win_wcsdup{{"_wcsdup"}, 1}, CD_kfree{{"kfree"}, 2},
+  CD_win_wcsdup{{"_wcsdup"}, 1}, CD_kfree{{"kfree"}, 1},
   CD_g_malloc{{"g_malloc"}, 1}, CD_g_malloc0{{"g_malloc0"}, 1},
   CD_g_realloc{{"g_realloc"}, 2}, CD_g_try_malloc{{"g_try_malloc"}, 1},
   CD_g_try_malloc0{{"g_try_malloc0"}, 1},


Index: clang/test/Analysis/kmalloc-linux.c
===
--- clang/test/Analysis/kmalloc-linux.c
+++ clang/test/Analysis/kmalloc-linux.c
@@ -1,4 +1,7 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux %s
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux %s -verify \
+// RUN:   -Wno-incompatible-library-redeclaration \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=unix.Malloc
 
 #define __GFP_ZERO 0x8000
 #define NULL ((void *)0)
@@ -6,6 +9,7 @@
 typedef __typeof(sizeof(int)) size_t;
 
 void *kmalloc(size_t, int);
+void kfree(void *);
 
 struct test {
 };
@@ -61,6 +65,8 @@
 
 struct malloc_type;
 
+// 3 parameter malloc:
+// https://www.freebsd.org/cgi/man.cgi?query=malloc=9
 void *malloc(unsigned long size, struct malloc_type *mtp, int flags);
 
 void test_3arg_malloc(struct malloc_type *mtp) {
@@ -97,7 +103,7 @@
   struct test **list, *t;
   int i;
 
-  list = alloc(sizeof(*list) * 10, mtp, flags);
+  list = malloc(sizeof(*list) * 10, mtp, flags);
   if (list == NULL)
 return;
 
@@ -107,3 +113,11 @@
   }
   kfree(list);
 }
+
+void test_3arg_malloc_leak(struct malloc_type *mtp, int flags) {
+  struct test **list;
+
+  list = malloc(sizeof(*list) * 10, mtp, flags);
+  if (list == NULL)
+return;
+} // expected-warning{{Potential leak of memory pointed to by 'list'}}
Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -285,7 +285,7 @@
   CD_strdup{{"strdup"}, 1}, CD_win_strdup{{"_strdup"}, 1},
   CD_kmalloc{{"kmalloc"}, 2}, CD_if_nameindex{{"if_nameindex"}, 1},
   CD_if_freenameindex{{"if_freenameindex"}, 1}, CD_wcsdup{{"wcsdup"}, 1},
-  CD_win_wcsdup{{"_wcsdup"}, 1}, CD_kfree{{"kfree"}, 2},
+  CD_win_wcsdup{{"_wcsdup"}, 1}, CD_kfree{{"kfree"}, 1},
   CD_g_malloc{{"g_malloc"}, 1}, CD_g_malloc0{{"g_malloc0"}, 1},
   CD_g_realloc{{"g_realloc"}, 2}, CD_g_try_malloc{{"g_try_malloc"}, 1},
   CD_g_try_malloc0{{"g_try_malloc0"}, 1},
___
cfe-commits 

[PATCH] D76916: [Darwin] Respect -fno-unroll-loops during LTO.

2020-03-27 Thread Florian Hahn via Phabricator via cfe-commits
fhahn created this revision.
fhahn added reviewers: thegameg, steven_wu.
Herald added subscribers: cfe-commits, dang, dexonsmith, zzheng, hiraditya, 
inglorion.
Herald added a project: clang.

Currently -fno-unroll-loops is ignored when doing LTO on Darwin. This
patch adds a new -lto-no-unroll-loops option to the LTO code generator
and forwards it to the linker if -fno-unroll-loops is passed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76916

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/darwin-ld-lto-fno-unroll-loops.c
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/test/tools/llvm-lto/fno-unroll-loops-option.ll

Index: llvm/test/tools/llvm-lto/fno-unroll-loops-option.ll
===
--- /dev/null
+++ llvm/test/tools/llvm-lto/fno-unroll-loops-option.ll
@@ -0,0 +1,34 @@
+; REQUIRES: asserts
+
+; RUN: llvm-as < %s > %t1.bc
+
+; Build with unrolling disabled (-lto-no-unroll-loops).
+; RUN: llvm-lto %t1.bc -o %t.nounroll.o -lto-no-unroll-loops --exported-symbol=foo -save-merged-module
+; RUN: llvm-dis  -o - %t.nounroll.o.merged.bc | FileCheck --check-prefix=NOUNROLL %s
+
+; NOUNROLL: br label %loop
+; NOUNROLL: br i1 %ec, label %exit, label %loop
+
+; Build with unrolling enabled (by not passing -lto-no-unroll-loops). All
+; branches should be gone.
+; RUN: llvm-lto %t1.bc -o %t.nounroll.o --exported-symbol=foo -save-merged-module
+; RUN: llvm-dis  -o - %t.nounroll.o.merged.bc | FileCheck --check-prefix=UNROLL %s
+
+; UNROLL-NOT: br
+
+define void @foo(i32* %ptr) {
+
+entry:
+  br label %loop
+
+loop:
+  %iv = phi i32 [ 0, %entry], [ %iv.next, %loop ]
+  %iv.ptr = getelementptr i32, i32* %ptr, i32 %iv
+  store i32 %iv, i32* %iv.ptr
+  %iv.next = add i32 %iv, 1
+  %ec = icmp eq i32 %iv.next, 10
+  br i1 %ec, label %exit, label %loop
+
+exit:
+  ret void
+}
Index: llvm/lib/LTO/LTOCodeGenerator.cpp
===
--- llvm/lib/LTO/LTOCodeGenerator.cpp
+++ llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -109,6 +109,10 @@
 cl::Hidden);
 }
 
+cl::opt LTONoUnrollLoops("lto-no-unroll-loops",
+   cl::desc("Disable unrolling during LTO."),
+   cl::Hidden, cl::init(false));
+
 LTOCodeGenerator::LTOCodeGenerator(LLVMContext )
 : Context(Context), MergedModule(new Module("ld-temp.o", Context)),
   TheLinker(new Linker(*MergedModule)) {
@@ -570,6 +574,7 @@
 
   Triple TargetTriple(TargetMach->getTargetTriple());
   PassManagerBuilder PMB;
+  PMB.DisableUnrollLoops = LTONoUnrollLoops;
   PMB.DisableGVNLoadPRE = DisableGVNLoadPRE;
   PMB.LoopVectorize = !DisableVectorization;
   PMB.SLPVectorize = !DisableVectorization;
Index: clang/test/Driver/darwin-ld-lto-fno-unroll-loops.c
===
--- /dev/null
+++ clang/test/Driver/darwin-ld-lto-fno-unroll-loops.c
@@ -0,0 +1,17 @@
+// REQUIRES: system-darwin
+
+// RUN: mkdir -p %t/bin
+// RUN: mkdir -p %t/lib
+// RUN: touch %t/lib/libLTO.dylib
+
+// Check that ld gets "-lto-no-unroll-loops" when -fno-unroll-loops is passed.
+//
+// RUN: %clang -target x86_64-apple-darwin10 %s -fno-unroll-loops -flto=full -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=NOUNROLL %s
+
+// NOUNROLL:  "-mllvm" "-lto-no-unroll-loops"
+//
+// RUN: %clang -target x86_64-apple-darwin10 %s -flto=full -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=UNROLL %s
+
+// UNROLL-NOT:  -lto-no-unroll-loops
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -542,6 +542,12 @@
 CmdArgs.push_back(Args.MakeArgString("-lto-stats-file=" + StatsFile.str()));
   }
 
+  // Forward -fno-unroll-loops to the linker in LTO.
+  if (Args.hasArg(options::OPT_fno_unroll_loops)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back(Args.MakeArgString("-lto-no-unroll-loops"));
+  }
+
   // It seems that the 'e' option is completely ignored for dynamic executables
   // (the default), and with static executables, the last one wins, as expected.
   Args.AddAllArgs(CmdArgs, {options::OPT_d_Flag, options::OPT_s, options::OPT_t,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76850: clang-format: Fix pointer alignment for overloaded operators (PR45107)

2020-03-27 Thread Hans Wennborg via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeb85e90350e9: clang-format: Fix pointer alignment for 
overloaded operators (PR45107) (authored by hans).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D76850?vs=252842=253065#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76850/new/

https://reviews.llvm.org/D76850

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -15386,6 +15386,13 @@
   verifyFormat("Foo::operator&&();", Style);
   verifyFormat("operator&&(int(&&)(), class Foo);", Style);
 
+  // PR45107
+  verifyFormat("operator Vector&();", Style);
+  verifyFormat("operator foo::Bar*();", Style);
+  verifyFormat("operator const Foo::Bar*();", Style);
+  verifyFormat("operator/*a*/ const /*b*/ Foo /*c*/ /*d*/ ::Bar*();",
+   Style);
+
   Style.PointerAlignment = FormatStyle::PAS_Middle;
   verifyFormat("Foo::operator*();", Style);
   verifyFormat("Foo::operator void *();", Style);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2799,20 +2799,38 @@
 tok::l_square));
   if (Right.is(tok::star) && Left.is(tok::l_paren))
 return false;
-  if (Right.isOneOf(tok::star, tok::amp, tok::ampamp) &&
-  (Left.is(tok::identifier) || Left.isSimpleTypeSpecifier()) &&
-  // Space between the type and the * in:
-  //   operator void*()
-  //   operator char*()
-  //   operator /*comment*/ const char*()
-  //   operator volatile /*comment*/ char*()
-  //   operator Foo*()
-  // dependent on PointerAlignment style.
-  Left.Previous &&
-  (Left.Previous->endsSequence(tok::kw_operator) ||
-   Left.Previous->endsSequence(tok::kw_const, tok::kw_operator) ||
-   Left.Previous->endsSequence(tok::kw_volatile, tok::kw_operator)))
-return (Style.PointerAlignment != FormatStyle::PAS_Left);
+  if (Right.isOneOf(tok::star, tok::amp, tok::ampamp)) {
+const FormatToken *Previous = 
+while (Previous && !Previous->is(tok::kw_operator)) {
+  if (Previous->is(tok::identifier) || Previous->isSimpleTypeSpecifier()) {
+Previous = Previous->getPreviousNonComment();
+continue;
+  }
+  if (Previous->is(TT_TemplateCloser) && Previous->MatchingParen) {
+Previous = Previous->MatchingParen->getPreviousNonComment();
+continue;
+  }
+  if (Previous->is(tok::coloncolon)) {
+Previous = Previous->getPreviousNonComment();
+continue;
+  }
+  break;
+}
+// Space between the type and the * in:
+//   operator void*()
+//   operator char*()
+//   operator /*comment*/ const char*()
+//   operator volatile /*comment*/ char*()
+//   operator Foo*()
+//   operator C*()
+//   operator std::Foo*()
+//   operator C::D*()
+// dependent on PointerAlignment style.
+if (Previous && (Previous->endsSequence(tok::kw_operator) ||
+   Previous->endsSequence(tok::kw_const, tok::kw_operator) ||
+   Previous->endsSequence(tok::kw_volatile, tok::kw_operator)))
+  return (Style.PointerAlignment != FormatStyle::PAS_Left);
+  }
   const auto SpaceRequiredForArrayInitializerLSquare =
   [](const FormatToken , const FormatStyle ) {
 return Style.SpacesInContainerLiterals ||


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -15386,6 +15386,13 @@
   verifyFormat("Foo::operator&&();", Style);
   verifyFormat("operator&&(int(&&)(), class Foo);", Style);
 
+  // PR45107
+  verifyFormat("operator Vector&();", Style);
+  verifyFormat("operator foo::Bar*();", Style);
+  verifyFormat("operator const Foo::Bar*();", Style);
+  verifyFormat("operator/*a*/ const /*b*/ Foo /*c*/ /*d*/ ::Bar*();",
+   Style);
+
   Style.PointerAlignment = FormatStyle::PAS_Middle;
   verifyFormat("Foo::operator*();", Style);
   verifyFormat("Foo::operator void *();", Style);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2799,20 +2799,38 @@
 tok::l_square));
   if (Right.is(tok::star) && Left.is(tok::l_paren))
 return false;
-  if (Right.isOneOf(tok::star, tok::amp, tok::ampamp) &&
-  (Left.is(tok::identifier) || Left.isSimpleTypeSpecifier()) &&
-  // Space between the type and the * in:
-  //   

[PATCH] D76830: [Analyzer][MallocChecker] No warning for kfree of ZERO_SIZE_PTR.

2020-03-27 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 253066.
balazske added a comment.

Checking for the macro value only if no memory region was found.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76830/new/

https://reviews.llvm.org/D76830

Files:
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
  clang/test/Analysis/kmalloc-linux-1.c

Index: clang/test/Analysis/kmalloc-linux-1.c
===
--- /dev/null
+++ clang/test/Analysis/kmalloc-linux-1.c
@@ -0,0 +1,27 @@
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux -analyzer-checker=unix.Malloc -verify %s
+
+#define ZERO_SIZE_PTR ((void *)16)
+
+void *__kmalloc(int size, int flags);
+
+// Linux kmalloc looks like this.
+// (simplified)
+void *kmalloc(int size, int flags) {
+  if (size == 0)
+return ZERO_SIZE_PTR;
+  return __kmalloc(size, flags);
+}
+
+// FIXME: malloc checker expects kfree with 2 arguments, is this correct?
+// (recent kernel source code contains a `kfree(const void *)`)
+void kfree(void *, int);
+
+void test_kmalloc_zero_sized_block_fixed_value_address() {
+  void *ptr = kmalloc(0, 0); // kmalloc returns a constant address
+  kfree(ptr, 0); // no warning about freeing a constant value
+}
+
+void test_kfree_constant_value() {
+  void *ptr = (void *)1;
+  kfree(ptr, 0); // expected-warning{{Argument to kfree() is a constant address (1)}}
+}
Index: clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
===
--- clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
@@ -126,9 +126,6 @@
 if (!T.isOneOf(tok::l_paren, tok::r_paren))
   FilteredTokens.push_back(T);
 
-  if (FilteredTokens.size() > 2)
-return llvm::None;
-
   // Parse an integer at the end of the macro definition.
   const Token  = FilteredTokens.back();
   if (!T.isLiteral())
@@ -140,11 +137,10 @@
 return llvm::None;
 
   // Parse an optional minus sign.
-  if (FilteredTokens.size() == 2) {
-if (FilteredTokens.front().is(tok::minus))
+  size_t Size = FilteredTokens.size();
+  if (Size >= 2) {
+if (FilteredTokens[Size - 2].is(tok::minus))
   IntValue = -IntValue;
-else
-  return llvm::None;
   }
 
   return IntValue.getSExtValue();
Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -58,6 +58,7 @@
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
@@ -389,6 +390,13 @@
   // TODO: Remove mutable by moving the initializtaion to the registry function.
   mutable Optional KernelZeroFlagVal;
 
+  using KernelZeroSizePtrValueTy = Optional;
+  /// Store the value of macro called `ZERO_SIZE_PTR`.
+  /// The value is initialized at first use, before first use the outer
+  /// Optional is empty, afterwards it contains another Optional that indicates
+  /// if the macro value could be determined, and if yes the value itself.
+  mutable Optional KernelZeroSizePtrValue;
+
   /// Process C++ operator new()'s allocation, which is the part of C++
   /// new-expression that goes before the constructor.
   void processNewAllocation(const CXXNewExpr *NE, CheckerContext ,
@@ -658,6 +666,9 @@
 CheckerContext );
 
   void reportLeak(SymbolRef Sym, ExplodedNode *N, CheckerContext ) const;
+
+  /// Test if value in ArgVal equals to value in macro `ZERO_SIZE_PTR`.
+  bool isArgZERO_SIZE_PTR(ProgramStateRef State, CheckerContext , SVal ArgVal) const;
 };
 
 //===--===//
@@ -1677,7 +1688,12 @@
   // Nonlocs can't be freed, of course.
   // Non-region locations (labels and fixed addresses) also shouldn't be freed.
   if (!R) {
-ReportBadFree(C, ArgVal, ArgExpr->getSourceRange(), ParentExpr, Family);
+// Exception:
+// If there is a macro called ZERO_SIZE_PTR, it could be a kernel source code
+// and this value indicates a special value used for a zero-sized memory
+// block. It is a constant value that is allowed to be freed.
+if (!isArgZERO_SIZE_PTR(State, C, ArgVal))
+  ReportBadFree(C, ArgVal, ArgExpr->getSourceRange(), ParentExpr, Family);
 return nullptr;
   }
 
@@ -3023,6 +3039,17 @@
   return State;
 }
 
+bool MallocChecker::isArgZERO_SIZE_PTR(ProgramStateRef State, 

[PATCH] D76830: [Analyzer][MallocChecker] No warning for kfree of ZERO_SIZE_PTR.

2020-03-27 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked an inline comment as done.
balazske added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:1687
+  if (ArgValKnown) {
+if (!KernelZeroSizePtrValue)
+  KernelZeroSizePtrValue =

Szelethus wrote:
> balazske wrote:
> > Szelethus wrote:
> > > Szelethus wrote:
> > > > martong wrote:
> > > > > balazske wrote:
> > > > > > martong wrote:
> > > > > > > martong wrote:
> > > > > > > > This is a bit confusing for me. Perhaps alternatively we could 
> > > > > > > > have a free function `isInitialized(KernelZero...)` instead. Or 
> > > > > > > > maybe having a separate bool variable to indicate whether it 
> > > > > > > > was initialized could be cleaner?
> > > > > > > Another idea: Adding a helper struct to contain the bool 
> > > > > > > `initialized`? E.g. (draft):
> > > > > > > ```
> > > > > > > struct LazyOptional {
> > > > > > >   bool initialized = false;
> > > > > > >   Opt value;
> > > > > > >   Opt& get();
> > > > > > >   void set(const Opt&);
> > > > > > > };
> > > > > > > ```
> > > > > > It may be OK to have a function `lazyInitKernelZeroSizePtrValue`?
> > > > > I don't insist, given we have a better described type for 
> > > > > `KernelZeroSizePtrValue` (e.g. having a `using` `template`)
> > > > `AnalysisManager` has access to the `Preprocessor`, and it is also 
> > > > responsible for the construction of the `CheckerManager` object. This 
> > > > would make moving such code to the checker registry function! I'll 
> > > > gladly take this issue off your hand and patch it in once 
> > > > rG2aac0c47aed8d1eff7ab6d858173c532b881d948 settles :)
> > > Just pushed rG4dc8472942ce60f29de9587b9451cc3d49df7abf. It it settles (no 
> > > buildbots complain), you could rebase and the lazy initialization could 
> > > be a thing of the past! :)
> > This makes it possible to have a generic one-time initialization function 
> > in the checker (`CheckerBase`)? The functionality is needed in more than 
> > one checker, at least for the bug types it can be used in almost every 
> > checker (that has bugtypes).
> I'm not sure I understand what you mean -- do you want to add 
> `CheckerManager` to `CheckerBase`'s constructor?
> 
> In any case, I remember reading something around `CheckerBase`'s or 
> `BugType`'s implementation the way the checker receives its name is a bit 
> tricky and not a part of the construction.
Initialization in register function does not work: The `MacroInfo` is not found 
in the preprocessor. Probably the code is not parsed normally at that time. For 
now only the lazy initialization is working.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76830/new/

https://reviews.llvm.org/D76830



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


[PATCH] D76830: [Analyzer][MallocChecker] No warning for kfree of ZERO_SIZE_PTR.

2020-03-27 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:1687
+  if (ArgValKnown) {
+if (!KernelZeroSizePtrValue)
+  KernelZeroSizePtrValue =

balazske wrote:
> Szelethus wrote:
> > Szelethus wrote:
> > > martong wrote:
> > > > balazske wrote:
> > > > > martong wrote:
> > > > > > martong wrote:
> > > > > > > This is a bit confusing for me. Perhaps alternatively we could 
> > > > > > > have a free function `isInitialized(KernelZero...)` instead. Or 
> > > > > > > maybe having a separate bool variable to indicate whether it was 
> > > > > > > initialized could be cleaner?
> > > > > > Another idea: Adding a helper struct to contain the bool 
> > > > > > `initialized`? E.g. (draft):
> > > > > > ```
> > > > > > struct LazyOptional {
> > > > > >   bool initialized = false;
> > > > > >   Opt value;
> > > > > >   Opt& get();
> > > > > >   void set(const Opt&);
> > > > > > };
> > > > > > ```
> > > > > It may be OK to have a function `lazyInitKernelZeroSizePtrValue`?
> > > > I don't insist, given we have a better described type for 
> > > > `KernelZeroSizePtrValue` (e.g. having a `using` `template`)
> > > `AnalysisManager` has access to the `Preprocessor`, and it is also 
> > > responsible for the construction of the `CheckerManager` object. This 
> > > would make moving such code to the checker registry function! I'll gladly 
> > > take this issue off your hand and patch it in once 
> > > rG2aac0c47aed8d1eff7ab6d858173c532b881d948 settles :)
> > Just pushed rG4dc8472942ce60f29de9587b9451cc3d49df7abf. It it settles (no 
> > buildbots complain), you could rebase and the lazy initialization could be 
> > a thing of the past! :)
> This makes it possible to have a generic one-time initialization function in 
> the checker (`CheckerBase`)? The functionality is needed in more than one 
> checker, at least for the bug types it can be used in almost every checker 
> (that has bugtypes).
I'm not sure I understand what you mean -- do you want to add `CheckerManager` 
to `CheckerBase`'s constructor?

In any case, I remember reading something around `CheckerBase`'s or `BugType`'s 
implementation the way the checker receives its name is a bit tricky and not a 
part of the construction.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76830/new/

https://reviews.llvm.org/D76830



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


[PATCH] D76850: clang-format: Fix pointer alignment for overloaded operators (PR45107)

2020-03-27 Thread Hans Wennborg via Phabricator via cfe-commits
hans marked an inline comment as done.
hans added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:2806
+  if (Previous->is(tok::identifier) || Previous->isSimpleTypeSpecifier()) {
+Previous = Previous->Previous;
+continue;

krasimir wrote:
> Consider using `Previous->getPreviousNonComment()` here and below to jump 
> over comments.
Thanks! Doing this, and adding a test that requires it.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76850/new/

https://reviews.llvm.org/D76850



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


[clang] eb85e90 - clang-format: Fix pointer alignment for overloaded operators (PR45107)

2020-03-27 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2020-03-27T10:47:19+01:00
New Revision: eb85e90350e93a64279139e7eca9ca40c8fbf5eb

URL: 
https://github.com/llvm/llvm-project/commit/eb85e90350e93a64279139e7eca9ca40c8fbf5eb
DIFF: 
https://github.com/llvm/llvm-project/commit/eb85e90350e93a64279139e7eca9ca40c8fbf5eb.diff

LOG: clang-format: Fix pointer alignment for overloaded operators (PR45107)

This fixes a regression from D69573 which broke the following example:

  $ echo 'operator C*();' | bin/clang-format --style=Chromium
  operator C *();

(There should be no space before the asterisk.)

It seems the problem is in TokenAnnotator::spaceRequiredBetween(),
which only looked at the token to the left of the * to see if it was a
type or not. That code only handled simple types or identifiers, not
templates or qualified types. This patch addresses that.

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

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index f2666a8bd171..8a1e247463d5 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2799,20 +2799,38 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine ,
 tok::l_square));
   if (Right.is(tok::star) && Left.is(tok::l_paren))
 return false;
-  if (Right.isOneOf(tok::star, tok::amp, tok::ampamp) &&
-  (Left.is(tok::identifier) || Left.isSimpleTypeSpecifier()) &&
-  // Space between the type and the * in:
-  //   operator void*()
-  //   operator char*()
-  //   operator /*comment*/ const char*()
-  //   operator volatile /*comment*/ char*()
-  //   operator Foo*()
-  // dependent on PointerAlignment style.
-  Left.Previous &&
-  (Left.Previous->endsSequence(tok::kw_operator) ||
-   Left.Previous->endsSequence(tok::kw_const, tok::kw_operator) ||
-   Left.Previous->endsSequence(tok::kw_volatile, tok::kw_operator)))
-return (Style.PointerAlignment != FormatStyle::PAS_Left);
+  if (Right.isOneOf(tok::star, tok::amp, tok::ampamp)) {
+const FormatToken *Previous = 
+while (Previous && !Previous->is(tok::kw_operator)) {
+  if (Previous->is(tok::identifier) || Previous->isSimpleTypeSpecifier()) {
+Previous = Previous->getPreviousNonComment();
+continue;
+  }
+  if (Previous->is(TT_TemplateCloser) && Previous->MatchingParen) {
+Previous = Previous->MatchingParen->getPreviousNonComment();
+continue;
+  }
+  if (Previous->is(tok::coloncolon)) {
+Previous = Previous->getPreviousNonComment();
+continue;
+  }
+  break;
+}
+// Space between the type and the * in:
+//   operator void*()
+//   operator char*()
+//   operator /*comment*/ const char*()
+//   operator volatile /*comment*/ char*()
+//   operator Foo*()
+//   operator C*()
+//   operator std::Foo*()
+//   operator C::D*()
+// dependent on PointerAlignment style.
+if (Previous && (Previous->endsSequence(tok::kw_operator) ||
+   Previous->endsSequence(tok::kw_const, tok::kw_operator) ||
+   Previous->endsSequence(tok::kw_volatile, tok::kw_operator)))
+  return (Style.PointerAlignment != FormatStyle::PAS_Left);
+  }
   const auto SpaceRequiredForArrayInitializerLSquare =
   [](const FormatToken , const FormatStyle ) {
 return Style.SpacesInContainerLiterals ||

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index a6f35ba27069..fe16eeaba53c 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -15386,6 +15386,13 @@ TEST_F(FormatTest, OperatorSpacing) {
   verifyFormat("Foo::operator&&();", Style);
   verifyFormat("operator&&(int(&&)(), class Foo);", Style);
 
+  // PR45107
+  verifyFormat("operator Vector&();", Style);
+  verifyFormat("operator foo::Bar*();", Style);
+  verifyFormat("operator const Foo::Bar*();", Style);
+  verifyFormat("operator/*a*/ const /*b*/ Foo /*c*/ /*d*/ ::Bar*();",
+   Style);
+
   Style.PointerAlignment = FormatStyle::PAS_Middle;
   verifyFormat("Foo::operator*();", Style);
   verifyFormat("Foo::operator void *();", Style);



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


[PATCH] D76856: Fix TBAA for unsigned fixed-point types

2020-03-27 Thread Mikael Holmén via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7d482e921353: Fix TBAA for unsigned fixed-point types 
(authored by uabelho).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76856/new/

https://reviews.llvm.org/D76856

Files:
  clang/lib/CodeGen/CodeGenTBAA.cpp
  clang/test/CodeGen/fixed-point-tbaa.c

Index: clang/test/CodeGen/fixed-point-tbaa.c
===
--- /dev/null
+++ clang/test/CodeGen/fixed-point-tbaa.c
@@ -0,0 +1,109 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -ffixed-point %s -emit-llvm -o - | FileCheck %s  -check-prefixes=CHECK
+//
+// Check that we generate correct TBAA metadata for fixed-point types.
+
+void sfract(unsigned short _Fract *p, short _Fract *q,
+unsigned _Sat short _Fract *r, _Sat short _Fract *s) {
+  // CHECK-LABEL: define void @sfract
+  // CHECK: store i8 -128, i8* %p, align 1, !tbaa [[TAG_sf:!.*]]
+  // CHECK: store i8 -64, i8* %q, align 1, !tbaa [[TAG_sf]]
+  // CHECK: store i8 -128, i8* %r, align 1, !tbaa [[TAG_sat_sf:!.*]]
+  // CHECK: store i8 -64, i8* %s, align 1, !tbaa [[TAG_sat_sf]]
+  *p = 0.5hur;
+  *q = -0.5hr;
+  *r = 0.5hur;
+  *s = -0.5hr;
+}
+
+void fract(unsigned _Fract *p, _Fract *q,
+   unsigned _Sat _Fract *r, _Sat _Fract *s) {
+  // CHECK-LABEL: define void @fract
+  // CHECK: store i16 -32768, i16* %p, align 2, !tbaa [[TAG_f:!.*]]
+  // CHECK: store i16 -16384, i16* %q, align 2, !tbaa [[TAG_f]]
+  // CHECK: store i16 -32768, i16* %r, align 2, !tbaa [[TAG_sat_f:!.*]]
+  // CHECK: store i16 -16384, i16* %s, align 2, !tbaa [[TAG_sat_f]]
+  *p = 0.5ur;
+  *q = -0.5r;
+  *r = 0.5ur;
+  *s = -0.5r;
+}
+
+void lfract(unsigned long _Fract *p, long _Fract *q,
+unsigned _Sat long _Fract *r, _Sat long _Fract *s) {
+  // CHECK-LABEL: define void @lfract
+  // CHECK: store i32 -2147483648, i32* %p, align 4, !tbaa [[TAG_lf:!.*]]
+  // CHECK: store i32 -1073741824, i32* %q, align 4, !tbaa [[TAG_lf]]
+  // CHECK: store i32 -2147483648, i32* %r, align 4, !tbaa [[TAG_sat_lf:!.*]]
+  // CHECK: store i32 -1073741824, i32* %s, align 4, !tbaa [[TAG_sat_lf]]
+  *p = 0.5ulr;
+  *q = -0.5lr;
+  *r = 0.5ulr;
+  *s = -0.5lr;
+}
+
+void saccum(unsigned short _Accum *p, short _Accum *q,
+unsigned _Sat short _Accum *r, _Sat short _Accum *s) {
+  // CHECK-LABEL: define void @saccum
+  // CHECK: store i16 128, i16* %p, align 2, !tbaa [[TAG_sk:!.*]]
+  // CHECK: store i16 -64, i16* %q, align 2, !tbaa [[TAG_sk]]
+  // CHECK: store i16 128, i16* %r, align 2, !tbaa [[TAG_sat_sk:!.*]]
+  // CHECK: store i16 -64, i16* %s, align 2, !tbaa [[TAG_sat_sk]]
+  *p = 0.5huk;
+  *q = -0.5hk;
+  *r = 0.5huk;
+  *s = -0.5hk;
+}
+
+void accum(unsigned _Accum *p, _Accum *q,
+   unsigned _Sat _Accum *r, _Sat _Accum *s) {
+  // CHECK-LABEL: define void @accum
+  // CHECK: store i32 32768, i32* %p, align 4, !tbaa [[TAG_k:!.*]]
+  // CHECK: store i32 -16384, i32* %q, align 4, !tbaa [[TAG_k]]
+  // CHECK: store i32 32768, i32* %r, align 4, !tbaa [[TAG_sat_k:!.*]]
+  // CHECK: store i32 -16384, i32* %s, align 4, !tbaa [[TAG_sat_k]]
+  *p = 0.5uk;
+  *q = -0.5k;
+  *r = 0.5uk;
+  *s = -0.5k;
+}
+
+void laccum(unsigned long _Accum *p, long _Accum *q,
+unsigned _Sat long _Accum *r, _Sat long _Accum *s) {
+  // CHECK-LABEL: define void @laccum
+  // CHECK: store i64 2147483648, i64* %p, align 8, !tbaa [[TAG_lk:!.*]]
+  // CHECK: store i64 -1073741824, i64* %q, align 8, !tbaa [[TAG_lk]]
+  // CHECK: store i64 2147483648, i64* %r, align 8, !tbaa [[TAG_sat_lk:!.*]]
+  // CHECK: store i64 -1073741824, i64* %s, align 8, !tbaa [[TAG_sat_lk]]
+  *p = 0.5ulk;
+  *q = -0.5lk;
+  *r = 0.5ulk;
+  *s = -0.5lk;
+}
+
+// CHECK-DAG: [[TAG_sf]] = !{[[TYPE_sf:!.*]], [[TYPE_sf]], i64 0}
+// CHECK-DAG: [[TYPE_sf]] = !{!"short _Fract"
+// CHECK-DAG: [[TAG_f]] = !{[[TYPE_f:!.*]], [[TYPE_f]], i64 0}
+// CHECK-DAG: [[TYPE_f]] = !{!"_Fract"
+// CHECK-DAG: [[TAG_lf]] = !{[[TYPE_lf:!.*]], [[TYPE_lf]], i64 0}
+// CHECK-DAG: [[TYPE_lf]] = !{!"long _Fract"
+
+// CHECK-DAG: [[TAG_sat_sf]] = !{[[TYPE_sat_sf:!.*]], [[TYPE_sat_sf]], i64 0}
+// CHECK-DAG: [[TYPE_sat_sf]] = !{!"_Sat short _Fract"
+// CHECK-DAG: [[TAG_sat_f]] = !{[[TYPE_sat_f:!.*]], [[TYPE_sat_f]], i64 0}
+// CHECK-DAG: [[TYPE_sat_f]] = !{!"_Sat _Fract"
+// CHECK-DAG: [[TAG_sat_lf]] = !{[[TYPE_sat_lf:!.*]], [[TYPE_sat_lf]], i64 0}
+// CHECK-DAG: [[TYPE_sat_lf]] = !{!"_Sat long _Fract"
+
+// CHECK-DAG: [[TAG_sk]] = !{[[TYPE_sk:!.*]], [[TYPE_sk]], i64 0}
+// CHECK-DAG: [[TYPE_sk]] = !{!"short _Accum"
+// CHECK-DAG: [[TAG_k]] = !{[[TYPE_k:!.*]], [[TYPE_k]], i64 0}
+// CHECK-DAG: [[TYPE_k]] = !{!"_Accum"
+// CHECK-DAG: [[TAG_lk]] = !{[[TYPE_lk:!.*]], [[TYPE_lk]], i64 0}
+// CHECK-DAG: [[TYPE_lk]] = !{!"long _Accum"
+
+// CHECK-DAG: [[TAG_sat_sk]] = !{[[TYPE_sat_sk:!.*]], [[TYPE_sat_sk]], i64 0}
+// CHECK-DAG: [[TYPE_sat_sk]] = !{!"_Sat short _Accum"
+// CHECK-DAG: 

[clang] 7d482e9 - Fix TBAA for unsigned fixed-point types

2020-03-27 Thread Mikael Holmen via cfe-commits

Author: Mikael Holmen
Date: 2020-03-27T10:35:24+01:00
New Revision: 7d482e9213537d9c5811d9fb68bace8fcb648132

URL: 
https://github.com/llvm/llvm-project/commit/7d482e9213537d9c5811d9fb68bace8fcb648132
DIFF: 
https://github.com/llvm/llvm-project/commit/7d482e9213537d9c5811d9fb68bace8fcb648132.diff

LOG: Fix TBAA for unsigned fixed-point types

Summary:
Unsigned types can alias the corresponding signed types. I don't see
that this is explicitly mentioned in the Embedded-C specification, but
I think it should work the same as for the integer types.

Patch by: materi

Reviewers: ebevhan, leonardchan

Reviewed By: leonardchan

Subscribers: kosarev, cfe-commits

Tags: #clang

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

Added: 
clang/test/CodeGen/fixed-point-tbaa.c

Modified: 
clang/lib/CodeGen/CodeGenTBAA.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index 7d730cb1ed15..8cc8c162dfbe 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -141,6 +141,34 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type 
*Ty) {
 case BuiltinType::UInt128:
   return getTypeInfo(Context.Int128Ty);
 
+case BuiltinType::UShortFract:
+  return getTypeInfo(Context.ShortFractTy);
+case BuiltinType::UFract:
+  return getTypeInfo(Context.FractTy);
+case BuiltinType::ULongFract:
+  return getTypeInfo(Context.LongFractTy);
+
+case BuiltinType::SatUShortFract:
+  return getTypeInfo(Context.SatShortFractTy);
+case BuiltinType::SatUFract:
+  return getTypeInfo(Context.SatFractTy);
+case BuiltinType::SatULongFract:
+  return getTypeInfo(Context.SatLongFractTy);
+
+case BuiltinType::UShortAccum:
+  return getTypeInfo(Context.ShortAccumTy);
+case BuiltinType::UAccum:
+  return getTypeInfo(Context.AccumTy);
+case BuiltinType::ULongAccum:
+  return getTypeInfo(Context.LongAccumTy);
+
+case BuiltinType::SatUShortAccum:
+  return getTypeInfo(Context.SatShortAccumTy);
+case BuiltinType::SatUAccum:
+  return getTypeInfo(Context.SatAccumTy);
+case BuiltinType::SatULongAccum:
+  return getTypeInfo(Context.SatLongAccumTy);
+
 // Treat all other builtin types as distinct types. This includes
 // treating wchar_t, char16_t, and char32_t as distinct from their
 // "underlying types".

diff  --git a/clang/test/CodeGen/fixed-point-tbaa.c 
b/clang/test/CodeGen/fixed-point-tbaa.c
new file mode 100644
index ..069860331673
--- /dev/null
+++ b/clang/test/CodeGen/fixed-point-tbaa.c
@@ -0,0 +1,109 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -ffixed-point %s -emit-llvm 
-o - | FileCheck %s  -check-prefixes=CHECK
+//
+// Check that we generate correct TBAA metadata for fixed-point types.
+
+void sfract(unsigned short _Fract *p, short _Fract *q,
+unsigned _Sat short _Fract *r, _Sat short _Fract *s) {
+  // CHECK-LABEL: define void @sfract
+  // CHECK: store i8 -128, i8* %p, align 1, !tbaa [[TAG_sf:!.*]]
+  // CHECK: store i8 -64, i8* %q, align 1, !tbaa [[TAG_sf]]
+  // CHECK: store i8 -128, i8* %r, align 1, !tbaa [[TAG_sat_sf:!.*]]
+  // CHECK: store i8 -64, i8* %s, align 1, !tbaa [[TAG_sat_sf]]
+  *p = 0.5hur;
+  *q = -0.5hr;
+  *r = 0.5hur;
+  *s = -0.5hr;
+}
+
+void fract(unsigned _Fract *p, _Fract *q,
+   unsigned _Sat _Fract *r, _Sat _Fract *s) {
+  // CHECK-LABEL: define void @fract
+  // CHECK: store i16 -32768, i16* %p, align 2, !tbaa [[TAG_f:!.*]]
+  // CHECK: store i16 -16384, i16* %q, align 2, !tbaa [[TAG_f]]
+  // CHECK: store i16 -32768, i16* %r, align 2, !tbaa [[TAG_sat_f:!.*]]
+  // CHECK: store i16 -16384, i16* %s, align 2, !tbaa [[TAG_sat_f]]
+  *p = 0.5ur;
+  *q = -0.5r;
+  *r = 0.5ur;
+  *s = -0.5r;
+}
+
+void lfract(unsigned long _Fract *p, long _Fract *q,
+unsigned _Sat long _Fract *r, _Sat long _Fract *s) {
+  // CHECK-LABEL: define void @lfract
+  // CHECK: store i32 -2147483648, i32* %p, align 4, !tbaa [[TAG_lf:!.*]]
+  // CHECK: store i32 -1073741824, i32* %q, align 4, !tbaa [[TAG_lf]]
+  // CHECK: store i32 -2147483648, i32* %r, align 4, !tbaa [[TAG_sat_lf:!.*]]
+  // CHECK: store i32 -1073741824, i32* %s, align 4, !tbaa [[TAG_sat_lf]]
+  *p = 0.5ulr;
+  *q = -0.5lr;
+  *r = 0.5ulr;
+  *s = -0.5lr;
+}
+
+void saccum(unsigned short _Accum *p, short _Accum *q,
+unsigned _Sat short _Accum *r, _Sat short _Accum *s) {
+  // CHECK-LABEL: define void @saccum
+  // CHECK: store i16 128, i16* %p, align 2, !tbaa [[TAG_sk:!.*]]
+  // CHECK: store i16 -64, i16* %q, align 2, !tbaa [[TAG_sk]]
+  // CHECK: store i16 128, i16* %r, align 2, !tbaa [[TAG_sat_sk:!.*]]
+  // CHECK: store i16 -64, i16* %s, align 2, !tbaa [[TAG_sat_sk]]
+  *p = 0.5huk;
+  *q = -0.5hk;
+  *r = 0.5huk;
+  *s = -0.5hk;
+}
+
+void accum(unsigned _Accum *p, _Accum *q,
+   unsigned _Sat _Accum *r, 

[PATCH] D76572: Replace `T(x)` with `reinterpret_cast(x)` everywhere it means reinterpret_cast. No functional change

2020-03-27 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg added a comment.

In D76572#1936935 , @grandinj wrote:

> In D76572#1936861 , @Quuxplusone 
> wrote:
>
> > Nice. Does LibreOffice have anything (either in clang-tidy or in a paper 
> > guideline) against `T(x)`-style casts? E.g.
>
>
> No, we don't have very many of those in our codebase, so we have left them 
> alone.
>  Our plugin is designed to convert c-style casts to modern C++ casts.


Heh, I've meanwhile improved LibreOffice's cstylecast check now (after I'd read 
only the first few initial comments here), to also flag function-style casts 
that should be const_/reinterpret_cast, and it indeed only found a handful of 
cases that would better be reinterpret_cast 
(https://gerrit.libreoffice.org/plugins/gitiles/core/+/1ebeacb20ad0165e399629fcfd7795ad0da3edf8%5E!/
 "Extend loplugin:cstylecast to certain function-style casts").  Though in two 
of those places it conveniently unearthed code that should rather do without 
any kind of casting (addressed with follow-up 
https://gerrit.libreoffice.org/plugins/gitiles/core/+/741d30b5e1b0dcdbafb300ed7c7ad46756ffd946%5E!/
 "Simplify pointer equality comparison" and 
https://gerrit.libreoffice.org/plugins/gitiles/core/+/e3196f3dddad6e7825db3b35e8196be35b466fd9%5E!/
 "Fix pointer equality comparision").


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76572/new/

https://reviews.llvm.org/D76572



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


[PATCH] D74941: [OpenMP] `omp begin/end declare variant` - part 1, parsing

2020-03-27 Thread Johannes Doerfert via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG095cecbe0ded: [OpenMP] `omp begin/end declare variant` - 
part 1, parsing (authored by jdoerfert).
Herald added a subscriber: hiraditya.

Changed prior to commit:
  https://reviews.llvm.org/D74941?vs=246630=253052#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74941/new/

https://reviews.llvm.org/D74941

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Parse/Parser.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant.c
  clang/test/OpenMP/begin-declare-variant_no_end_for_matching_selector.c
  clang/test/OpenMP/begin_declare_variant_messages.c
  clang/test/OpenMP/declare_variant_messages.c
  clang/test/OpenMP/declare_variant_messages.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPContext.cpp

Index: llvm/lib/Frontend/OpenMP/OMPContext.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPContext.cpp
+++ llvm/lib/Frontend/OpenMP/OMPContext.cpp
@@ -450,6 +450,8 @@
   StringRef(Str) != "invalid") \
 S.append("'").append(Str).append("'").append(" ");
 #include "llvm/Frontend/OpenMP/OMPKinds.def"
+  if (S.empty())
+return "";
   S.pop_back();
   return S;
 }
Index: llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
===
--- llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -93,6 +93,8 @@
 "parallel master taskloop simd")
 __OMP_DIRECTIVE(depobj)
 __OMP_DIRECTIVE(scan)
+__OMP_DIRECTIVE_EXT(begin_declare_variant, "begin declare variant")
+__OMP_DIRECTIVE_EXT(end_declare_variant, "end declare variant")
 
 // Has to be the last because Clang implicitly expects it to be.
 __OMP_DIRECTIVE(unknown)
Index: clang/test/OpenMP/declare_variant_messages.cpp
===
--- clang/test/OpenMP/declare_variant_messages.cpp
+++ clang/test/OpenMP/declare_variant_messages.cpp
@@ -43,8 +43,8 @@
 #pragma omp declare variant(foofoo ) match(device={kind}) // expected-warning {{the context selector 'kind' in context set 'device' requires a context property defined in parentheses; selector ignored}} expected-note {{the ignored selector spans until here}}
 #pragma omp declare variant(foofoo ) match(device={kind(}) // expected-error {{expected ')'}} expected-warning {{expected identifier or string literal describing a context property; property skipped}} expected-note {{context property options are: 'host' 'nohost' 'cpu' 'gpu' 'fpga' 'any'}} expected-note {{to match this '('}}
 #pragma omp declare variant(foofoo ) match(device={kind()}) // expected-warning {{expected identifier or string literal describing a context property; property skipped}} expected-note {{context property options are: 'host' 'nohost' 'cpu' 'gpu' 'fpga' 'any'}}
-#pragma omp declare variant(foofoo ) match(device={kind(score cpu)}) // expected-error {{expected '(' after 'score'}} expected-warning {{expected '':'' after the score expression; '':'' assumed}}
-#pragma omp declare variant(foofoo ) match(device={kind(score( ibm)}) // expected-error {{use of undeclared identifier 'ibm'}} expected-error {{expected ')'}} expected-warning {{expected '':'' after the score expression; '':'' assumed}} expected-warning {{expected identifier or string literal describing a context property; property skipped}} expected-note {{context property options are: 'host' 'nohost' 'cpu' 'gpu' 'fpga' 'any'}} expected-note {{to match this '('}}
+#pragma omp declare variant(foofoo ) match(device={kind(score cpu)}) // expected-error {{expected '(' after 'score'}} expected-warning {{expected '':'' after the score expression; '':'' assumed}} expected-warning {{the context selector 'kind' in the context set 'device' cannot have a score (''); score ignored}}
+#pragma omp declare variant(foofoo ) match(device={kind(score( ibm)}) // expected-error {{use of undeclared identifier 'ibm'}} expected-error {{expected ')'}} expected-warning {{expected '':'' after the score expression; '':'' assumed}} expected-warning {{the context selector 'kind' in the context set 'device' cannot have a score (''); score ignored}} expected-warning {{expected identifier or string literal describing a context property; property skipped}} expected-note {{context property options are: 'host' 'nohost' 'cpu' 'gpu' 'fpga' 'any'}} expected-note {{to match this '('}}
 #pragma omp declare variant(foofoo ) match(device={kind(score(2 gpu)}) // expected-error {{expected ')'}} 

[PATCH] D76830: [Analyzer][MallocChecker] No warning for kfree of ZERO_SIZE_PTR.

2020-03-27 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked an inline comment as done.
balazske added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:1687
+  if (ArgValKnown) {
+if (!KernelZeroSizePtrValue)
+  KernelZeroSizePtrValue =

Szelethus wrote:
> Szelethus wrote:
> > martong wrote:
> > > balazske wrote:
> > > > martong wrote:
> > > > > martong wrote:
> > > > > > This is a bit confusing for me. Perhaps alternatively we could have 
> > > > > > a free function `isInitialized(KernelZero...)` instead. Or maybe 
> > > > > > having a separate bool variable to indicate whether it was 
> > > > > > initialized could be cleaner?
> > > > > Another idea: Adding a helper struct to contain the bool 
> > > > > `initialized`? E.g. (draft):
> > > > > ```
> > > > > struct LazyOptional {
> > > > >   bool initialized = false;
> > > > >   Opt value;
> > > > >   Opt& get();
> > > > >   void set(const Opt&);
> > > > > };
> > > > > ```
> > > > It may be OK to have a function `lazyInitKernelZeroSizePtrValue`?
> > > I don't insist, given we have a better described type for 
> > > `KernelZeroSizePtrValue` (e.g. having a `using` `template`)
> > `AnalysisManager` has access to the `Preprocessor`, and it is also 
> > responsible for the construction of the `CheckerManager` object. This would 
> > make moving such code to the checker registry function! I'll gladly take 
> > this issue off your hand and patch it in once 
> > rG2aac0c47aed8d1eff7ab6d858173c532b881d948 settles :)
> Just pushed rG4dc8472942ce60f29de9587b9451cc3d49df7abf. It it settles (no 
> buildbots complain), you could rebase and the lazy initialization could be a 
> thing of the past! :)
This makes it possible to have a generic one-time initialization function in 
the checker (`CheckerBase`)? The functionality is needed in more than one 
checker, at least for the bug types it can be used in almost every checker 
(that has bugtypes).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76830/new/

https://reviews.llvm.org/D76830



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


[clang] 095cecb - [OpenMP] `omp begin/end declare variant` - part 1, parsing

2020-03-27 Thread Johannes Doerfert via cfe-commits

Author: Johannes Doerfert
Date: 2020-03-27T02:30:58-05:00
New Revision: 095cecbe0ded16f2e66435d938fdc3cb1869713f

URL: 
https://github.com/llvm/llvm-project/commit/095cecbe0ded16f2e66435d938fdc3cb1869713f
DIFF: 
https://github.com/llvm/llvm-project/commit/095cecbe0ded16f2e66435d938fdc3cb1869713f.diff

LOG: [OpenMP] `omp begin/end declare variant` - part 1, parsing

This is the first part extracted from D71179 and cleaned up.

This patch provides parsing support for `omp begin/end declare variant`,
as defined in OpenMP technical report 8 (TR8) [0].

A major purpose of this patch is to provide proper math.h/cmath support
for OpenMP target offloading. See PR42061, PR42798, PR42799. The current
code was developed with this feature in mind, see [1].

[0] https://www.openmp.org/wp-content/uploads/openmp-TR8.pdf
[1] https://reviews.llvm.org/D61399#change-496lQkg0mhRN

Reviewed By: aaron.ballman

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

Added: 
clang/test/AST/ast-dump-openmp-begin-declare-variant.c
clang/test/OpenMP/begin-declare-variant_no_end_for_matching_selector.c
clang/test/OpenMP/begin_declare_variant_messages.c

Modified: 
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Parse/Parser.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/Basic/OpenMPKinds.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/declare_variant_messages.c
clang/test/OpenMP/declare_variant_messages.cpp
llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
llvm/lib/Frontend/OpenMP/OMPContext.cpp

Removed: 




diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 29c251ef7ee6..4abe5984936d 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -7178,9 +7178,11 @@ class OMPTraitInfo {
   /// former is a flat representation the actual main 
diff erence is that the
   /// latter uses clang::Expr to store the score/condition while the former is
   /// independent of clang. Thus, expressions and conditions are evaluated in
-  /// this method.
+  /// this method. If \p DeviceSetOnly is true, only the device selector set, 
if
+  /// present, is put in \p VMI, otherwise all selector sets are put in \p VMI.
   void getAsVariantMatchInfo(ASTContext ,
- llvm::omp::VariantMatchInfo ) const;
+ llvm::omp::VariantMatchInfo ,
+ bool DeviceSetOnly) const;
 
   /// Print a human readable representation into \p OS.
   void print(llvm::raw_ostream , const PrintingPolicy ) const;

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index dcbb0d3f8799..482b6933b30b 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1232,8 +1232,8 @@ def err_omp_map_type_modifier_missing : Error<
   "missing map type modifier">;
 def err_omp_declare_simd_inbranch_notinbranch : Error<
   "unexpected '%0' clause, '%1' is specified already">;
-def err_expected_end_declare_target : Error<
-  "expected '#pragma omp end declare target'">;
+def err_expected_end_declare_target_or_variant : Error<
+  "expected '#pragma omp end declare %select{target|variant}0'">;
 def err_omp_declare_target_unexpected_clause: Error<
   "unexpected '%0' clause, only %select{'to' or 'link'|'to', 'link' or 
'device_type'}1 clauses expected">;
 def err_omp_expected_clause: Error<

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index d0e2540938d6..6ebceee006e6 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -2963,9 +2963,14 @@ class Parser : public CodeCompletionHandler {
   /// Parses OpenMP context selectors.
   bool parseOMPContextSelectors(SourceLocation Loc, OMPTraitInfo );
 
+  /// Parse a `match` clause for an '#pragma omp declare variant'. Return true
+  /// if there was an error.
+  bool parseOMPDeclareVariantMatchClause(SourceLocation Loc, OMPTraitInfo );
+
   /// Parse clauses for '#pragma omp declare variant'.
   void ParseOMPDeclareVariantClauses(DeclGroupPtrTy Ptr, CachedTokens ,
  SourceLocation Loc);
+
   /// Parse clauses for '#pragma omp declare target'.
   DeclGroupPtrTy ParseOMPDeclareTargetClauses();
   /// Parse '#pragma omp end declare target'.
@@ -2976,6 +2981,17 @@ class Parser : public CodeCompletionHandler {
   /// it is not the current token.
   void skipUntilPragmaOpenMPEnd(OpenMPDirectiveKind DKind);
 
+  /// Check the \p FoundKind against the \p ExpectedKind, if not issue an error
+  /// that the "end" matching the "begin" directive 

[clang] b293224 - [OpenMP][NFC] Open `llvm` and `llvm::omp` namespace in OpenMPClause.cpp

2020-03-27 Thread Johannes Doerfert via cfe-commits

Author: Johannes Doerfert
Date: 2020-03-27T02:30:57-05:00
New Revision: b29322435abd9aa802ccc68a57f89cb068ff8526

URL: 
https://github.com/llvm/llvm-project/commit/b29322435abd9aa802ccc68a57f89cb068ff8526
DIFF: 
https://github.com/llvm/llvm-project/commit/b29322435abd9aa802ccc68a57f89cb068ff8526.diff

LOG: [OpenMP][NFC] Open `llvm` and `llvm::omp` namespace in OpenMPClause.cpp

Added: 


Modified: 
clang/lib/AST/OpenMPClause.cpp

Removed: 




diff  --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp
index fc7912d6fdca..dc74a952ccd3 100644
--- a/clang/lib/AST/OpenMPClause.cpp
+++ b/clang/lib/AST/OpenMPClause.cpp
@@ -24,6 +24,8 @@
 #include 
 
 using namespace clang;
+using namespace llvm;
+using namespace omp;
 
 OMPClause::child_range OMPClause::children() {
   switch (getClauseKind()) {
@@ -1296,7 +1298,7 @@ OMPExclusiveClause *OMPExclusiveClause::CreateEmpty(const 
ASTContext ,
 
 void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
   OS << "if(";
-  if (Node->getNameModifier() != llvm::omp::OMPD_unknown)
+  if (Node->getNameModifier() != OMPD_unknown)
 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
   Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
   OS << ")";
@@ -1867,24 +1869,24 @@ void 
OMPClausePrinter::VisitOMPExclusiveClause(OMPExclusiveClause *Node) {
 }
 
 void OMPTraitInfo::getAsVariantMatchInfo(
-ASTContext , llvm::omp::VariantMatchInfo ) const {
+ASTContext , VariantMatchInfo ) const {
   for (const OMPTraitSet  : Sets) {
 for (const OMPTraitSelector  : Set.Selectors) {
 
   // User conditions are special as we evaluate the condition here.
-  if (Selector.Kind == llvm::omp::TraitSelector::user_condition) {
+  if (Selector.Kind == TraitSelector::user_condition) {
 assert(Selector.ScoreOrCondition &&
"Ill-formed user condition, expected condition expression!");
 assert(Selector.Properties.size() == 1 &&
Selector.Properties.front().Kind ==
-   llvm::omp::TraitProperty::user_condition_unknown &&
+   TraitProperty::user_condition_unknown &&
"Ill-formed user condition, expected unknown trait property!");
 
 llvm::APInt CondVal =
 Selector.ScoreOrCondition->EvaluateKnownConstInt(ASTCtx);
 VMI.addTrait(CondVal.isNullValue()
- ? llvm::omp::TraitProperty::user_condition_false
- : llvm::omp::TraitProperty::user_condition_true);
+ ? TraitProperty::user_condition_false
+ : TraitProperty::user_condition_true);
 continue;
   }
 
@@ -1897,13 +1899,13 @@ void OMPTraitInfo::getAsVariantMatchInfo(
   for (const OMPTraitProperty  : Selector.Properties)
 VMI.addTrait(Set.Kind, Property.Kind, ScorePtr);
 
-  if (Set.Kind != llvm::omp::TraitSet::construct)
+  if (Set.Kind != TraitSet::construct)
 continue;
 
   // TODO: This might not hold once we implement SIMD properly.
   assert(Selector.Properties.size() == 1 &&
  Selector.Properties.front().Kind ==
- llvm::omp::getOpenMPContextTraitPropertyForSelector(
+ getOpenMPContextTraitPropertyForSelector(
  Selector.Kind) &&
  "Ill-formed construct selector!");
 
@@ -1919,25 +1921,25 @@ void OMPTraitInfo::print(llvm::raw_ostream ,
 if (!FirstSet)
   OS << ", ";
 FirstSet = false;
-OS << llvm::omp::getOpenMPContextTraitSetName(Set.Kind) << "={";
+OS << getOpenMPContextTraitSetName(Set.Kind) << "={";
 
 bool FirstSelector = true;
 for (const OMPTraitInfo::OMPTraitSelector  : Set.Selectors) {
   if (!FirstSelector)
 OS << ", ";
   FirstSelector = false;
-  OS << llvm::omp::getOpenMPContextTraitSelectorName(Selector.Kind);
+  OS << getOpenMPContextTraitSelectorName(Selector.Kind);
 
   bool AllowsTraitScore = false;
   bool RequiresProperty = false;
-  llvm::omp::isValidTraitSelectorForTraitSet(
+  isValidTraitSelectorForTraitSet(
   Selector.Kind, Set.Kind, AllowsTraitScore, RequiresProperty);
 
   if (!RequiresProperty)
 continue;
 
   OS << "(";
-  if (Selector.Kind == llvm::omp::TraitSelector::user_condition) {
+  if (Selector.Kind == TraitSelector::user_condition) {
 Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy);
   } else {
 
@@ -1953,7 +1955,7 @@ void OMPTraitInfo::print(llvm::raw_ostream ,
   if (!FirstProperty)
 OS << ", ";
   FirstProperty = false;
-  OS << llvm::omp::getOpenMPContextTraitPropertyName(Property.Kind);
+  OS << getOpenMPContextTraitPropertyName(Property.Kind);
 }
   }
   OS << ")";



___
cfe-commits 

[clang] 56d1553 - [OpenMP][NFC] Outline common functionality (skipUntilPragmaOpenMPEnd)

2020-03-27 Thread Johannes Doerfert via cfe-commits

Author: Johannes Doerfert
Date: 2020-03-27T02:30:57-05:00
New Revision: 56d1553dd2cfc60b62c6e898a1dde18e4d6ebc71

URL: 
https://github.com/llvm/llvm-project/commit/56d1553dd2cfc60b62c6e898a1dde18e4d6ebc71
DIFF: 
https://github.com/llvm/llvm-project/commit/56d1553dd2cfc60b62c6e898a1dde18e4d6ebc71.diff

LOG: [OpenMP][NFC] Outline common functionality (skipUntilPragmaOpenMPEnd)

The same code was repeated multiple times, we put it in a function now.

Added: 


Modified: 
clang/include/clang/Parse/Parser.h
clang/lib/Parse/ParseOpenMP.cpp

Removed: 




diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 8ba701c10c59..d0e2540938d6 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -2971,6 +2971,11 @@ class Parser : public CodeCompletionHandler {
   /// Parse '#pragma omp end declare target'.
   void ParseOMPEndDeclareTargetDirective(OpenMPDirectiveKind DKind,
  SourceLocation Loc);
+
+  /// Skip tokens until a `annot_pragma_openmp_end` was found. Emit a warning 
if
+  /// it is not the current token.
+  void skipUntilPragmaOpenMPEnd(OpenMPDirectiveKind DKind);
+
   /// Parses declarative OpenMP directives.
   DeclGroupPtrTy ParseOpenMPDeclarativeDirectiveWithExtDecl(
   AccessSpecifier , ParsedAttributesWithRange ,

diff  --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 7ae9885abe2b..d47051c9f594 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -796,13 +796,7 @@ Parser::ParseOMPDeclareSimdClauses(Parser::DeclGroupPtrTy 
Ptr,
   bool IsError =
   parseDeclareSimdClauses(*this, BS, Simdlen, Uniforms, Aligneds,
   Alignments, Linears, LinModifiers, Steps);
-  // Need to check for extra tokens.
-  if (Tok.isNot(tok::annot_pragma_openmp_end)) {
-Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
-<< getOpenMPDirectiveName(OMPD_declare_simd);
-while (Tok.isNot(tok::annot_pragma_openmp_end))
-  ConsumeAnyToken();
-  }
+  skipUntilPragmaOpenMPEnd(OMPD_declare_simd);
   // Skip the last annot_pragma_openmp_end.
   SourceLocation EndLoc = ConsumeAnnotationToken();
   if (IsError)
@@ -1524,6 +1518,18 @@ Parser::DeclGroupPtrTy 
Parser::ParseOMPDeclareTargetClauses() {
   return Actions.BuildDeclaratorGroup(Decls);
 }
 
+void Parser::skipUntilPragmaOpenMPEnd(OpenMPDirectiveKind DKind) {
+  // The last seen token is annot_pragma_openmp_end - need to check for
+  // extra tokens.
+  if (Tok.is(tok::annot_pragma_openmp_end))
+return;
+
+  Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
+  << getOpenMPDirectiveName(DKind);
+  while (Tok.isNot(tok::annot_pragma_openmp_end))
+ConsumeAnyToken();
+}
+
 void Parser::ParseOMPEndDeclareTargetDirective(OpenMPDirectiveKind DKind,
SourceLocation DTLoc) {
   if (DKind != OMPD_end_declare_target) {
@@ -1532,11 +1538,7 @@ void 
Parser::ParseOMPEndDeclareTargetDirective(OpenMPDirectiveKind DKind,
 return;
   }
   ConsumeAnyToken();
-  if (Tok.isNot(tok::annot_pragma_openmp_end)) {
-Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
-<< getOpenMPDirectiveName(OMPD_end_declare_target);
-SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
-  }
+  skipUntilPragmaOpenMPEnd(OMPD_end_declare_target);
   // Skip the last annot_pragma_openmp_end.
   ConsumeAnyToken();
 }
@@ -1616,13 +1618,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
 DeclDirectiveListParserHelper Helper(this, DKind);
 if (!ParseOpenMPSimpleVarList(DKind, Helper,
   /*AllowScopeSpecifier=*/true)) {
-  // The last seen token is annot_pragma_openmp_end - need to check for
-  // extra tokens.
-  if (Tok.isNot(tok::annot_pragma_openmp_end)) {
-Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
-<< getOpenMPDirectiveName(DKind);
-SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
-  }
+  skipUntilPragmaOpenMPEnd(DKind);
   // Skip the last annot_pragma_openmp_end.
   ConsumeAnnotationToken();
   return Actions.ActOnOpenMPThreadprivateDirective(Loc,
@@ -1661,13 +1657,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
 ConsumeToken();
   Actions.EndOpenMPClause();
 }
-// The last seen token is annot_pragma_openmp_end - need to check for
-// extra tokens.
-if (Tok.isNot(tok::annot_pragma_openmp_end)) {
-  Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
-  << getOpenMPDirectiveName(DKind);
-  SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
-}
+skipUntilPragmaOpenMPEnd(DKind);
   }
   // Skip the last annot_pragma_openmp_end.
   ConsumeAnnotationToken();

[PATCH] D66831: [ObjC] Fix type checking for qualified id block parameters.

2020-03-27 Thread ChatWyn via Phabricator via cfe-commits
chatwyn added a comment.

Hi:
we're in the process of testing with Clang 10 and noticed a behavior change 
caused by this commit.

Consider the following piece of code:

  @protocol P
  @end
  
  @protocol Q
  @end
  
  @interface I 
  @end
  
  void a() {
  void (^genericBlockWithParam)(id );
  void (^blockWithParam)(I *);
  blockWithParam = genericBlockWithParam;
  genericBlockWithParam = blockWithParam;
  }

when I use clang 9, it will be  below error

  incompatible block pointer types assigning to 'void (^__strong)(I *__strong)' 
from 'void (^__strong)(__strong id)'
  blockWithParam = genericBlockWithParam;
 ^ ~

but in clang 10, the error is that

  incompatible block pointer types assigning to 'void (^__strong)(__strong 
id)' from 'void (^__strong)(I *__strong)'
  genericBlockWithParam = blockWithParam;
 ^ ~

I think clang 9 is reasonable.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66831/new/

https://reviews.llvm.org/D66831



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


<    1   2