[PATCH] D98799: [UniqueLinkageName] Use consistent checks when mangling symbo linkage name and debug linkage name.

2021-05-25 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D98799#2761684 , @dblaikie wrote:

> OK - poked around a bit more to better understand this, so attempting to 
> summarize my current understanding (excuse the repetition from previous parts 
> of this thread) and results.
>
> - `__attribute__((overloadable))` can/does mangle K&R C style declarations 
> 
> - with this patch (currently committed), `-funique-internal-linkage-names` 
> does not mangle K&R C style declarations (see `bar` in the included test 
> case, unmangled)
> - I'd like to avoid that divergence if possible
> - Changing the debug info code to be more generous with names it mangles (by 
> using `FD->getType()->getAs()` rather than 
> `hasPrototype()`) causes problems
>   - Specifically: Objective C blocks (which have a `FunctionProtoType` type, 
> but `!hasPrototype` it seems) are missing parameter info so this 
> 
>  call crashes
> - There doesn't seem to be any way to test for this property of the 
> `FunctionDecl` that I can see - where it has a type, but doesn't have 
> parameter info
>
> Trying to pull in some folks who might know what's going on here/be able to 
> suggest a way to split these cases if needed, or fix the block 
> `FunctionDecl`s to have param info. @rjmccall @JDevlieghere - I'd really 
> appreciate some help here.

Unlike lambdas, `BlockDecl` is not a subclass of `FunctionDecl`, so I'm not 
quite sure what you're asking — there shouldn't be a way for that line to crash 
on a `BlockDecl` because `FD` should be null.

Not sure what you mean by block `FunctionDecl` — a block doesn't make a 
`FunctionDecl`.  If it's useful for `BlockDecl` to return


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98799

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


[PATCH] D102478: [Matrix] Emit assumption that matrix indices are valid.

2021-05-25 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Do you want to generate these even at -O0?




Comment at: llvm/include/llvm/IR/MatrixBuilder.h:242
+auto *Cmp = B.CreateICmpULT(Idx, NumElts);
+if (!isa(Cmp)) {
+  Function *TheFn =

xbolva00 wrote:
> Prefer early exit?
Should this do something special if the index is statically out of bounds?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102478

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


[PATCH] D103112: Reimplement __builtin_unique_stable_name-

2021-05-25 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:2413
+(or type of the expression) that is stable across split compilations, mainly to
+support SYCL/Data Parallel C++ language.
+

The semantics here seem specific to SYCL.  In fact, if this feature were used 
in normal code, it would arguably be weird that it changed behavior 
significantly in SYCL.  I think we should just acknowledge that and make it a 
feature that's only enabled when SYCL is enabled.  That probably also means 
renaming it to `__builtin_sycl_unique_stable_name`.



Comment at: clang/include/clang/AST/Expr.h:2045
+// representation of the type (or type of the expression) in a way that permits
+// us to properly encode information about the SYCL kernels.
+class UniqueStableNameExpr final

Since this is really just for internal use in system headers (right?), is there 
a need for it to be as flexible as this about whether it takes an expression or 
a type?



Comment at: clang/include/clang/Serialization/ASTBitCodes.h:1965
+  // UniqueStableNameExpr
+  EXPR_UNIQUESTABLENAME,
 };

UniQuestableName :)

Probably ought to use underscores here.



Comment at: clang/lib/AST/ASTContext.cpp:11662
+
+void ASTContext::AddSYCLKernelNamingDecl(const CXXRecordDecl *RD) {
+  RD = RD->getCanonicalDecl();

Can we assert that these methods are only called in SYCL?  I'd hate to 
accidentally do this bookkeeping in other modes.



Comment at: clang/lib/AST/ItaniumMangle.cpp:1977
+  if (Context.getShouldCallKernelCallback()(Context.getASTContext(), Lambda)) {
+Context.getKernelMangleCallback()(Context.getASTContext(), Lambda, Out);
+Out << '_';

This basically assumes that the callback is only changing the discriminator.  
And in fact, we already have this "device lambda mangling number" concept that 
we use in different modes with similar problems to SYCL.  Can we unify these 
and just provide one way for the context to opt in to overriding discriminators?



Comment at: clang/lib/AST/ItaniumMangle.cpp:5056
+
+Out << "u20__unique_stable_name";
+if (USN->isExpr()) {

The expectation is that these names match the spelling in the source, so this 
should include the `__builtin` prefix.


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

https://reviews.llvm.org/D103112

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


[PATCH] D103131: support debug info for alias variable

2021-05-25 Thread Umesh Kalappa via Phabricator via cfe-commits
umesh.kalappa0 added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:4948
 
+void CGDebugInfo::EmitGlobalAlias(llvm::GlobalAlias *Var, const VarDecl *D) {
+  if (!CGM.getCodeGenOpts().hasReducedDebugInfo())

Var is never used in the EmitGlobalAlias ,we don't need the same.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:4929
+if (CGDebugInfo *DI = getModuleDebugInfo())
+  if (getCodeGenOpts().hasReducedDebugInfo())
+DI->EmitGlobalAlias(GA, VD);

this should be other way right  i.e if(!getCodeGenOpts().hasReducedDebugInfo())


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103131

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


[PATCH] D102996: [ObjC][ARC] Use the addresses of the ARC runtime functions instead of integer 0/1 for the operand of bundle "clang.arc.attachedcall"

2021-05-25 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102996

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


[PATCH] D102443: [PowerPC] Added multiple PowerPC builtins

2021-05-25 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Alright, that's fine with me, too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102443

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


[PATCH] D96418: [clang] Refactor mustprogress handling, add it to all loops in c++11+.

2021-05-25 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D96418#2780687 , @leonardchan wrote:

> Hi all, it looks like this commit led to some unexpected behavior in our 
> build. When compiling something like:
>
>   // clang++ -c -S -o - /tmp/test.cc -std=c++17 -O1
>   static int do_nothing(void* unused) {
> for (;;) {
> }
> return 0;
>   }
>   
>   typedef int (*func_t)(void *);
>   void call(func_t);
>   
>   void func() {
> call(&do_nothing);
>   }
>
> we get the following assembly for `do_nothing`:
>
>   .p2align4, 0x90 # -- Begin function 
> _ZL10do_nothingPv
>   .type   _ZL10do_nothingPv,@function
>   _ZL10do_nothingPv:  # @_ZL10do_nothingPv
>   .cfi_startproc
>   # %bb.0:
>   .Lfunc_end1:
>   .size   _ZL10do_nothingPv, .Lfunc_end1-_ZL10do_nothingPv
>   .cfi_endproc
>   # -- End function
>   .ident  "Fuchsia clang version 13.0.0 
> (https://llvm.googlesource.com/a/llvm-project 
> 6555e53ab0f2bca3dc30f5ab3a2d6872d50b6ff8)"
>   .section".note.GNU-stack","",@progbits
>   .addrsig
>   .addrsig_sym _ZL10do_nothingPv
>
> It seems that the function doesn't have a return statement or halting 
> instruction and it would just jump into the next function. While I do follow 
> what this patch is trying to do, this behavior seems pretty unexpected from a 
> C++ user perspective. I could be wrong, but it doesn't seem clear in this 
> case that the infinite loop results in UB which would justify this assembly.

Well, no, I'm afraid it is actually clear that that code does have UB according 
to the C++ standard.  Perhaps you mean that it *shouldn't* have UB, or that 
Clang should define its behavior despite the standard.

I might agree with you that I don't see the value in using this stronger rule 
in C++, but I think it would help to understand the problem a little better.  I 
assume this is causing problems for a less trivial test case?  Or do you really 
have code that's relying on that loop not terminating?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96418

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


[clang] 9ef66ed - [clang-format][NFC] correctly sort StatementAttributeLike-macros' IO.map

2021-05-25 Thread Björn Schäpers via cfe-commits

Author: Björn Schäpers
Date: 2021-05-26T07:59:08+02:00
New Revision: 9ef66ed43758a575e1f53a09f07ecb7e3025aafa

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

LOG: [clang-format][NFC] correctly sort StatementAttributeLike-macros' IO.map

Added: 


Modified: 
clang/lib/Format/Format.cpp

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index f1508b98653d7..c50786c9d2f7a 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -616,8 +616,6 @@ template <> struct MappingTraits {
Style.ExperimentalAutoDetectBinPacking);
 IO.mapOptional("FixNamespaceComments", Style.FixNamespaceComments);
 IO.mapOptional("ForEachMacros", Style.ForEachMacros);
-IO.mapOptional("StatementAttributeLikeMacros",
-   Style.StatementAttributeLikeMacros);
 IO.mapOptional("IncludeBlocks", Style.IncludeStyle.IncludeBlocks);
 IO.mapOptional("IncludeCategories", Style.IncludeStyle.IncludeCategories);
 IO.mapOptional("IncludeIsMainRegex", 
Style.IncludeStyle.IncludeIsMainRegex);
@@ -709,6 +707,8 @@ template <> struct MappingTraits {
Style.SpaceBeforeSquareBrackets);
 IO.mapOptional("BitFieldColonSpacing", Style.BitFieldColonSpacing);
 IO.mapOptional("Standard", Style.Standard);
+IO.mapOptional("StatementAttributeLikeMacros",
+   Style.StatementAttributeLikeMacros);
 IO.mapOptional("StatementMacros", Style.StatementMacros);
 IO.mapOptional("TabWidth", Style.TabWidth);
 IO.mapOptional("TypenameMacros", Style.TypenameMacros);



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


[PATCH] D102465: [Coroutines] Mark every parameter

2021-05-25 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

If it would take times to mark parameter passed by value only, I think we could 
proceed with this one first. We can try to optimize it later. After all, 
correctness is most important.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102465

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


[PATCH] D96418: [clang] Refactor mustprogress handling, add it to all loops in c++11+.

2021-05-25 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

>> Would it be fine to revert this for now to work out the kinks?

I dont think. This is a known problem, not caused by this patch, just exposed. 
You can search bugzilla for it, simply, if there is an UB, llvm should emit a 
“ret”.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96418

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


[PATCH] D102995: errorUnsupported should be non-fatal

2021-05-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

X86-64 ABI requires float/double arguments to use XMM registers. All x86-64 
CPUs have SSE2.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102995

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


[PATCH] D103131: support debug info for alias variable

2021-05-25 Thread kamlesh kumar via Phabricator via cfe-commits
kamleshbhalui added a comment.

In D103131#2780997 , @dblaikie wrote:

> Looks like GCC emits aliases as a `DW_TAG_variable` without a location, not 
> as a `DW_TAG_imported_declaration` - what gave you the inspiration to do it 
> in this way? (I think it's probably good, but DWARF doesn't lend itself to 
> novelty so much... can be good to stick with how other folks already do 
> things since it'll be what consumers already know how to handle)
>
> How's this work if the alias target isn't declared in the source - but in 
> inline assembly instead? (I guess GCC probably handles that OK, but the Clang 
> strategy here might not cope with it)



> what gave you the inspiration to do it in this way?

Actually, I got the idea from the discussion in the defect.

> How's this work if the alias target isn't declared in the source

gcc spec says that alias target has to be in the same source.
https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
it would be great if you share an example if I misunderstood you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103131

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


[PATCH] D103131: support debug info for alias variable

2021-05-25 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Looks like GCC emits aliases as a `DW_TAG_variable` without a location, not as 
a `DW_TAG_imported_declaration` - what gave you the inspiration to do it in 
this way? (I think it's probably good, but DWARF doesn't lend itself to novelty 
so much... can be good to stick with how other folks already do things since 
it'll be what consumers already know how to handle)

How's this work if the alias target isn't declared in the source - but in 
inline assembly instead? (I guess GCC probably handles that OK, but the Clang 
strategy here might not cope with it)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103131

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


[PATCH] D102995: errorUnsupported should be non-fatal

2021-05-25 Thread MJ via Phabricator via cfe-commits
majiang31312 added a comment.

In D102995#2778674 , @craig.topper 
wrote:

> "fatal" in the comment means don't diagnose any additional errors and 
> immediately stop. We attempt to recover to detect more errors, but the 
> emitted binary code is likely incorrect. I don't think we can just emit a 
> warning.
>
> The function name says "error" in its name, it should be an error.

Thanks for the explanations, it's reasonable now. 
Although “SSE register return with SSE disabled” seems strange as the code did 
not use SSE directly, it's another problem.  I'll close this one now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102995

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


[PATCH] D103131: support debug info for alias variable

2021-05-25 Thread kamlesh kumar via Phabricator via cfe-commits
kamleshbhalui created this revision.
kamleshbhalui added reviewers: dblaikie, aprantl, probinson.
kamleshbhalui added a project: LLVM.
Herald added a subscriber: jeroen.dobbelaere.
kamleshbhalui requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

consider below test demonstration
$cat test.c
int oldname = 1;
extern int newname __attribute__((alias("oldname")));

$clang -g -O0 test.c

$gdb a.out
(gdb) pt oldname
type = int
(gdb) pt newname
type = 
(gdb) p newname
'newname' has unknown type; cast it to its declared type

debugger is unable to print newname types and value because clang does not emit 
debug info for newname.
This patch supports having debug info for alias variable as imported entity.

Fixes PR50052.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103131

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/debug-info-alias.c


Index: clang/test/CodeGen/debug-info-alias.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-alias.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple 
x86_64-linux-unknown %s -o - | FileCheck %s
+
+// CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, scope:{{.*}}, 
entity: ![[VAR:[0-9]+]]
+// CHECK: ![[VAR]] = !DIGlobalVariable(name: "newname"
+
+int oldname = 1;
+extern int newname __attribute__((alias("oldname")));
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4922,6 +4922,13 @@
   setTLSMode(GA, *VD);
 
   SetCommonAttributes(GD, GA);
+
+  // Emit global alias debug information.
+  if (const auto *VD = dyn_cast(D)) {
+if (CGDebugInfo *DI = getModuleDebugInfo())
+  if (getCodeGenOpts().hasReducedDebugInfo())
+DI->EmitGlobalAlias(GA, VD);
+  }
 }
 
 void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -493,6 +493,9 @@
   /// Emit information about an external variable.
   void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
 
+  /// Emit information about global alias.
+  void EmitGlobalAlias(llvm::GlobalAlias *GA, const VarDecl *Decl);
+
   /// Emit C++ using directive.
   void EmitUsingDirective(const UsingDirectiveDecl &UD);
 
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4945,6 +4945,19 @@
   Var->addDebugInfo(GVE);
 }
 
+void CGDebugInfo::EmitGlobalAlias(llvm::GlobalAlias *Var, const VarDecl *D) {
+  if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
+return;
+
+  llvm::DIFile *Unit = getOrCreateFile(D->getLocation());
+  llvm::DIScope *DContext = getDeclContextDescriptor(D);
+  if (llvm::DINode *Target = getDeclarationOrDefinition(D)) {
+auto Loc = D->getLocation();
+DBuilder.createImportedDeclaration(DContext, Target, Unit,
+   getLineNumber(Loc));
+  }
+}
+
 llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(const Decl *D) {
   if (!LexicalBlockStack.empty())
 return LexicalBlockStack.back();


Index: clang/test/CodeGen/debug-info-alias.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-alias.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple x86_64-linux-unknown %s -o - | FileCheck %s
+
+// CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, scope:{{.*}}, entity: ![[VAR:[0-9]+]]
+// CHECK: ![[VAR]] = !DIGlobalVariable(name: "newname"
+
+int oldname = 1;
+extern int newname __attribute__((alias("oldname")));
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4922,6 +4922,13 @@
   setTLSMode(GA, *VD);
 
   SetCommonAttributes(GD, GA);
+
+  // Emit global alias debug information.
+  if (const auto *VD = dyn_cast(D)) {
+if (CGDebugInfo *DI = getModuleDebugInfo())
+  if (getCodeGenOpts().hasReducedDebugInfo())
+DI->EmitGlobalAlias(GA, VD);
+  }
 }
 
 void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -493,6 +493,9 @@
   /// Emit information about an external variable.
   void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
 
+  /// Emit information about global alias.
+  vo

[PATCH] D99903: [Clang][Sema] better -Wcast-function-type diagnose for pointer parameters and parameters with cv-qualifiers

2021-05-25 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99903

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


[PATCH] D102531: PR45881: Properly use CXXThisOverride for templated lambda

2021-05-25 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

ping...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102531

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


[PATCH] D102543: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2021-05-25 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 347814.
hctim marked an inline comment as done.
hctim added a comment.

Address Vitaly's suggestions, make some slight changes so that 
cross-compilation and running under QEMU doesn't require staging the runtimes 
in the host compiler.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102543

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo_standalone.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo_standalone.so
  clang/test/Driver/fuchsia.c
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp
  compiler-rt/test/scudo/CMakeLists.txt
  compiler-rt/test/scudo/aligned-new.cpp
  compiler-rt/test/scudo/alignment.c
  compiler-rt/test/scudo/dealloc-race.c
  compiler-rt/test/scudo/double-free.cpp
  compiler-rt/test/scudo/fsanitize.c
  compiler-rt/test/scudo/interface.cpp
  compiler-rt/test/scudo/lit.cfg.py
  compiler-rt/test/scudo/lit.site.cfg.py.in
  compiler-rt/test/scudo/malloc.cpp
  compiler-rt/test/scudo/memalign.c
  compiler-rt/test/scudo/mismatch.cpp
  compiler-rt/test/scudo/options.cpp
  compiler-rt/test/scudo/overflow.c
  compiler-rt/test/scudo/preinit.c
  compiler-rt/test/scudo/preload.cpp
  compiler-rt/test/scudo/quarantine.c
  compiler-rt/test/scudo/random_shuffle.cpp
  compiler-rt/test/scudo/realloc.cpp
  compiler-rt/test/scudo/rss.c
  compiler-rt/test/scudo/secondary.c
  compiler-rt/test/scudo/sized-delete.cpp
  compiler-rt/test/scudo/sizes.cpp
  compiler-rt/test/scudo/standalone/CMakeLists.txt
  compiler-rt/test/scudo/standalone/aligned-new.cpp
  compiler-rt/test/scudo/standalone/alignment.c
  compiler-rt/test/scudo/standalone/dealloc-race.c
  compiler-rt/test/scudo/standalone/double-free.cpp
  compiler-rt/test/scudo/standalone/fsanitize.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/overflow.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/quarantine.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/realloc.cpp
  compiler-rt/test/scudo/standalone/lit-unmigrated/rss.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/secondary.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/sizes.cpp
  compiler-rt/test/scudo/standalone/lit-unmigrated/threads.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/valloc.c
  compiler-rt/test/scudo/standalone/lit.cfg.py
  compiler-rt/test/scudo/standalone/lit.site.cfg.py.in
  compiler-rt/test/scudo/standalone/malloc.cpp
  compiler-rt/test/scudo/standalone/memalign.c
  compiler-rt/test/scudo/standalone/mismatch.cpp
  compiler-rt/test/scudo/standalone/options.cpp
  compiler-rt/test/scudo/standalone/preinit.c
  compiler-rt/test/scudo/standalone/preload.cpp
  compiler-rt/test/scudo/standalone/random_shuffle.cpp
  compiler-rt/test/scudo/standalone/sized-delete.cpp
  compiler-rt/test/scudo/standalone/stats.c
  compiler-rt/test/scudo/standalone/tsd_destruction.c
  compiler-rt/test/scudo/stats.c
  compiler-rt/test/scudo/symbols.test
  compiler-rt/test/scudo/threads.c
  compiler-rt/test/scudo/tsd_destruction.c
  compiler-rt/test/scudo/valloc.c

Index: compiler-rt/test/scudo/symbols.test
===
--- compiler-rt/test/scudo/symbols.test
+++ /dev/null
@@ -1,8 +0,0 @@
-UNSUPPORTED: android
-
-Verify that various functions are *not* present in the minimal binary. Presence
-of those symbols in the minimal runtime would mean that the split code made it
-back into the core Sanitizer runtime library.
-
-RUN: nm %shared_minlibscudo | not grep Symbolizer
-RUN: nm %shared_minlibscudo | not grep Coverage
Index: compiler-rt/test/scudo/tsd_destruction.c
===
--- /dev/null
+++ compiler-rt/test/scudo/tsd_destruction.c
@@ -1,43 +0,0 @@
-// RUN: %clang_scudo %s -o %t
-// RUN: %run %t 2>&1
-
-#include 
-#include 
-#include 
-#include 
-#include 
-
-// Some of glibc's own thread local data is destroyed after a user's thread
-// local destructors are called, via __libc_thread_freeres. This might involve
-// calling free, as is the case for strerror_thread_freeres.
-// If there is no prior heap operation in the thread, this free would end up
-// initializing some thread specific data that would never be destroyed
-// properly, while still being deallocated when the TLS goes away. As a result,
-// a program could SEGV, usually in
-// __sanitizer::AllocatorGlobalStats::Unregister, where one of the doubly
-// linked list links would refer to a now unmapped memory area.
-
-// This test reproduces those circumstances. Succ

[PATCH] D102543: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2021-05-25 Thread Mitch Phillips via Phabricator via cfe-commits
hctim marked 2 inline comments as done.
hctim added inline comments.



Comment at: compiler-rt/test/scudo/standalone/CMakeLists.txt:13-14
+  string(TOLOWER "-${arch}" SCUDO_STANDALONE_TEST_CONFIG_SUFFIX)
+  get_test_cc_for_arch(${arch} SCUDO_STANDALONE_TEST_TARGET_CC
+   SCUDO_STANDALONE_TEST_TARGET_CFLAGS)
+  string(TOUPPER ${arch} ARCH_UPPER_CASE)

vitalybuka wrote:
> This places breaks ppc build and I don't understand why we need it
Yeah, `get_test_cc_for_arch` looks wrong to me. But we do still need one of its 
children, `get_target_flags_for_arch`, otherwise host cross-compile (from amd64 
-> i386) fails.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102543

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


[PATCH] D103112: Reimplement __builtin_unique_stable_name-

2021-05-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 347805.
erichkeane added a comment.

Apply the clang-format patch from CI, also apply the unused variable fix 
clang-tidy suggested.  The rest of the issues in clang-tidy are identifying 
functions in a recursive call-chain, but they are all part of the various 
visitors, so I don't think I have a way to fix those.


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

https://reviews.llvm.org/D103112

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ComputeDependence.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/Mangle.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaSYCL.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/CodeGenSYCL/unique_stable_name.cpp
  clang/test/ParserSYCL/unique_stable_name.cpp
  clang/test/SemaSYCL/unique_stable_name.cpp
  clang/tools/libclang/CXCursor.cpp

Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -336,6 +336,7 @@
   case Stmt::ObjCBoxedExprClass:
   case Stmt::ObjCSubscriptRefExprClass:
   case Stmt::RecoveryExprClass:
+  case Stmt::UniqueStableNameExprClass:
 K = CXCursor_UnexposedExpr;
 break;
 
Index: clang/test/SemaSYCL/unique_stable_name.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/unique_stable_name.cpp
@@ -0,0 +1,208 @@
+// RUN: %clang_cc1 %s -std=c++17 -triple x86_64-pc-windows-msvc -fsycl-is-device -verify -fsyntax-only -Wno-unused
+// RUN: %clang_cc1 %s -std=c++17 -triple x86_64-linux-gnu -fsycl-is-device -verify -fsyntax-only -Wno-unused
+
+template 
+[[clang::sycl_kernel]] void kernel_single_task(KernelType kernelFunc) { // #kernelSingleTask
+  kernelFunc();
+}
+
+// kernel1 - expect error
+// The current function is named with a lambda (i.e., takes a lambda as a
+// template parameter. Call the builtin on the current function then it is
+// passed to a kernel. Test that passing the given function to the unique
+// stable name builtin and then to the kernel throws an error because the
+// latter causes its name mangling to change.
+template 
+void kernel1func(const Func &F1) {
+  constexpr const char *F1_output = __builtin_unique_stable_name(F1); // #USN_F1
+  // expected-error@#kernelSingleTask{{kernel instantiation changes the result of an evaluated '__builtin_unique_stable_name'}}
+  // expected-note@#kernel1func_call{{in instantiation of function template specialization}}
+  // expected-note@#USN_F1{{'__builtin_unique_stable_name' evaluated here}}
+  // expected-note@+1{{in instantiation of function template specialization}}
+  kernel_single_task(F1); // #kernel1_call
+}
+
+void callkernel1() {
+  kernel1func([]() {}); // #kernel1func_call
+}
+
+// kernel2 - expect error
+// The current function is named with a lambda (i.e., takes a lambda as a
+// template parameter). Call the builtin on the given function,
+// then an empty lambda is passed to kernel.
+// Test that passing the given function to the unique stable name builtin and
+// then passing a different lambda to the kernel still throws an error because
+// the calling context is part of naming the kernel. Even though the given
+// function (F2) is not passed to the kernel, its mangling changes due to
+// kernel call with the unrelated lambda.
+template 
+void kernel2func(const Func &F2) {
+  constexpr const char *F2_output = __builtin_unique_stable_name(F2); // #USN_F2
+  // expected-error@#kernelSingleTask{{kernel instantiation changes the result of an evaluated '__builtin_unique_stable_name'}}
+  // expected-note@#kernel2func_call{{in instantiation of function template specialization}}
+  // expected-note@#USN_F2{{'__builtin_unique_stable_name' evaluated here}}
+  // expected-note@+1{{in instanti

[PATCH] D102736: Fix tmp files being left on Windows builds.

2021-05-25 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 347802.
akhuang marked 5 inline comments as done.
akhuang added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102736

Files:
  clang/include/clang/Frontend/CompilerInstance.h
  clang/lib/Frontend/CompilerInstance.cpp
  llvm/lib/Support/Path.cpp
  llvm/lib/Support/Windows/Path.inc

Index: llvm/lib/Support/Windows/Path.inc
===
--- llvm/lib/Support/Windows/Path.inc
+++ llvm/lib/Support/Windows/Path.inc
@@ -560,11 +560,6 @@
   return errc::permission_denied;
 }
 
-static std::error_code rename_fd(int FromFD, const Twine &To) {
-  HANDLE FromHandle = reinterpret_cast(_get_osfhandle(FromFD));
-  return rename_handle(FromHandle, To);
-}
-
 std::error_code rename(const Twine &From, const Twine &To) {
   // Convert to utf-16.
   SmallVector WideFrom;
Index: llvm/lib/Support/Path.cpp
===
--- llvm/lib/Support/Path.cpp
+++ llvm/lib/Support/Path.cpp
@@ -1229,7 +1229,7 @@
   auto H = reinterpret_cast(_get_osfhandle(FD));
   std::error_code RenameEC = setDeleteDisposition(H, false);
   if (!RenameEC) {
-RenameEC = rename_fd(FD, Name);
+RenameEC = rename_handle(H, Name);
 // If rename failed because it's cross-device, copy instead
 if (RenameEC ==
   std::error_code(ERROR_NOT_SAME_DEVICE, std::system_category())) {
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -703,31 +703,37 @@
 // Output Files
 
 void CompilerInstance::clearOutputFiles(bool EraseFiles) {
+  // Ignore errors that occur when trying to discard the temp file.
   for (OutputFile &OF : OutputFiles) {
 if (EraseFiles) {
-  if (!OF.TempFilename.empty()) {
-llvm::sys::fs::remove(OF.TempFilename);
-continue;
-  }
+  if (OF.File)
+consumeError(OF.File->discard());
   if (!OF.Filename.empty())
 llvm::sys::fs::remove(OF.Filename);
   continue;
 }
 
-if (OF.TempFilename.empty())
+if (!OF.File)
   continue;
 
+if (OF.File->TmpName.empty()) {
+  consumeError(OF.File->discard());
+  continue;
+}
+
 // If '-working-directory' was passed, the output filename should be
 // relative to that.
 SmallString<128> NewOutFile(OF.Filename);
 FileMgr->FixupRelativePath(NewOutFile);
-std::error_code EC = llvm::sys::fs::rename(OF.TempFilename, NewOutFile);
-if (!EC)
+
+llvm::Error E = OF.File->keep(NewOutFile);
+if (!E)
   continue;
+
 getDiagnostics().Report(diag::err_unable_to_rename_temp)
-<< OF.TempFilename << OF.Filename << EC.message();
+<< OF.File->TmpName << OF.Filename << std::move(E);
 
-llvm::sys::fs::remove(OF.TempFilename);
+llvm::sys::fs::remove(OF.File->TmpName);
   }
   OutputFiles.clear();
   if (DeleteBuiltModules) {
@@ -809,7 +815,7 @@
 }
   }
 
-  std::string TempFile;
+  Optional Temp;
   if (UseTemporary) {
 // Create a temporary file.
 // Insert - before the extension (if any), and because some tools
@@ -821,25 +827,36 @@
 TempPath += "-";
 TempPath += OutputExtension;
 TempPath += ".tmp";
-int fd;
-std::error_code EC = llvm::sys::fs::createUniqueFile(
-TempPath, fd, TempPath,
-Binary ? llvm::sys::fs::OF_None : llvm::sys::fs::OF_Text);
-
-if (CreateMissingDirectories &&
-EC == llvm::errc::no_such_file_or_directory) {
-  StringRef Parent = llvm::sys::path::parent_path(OutputPath);
-  EC = llvm::sys::fs::create_directories(Parent);
-  if (!EC) {
-EC = llvm::sys::fs::createUniqueFile(TempPath, fd, TempPath,
- Binary ? llvm::sys::fs::OF_None
-: llvm::sys::fs::OF_Text);
-  }
-}
+Expected ExpectedFile =
+llvm::sys::fs::TempFile::create(TempPath);
+
+llvm::Error E = handleErrors(
+ExpectedFile.takeError(), [&](const llvm::ECError &E) -> llvm::Error {
+  std::error_code EC = E.convertToErrorCode();
+  if (CreateMissingDirectories &&
+  EC == llvm::errc::no_such_file_or_directory) {
+StringRef Parent = llvm::sys::path::parent_path(OutputPath);
+EC = llvm::sys::fs::create_directories(Parent);
+if (!EC) {
+  ExpectedFile = llvm::sys::fs::TempFile::create(TempPath);
+  if (!ExpectedFile)
+return llvm::errorCodeToError(
+llvm::errc::no_such_file_or_directory);
+}
+  }
+  return llvm::errorCodeToError(EC);
+});
+
+if (E) {
+  consumeError(std::move(E));
+} else {
+  Temp = std::m

[PATCH] D96418: [clang] Refactor mustprogress handling, add it to all loops in c++11+.

2021-05-25 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

Hi all, it looks like this commit led to some unexpected behavior in our build. 
When compiling something like:

  // clang++ -c -S -o - /tmp/test.cc -std=c++17 -O1
  static int do_nothing(void* unused) {
for (;;) {
}
return 0;
  }
  
  typedef int (*func_t)(void *);
  void call(func_t);
  
  void func() {
call(&do_nothing);
  }

we get the following assembly for `do_nothing`:

.p2align4, 0x90 # -- Begin function 
_ZL10do_nothingPv
.type   _ZL10do_nothingPv,@function
  _ZL10do_nothingPv:  # @_ZL10do_nothingPv
.cfi_startproc
  # %bb.0:
  .Lfunc_end1:
.size   _ZL10do_nothingPv, .Lfunc_end1-_ZL10do_nothingPv
.cfi_endproc
  # -- End function
.ident  "Fuchsia clang version 13.0.0 
(https://llvm.googlesource.com/a/llvm-project 
6555e53ab0f2bca3dc30f5ab3a2d6872d50b6ff8)"
.section".note.GNU-stack","",@progbits
.addrsig
.addrsig_sym _ZL10do_nothingPv

It seems that the function doesn't have a return statement or halting 
instruction and it would just jump into the next function. While I do follow 
what this patch is trying to do, this behavior seems pretty unexpected from a 
C++ user perspective. I could be wrong, but it doesn't seem clear in this case 
that the infinite loop results in UB which would justify this assembly. Would 
it be fine to revert this for now to work out the kinks?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96418

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


[PATCH] D102736: Fix tmp files being left on Windows builds.

2021-05-25 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Nice, this seems to be working out.




Comment at: clang/include/clang/Frontend/CompilerInstance.h:170
 std::string TempFilename;
+Optional TempFile;
 

aganea wrote:
> Can we always use `TempFile`? And remove `TempFilename` in that case?
Having a field and type both named `TempFile` is setting off my portability 
alarms. I think some old versions of GCC don't like this. Maybe the field can 
be called `Temporary`? `TemporaryFile`? I dono.



Comment at: clang/lib/Frontend/CompilerInstance.cpp:708-709
+  if (OF.TempFile) {
+if (llvm::Error E = OF.TempFile->discard())
+  consumeError(std::move(E));
   }

Can this be `consumeError(OF.TempFile->discard())`?

I find `consumeError` hard to read, I wish it were `ignoreErrors` or something 
like that. Short of that, please add a comment at the top of this function that 
we ignore any errors about failing to remove files.



Comment at: clang/lib/Frontend/CompilerInstance.cpp:720-721
+if (OF.TempFile->TmpName.empty()) {
+  if (llvm::Error E = OF.TempFile->discard())
+consumeError(std::move(E));
   continue;

Ditto re consumeError simplification



Comment at: clang/lib/Frontend/CompilerInstance.cpp:730
+
+std::string ErrorMsg;
+llvm::Error E = OF.TempFile->keep(NewOutFile);

`ErrorMsg` seems unused now



Comment at: clang/lib/Frontend/CompilerInstance.cpp:736
 getDiagnostics().Report(diag::err_unable_to_rename_temp)
-<< OF.TempFilename << OF.Filename << EC.message();
+<< OF.TempFile->TmpName << OF.Filename << toString(std::move(E));
 

Can you skip the toString and just do `<< std::move(E)`? I see an operator<< 
overload for it:
https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/Diagnostic.h#L1518



Comment at: llvm/lib/Support/Path.cpp:1264
   FD = -1;
-
   return errorCodeToError(RenameEC);

Please revert unrelated whitespace changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102736

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


[PATCH] D102443: [PowerPC] Added multiple PowerPC builtins

2021-05-25 Thread Quinn Pham via Phabricator via cfe-commits
quinnp updated this revision to Diff 34.
quinnp added a comment.

This update is motivated by comments made by @nemanjai. All of the builtin 
names have been changed to follow the convention of __builtin__. To 
fulfill the original goal of compatibility with the XL compiler, macros have 
been added to map __ to __builtin_ppc_.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102443

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/test/CodeGen/builtins-ppc-xlcompat-sync.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
  llvm/lib/Target/PowerPC/PPCInstrInfo.td
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-msync.ll
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-sync.ll
  llvm/test/CodeGen/PowerPC/eieio.ll

Index: llvm/test/CodeGen/PowerPC/eieio.ll
===
--- llvm/test/CodeGen/PowerPC/eieio.ll
+++ llvm/test/CodeGen/PowerPC/eieio.ll
@@ -4,7 +4,9 @@
 
 define void @eieio_test() {
 ; CHECK-LABEL: @eieio_test
-; CHECK: eieio
+; CHECK: ori r2, r2, 0
+; CHECK-NEXT: ori r2, r2, 0
+; CHECK-NEXT: eieio
 ; CHECK-NEXT: blr
 
 entry:
Index: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-sync.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-sync.ll
@@ -0,0 +1,74 @@
+; RUN: llc -verify-machineinstrs -mtriple=powerpcle-unknown-linux-gnu \
+; RUN: -mcpu=pwr8 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-linux-gnu \
+; RUN: -mcpu=pwr8 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN: -mcpu=pwr8 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
+; RUN: -mcpu=pwr8 < %s | FileCheck %s
+
+define dso_local void @test_builtin_ppc_eieio() #0 {
+; CHECK-LABEL: test_builtin_ppc_eieio
+
+entry:
+  call void @llvm.ppc.eieio()
+; CHECK: ori 2, 2, 0
+; CHECK-NEXT: ori 2, 2, 0
+; CHECK-NEXT: eieio
+ 
+  ret void
+}
+
+declare void @llvm.ppc.eieio() #2
+
+define dso_local void @test_builtin_ppc_iospace_eieio() #0 {
+; CHECK-LABEL: test_builtin_ppc_iospace_eieio
+
+entry:
+  call void @llvm.ppc.iospace.eieio()
+; CHECK: ori 2, 2, 0
+; CHECK-NEXT: ori 2, 2, 0
+; CHECK-NEXT: eieio
+ 
+  ret void
+}
+
+declare void @llvm.ppc.iospace.eieio() #2
+
+define dso_local void @test_builtin_ppc_iospace_lwsync() #0 {
+; CHECK-LABEL: test_builtin_ppc_iospace_lwsync
+
+entry:
+  call void @llvm.ppc.iospace.lwsync()
+; CHECK: lwsync
+
+  ret void
+}
+
+declare void @llvm.ppc.iospace.lwsync() #2
+
+define dso_local void @test_builtin_ppc_iospace_sync() #0 {
+; CHECK-LABEL: test_builtin_ppc_iospace_sync
+
+entry:
+  call void @llvm.ppc.iospace.sync()
+; CHECK: sync
+
+  ret void
+}
+
+declare void @llvm.ppc.iospace.sync() #2
+
+define dso_local void @test_builtin_ppc_icbt() #0 {
+; CHECK-LABEL: test_builtin_ppc_icbt
+
+entry:
+  %a = alloca i8*, align 8
+  %0 = load i8*, i8** %a, align 8
+  call void @llvm.ppc.icbt(i8* %0)
+; CHECK: icbt 0, 0, 3
+
+  ret void
+}
+
+declare void @llvm.ppc.icbt(i8*) #2
Index: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-msync.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-msync.ll
@@ -0,0 +1,33 @@
+; RUN: llc -verify-machineinstrs -mtriple=powerpcle-unknown-linux-gnu \
+; RUN:-mattr=+msync -mcpu=pwr8 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-linux-gnu \
+; RUN:-mattr=+msync -mcpu=pwr8 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN:-mattr=+msync -mcpu=pwr8 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
+; RUN:-mattr=+msync -mcpu=pwr8 < %s | FileCheck %s
+
+define dso_local void @test_builtin_ppc_iospace_lwsync() #0 {
+; CHECK-LABEL: test_builtin_ppc_iospace_lwsync
+
+entry:
+  call void @llvm.ppc.iospace.lwsync()
+; CHECK: msync
+
+  ret void
+}
+
+declare void @llvm.ppc.iospace.lwsync() #2
+
+define dso_local void @test_builtin_ppc_iospace_sync() #0 {
+; CHECK-LABEL: test_builtin_ppc_iospace_sync
+
+entry:
+  call void @llvm.ppc.iospace.sync()
+; CHECK: msync
+
+  ret void
+}
+
+declare void @llvm.ppc.iospace.sync() #2
+
Index: llvm/lib/Target/PowerPC/PPCInstrInfo.td
===
--- llvm/lib/Target/PowerPC/PPCInstrInfo.td
+++ llvm/lib/Target/PowerPC/PPCInstrInfo.td
@@ -2044,6 +2044,8 @@
   (DCBTST 0, xoaddr:$dst)>;
 def : Pat<(int_ppc_dcbf xoaddr:$dst),
   (DCBF 0, xoaddr:$dst)>;
+def : Pat<(int_ppc_icbt xoaddr:$dst),
+  (ICBT 0, xoaddr:$dst)>;
 
 def : Pat<(prefetch xoaddr:$dst, (i32 0), imm, (i32 1)),
   (DCBT 0, x

[PATCH] D103112: Reimplement __builtin_unique_stable_name-

2021-05-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.
erichkeane added reviewers: aaron.ballman, rjmccall.
Herald added subscribers: Naghasan, dexonsmith, martong, Anastasia, mgrang.
erichkeane requested review of this revision.

The original version of this was reverted, and @rjmcall provided some
advice to architect a new solution.  This is that solution.

This implements a builtin to provide a unique name that is stable across
compilations of this TU for the purposes of implementing the library
component of the unnamed kernel feature of SYCL.  It does this by
running the Itanium mangler with a few modifications.

Because it is somewhat common to wrap non-kernel-related lambdas in
macros that aren't present on the device (such as for logging), this
uniquely generates an ID for all lambdas involved in the naming of a
kernel. It uses the lambda-mangling number to do this, except replaces
this with its own number (starting at 1 for readabililty reasons)
for lambdas used to name a kernel.

Additionally, this implements itself as constexpr with a slight catch:
if a name would be invalidated by the use of this lambda in a later
kernel invocation, it is diagnosed as an error (see the Sema tests).


https://reviews.llvm.org/D103112

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ComputeDependence.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/Mangle.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaSYCL.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/CodeGenSYCL/unique_stable_name.cpp
  clang/test/ParserSYCL/unique_stable_name.cpp
  clang/test/SemaSYCL/unique_stable_name.cpp
  clang/tools/libclang/CXCursor.cpp

Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -336,6 +336,7 @@
   case Stmt::ObjCBoxedExprClass:
   case Stmt::ObjCSubscriptRefExprClass:
   case Stmt::RecoveryExprClass:
+  case Stmt::UniqueStableNameExprClass:
 K = CXCursor_UnexposedExpr;
 break;
 
Index: clang/test/SemaSYCL/unique_stable_name.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/unique_stable_name.cpp
@@ -0,0 +1,208 @@
+// RUN: %clang_cc1 %s -std=c++17 -triple x86_64-pc-windows-msvc -fsycl-is-device -verify -fsyntax-only -Wno-unused
+// RUN: %clang_cc1 %s -std=c++17 -triple x86_64-linux-gnu -fsycl-is-device -verify -fsyntax-only -Wno-unused
+
+template 
+[[clang::sycl_kernel]] void kernel_single_task(KernelType kernelFunc) { // #kernelSingleTask
+  kernelFunc();
+}
+
+// kernel1 - expect error
+// The current function is named with a lambda (i.e., takes a lambda as a
+// template parameter. Call the builtin on the current function then it is
+// passed to a kernel. Test that passing the given function to the unique
+// stable name builtin and then to the kernel throws an error because the
+// latter causes its name mangling to change.
+template 
+void kernel1func(const Func &F1) {
+  constexpr const char *F1_output = __builtin_unique_stable_name(F1); // #USN_F1
+  // expected-error@#kernelSingleTask{{kernel instantiation changes the result of an evaluated '__builtin_unique_stable_name'}}
+  // expected-note@#kernel1func_call{{in instantiation of function template specialization}}
+  // expected-note@#USN_F1{{'__builtin_unique_stable_name' evaluated here}}
+  // expected-note@+1{{in instantiation of function template specialization}}
+  kernel_single_task(F1); // #kernel1_call
+}
+
+void callkernel1() {
+  kernel1func([]() {}); // #kernel1func_call
+}
+
+// kernel2 - expect error
+// The current function is named with a lambda (i.e., takes a lambda as a
+// template parameter). Call the builtin on the given function,
+// then an empty lambda is passed to kernel.
+// Test that passing the given function to the

[PATCH] D102975: [HIP] Check compatibility of -fgpu-sanitize with offload arch

2021-05-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 347769.
yaxunl marked 2 inline comments as done.
yaxunl added a comment.

revised by Artem's comments


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

https://reviews.llvm.org/D102975

Files:
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/AMDGPU.h
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/lib/Driver/ToolChains/HIP.h
  clang/test/Driver/hip-sanitize-options.hip

Index: clang/test/Driver/hip-sanitize-options.hip
===
--- clang/test/Driver/hip-sanitize-options.hip
+++ clang/test/Driver/hip-sanitize-options.hip
@@ -25,6 +25,11 @@
 // RUN:   -nogpuinc --rocm-path=%S/Inputs/rocm-invalid \
 // RUN:   %s 2>&1 | FileCheck -check-prefixes=FAIL %s
 
+// RUN: %clang -### -target x86_64-unknown-linux-gnu --offload-arch=gfx900:xnack- \
+// RUN:   -fsanitize=address -fgpu-sanitize \
+// RUN:   -nogpuinc --rocm-path=%S/Inputs/rocm \
+// RUN:   %s 2>&1 | FileCheck -check-prefix=XNACK %s
+
 // CHECK-NOT: {{"[^"]*clang[^"]*".* "-fcuda-is-device".* "-fsanitize=address"}}
 // CHECK-NOT: {{"[^"]*lld(\.exe){0,1}".* ".*hip.bc"}}
 // CHECK: {{"[^"]*clang[^"]*".* "-triple" "x86_64-unknown-linux-gnu".* "-fsanitize=address"}}
@@ -38,3 +43,5 @@
 // RDC: {{"[^"]*lld(\.exe){0,1}".*}} "[[OUT]]" {{".*asanrtl.bc" ".*hip.bc"}}
 
 // FAIL: AMDGPU address sanitizer runtime library (asanrtl) is not found. Please install ROCm device library which supports address sanitizer
+
+// XNACK: error: '-fgpu-sanitize' is not compatible with offload arch 'gfx900:xnack-'. Use an offload arch without 'xnack-' instead
Index: clang/lib/Driver/ToolChains/HIP.h
===
--- clang/lib/Driver/ToolChains/HIP.h
+++ clang/lib/Driver/ToolChains/HIP.h
@@ -95,6 +95,7 @@
   unsigned GetDefaultDwarfVersion() const override { return 4; }
 
   const ToolChain &HostTC;
+  void checkTargetID(const llvm::opt::ArgList &DriverArgs) const override;
 
 protected:
   Tool *buildLinker() const override;
Index: clang/lib/Driver/ToolChains/HIP.cpp
===
--- clang/lib/Driver/ToolChains/HIP.cpp
+++ clang/lib/Driver/ToolChains/HIP.cpp
@@ -459,3 +459,28 @@
 
   return BCLibs;
 }
+
+void HIPToolChain::checkTargetID(const llvm::opt::ArgList &DriverArgs) const {
+  auto PTID = getParsedTargetID(DriverArgs);
+  if (PTID.OptionalTargetID && !PTID.OptionalGPUArch) {
+getDriver().Diag(clang::diag::err_drv_bad_target_id)
+<< PTID.OptionalTargetID.getValue();
+return;
+  }
+
+  assert(PTID.OptionalFeatures && "Invalid return from getParsedTargetID");
+  auto &FeatureMap = PTID.OptionalFeatures.getValue();
+  // Sanitizer is not supported with xnack-.
+  if (DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
+ options::OPT_fno_gpu_sanitize, false)) {
+auto Loc = FeatureMap.find("xnack");
+if (Loc != FeatureMap.end() && !Loc->second) {
+  auto &Diags = getDriver().getDiags();
+  auto DiagID = Diags.getCustomDiagID(
+  DiagnosticsEngine::Error,
+  "'-fgpu-sanitize' is not compatible with offload arch '%0'. "
+  "Use an offload arch without 'xnack-' instead");
+  Diags.Report(DiagID) << PTID.OptionalTargetID.getValue();
+}
+  }
+}
Index: clang/lib/Driver/ToolChains/AMDGPU.h
===
--- clang/lib/Driver/ToolChains/AMDGPU.h
+++ clang/lib/Driver/ToolChains/AMDGPU.h
@@ -107,7 +107,19 @@
 
 protected:
   /// Check and diagnose invalid target ID specified by -mcpu.
-  void checkTargetID(const llvm::opt::ArgList &DriverArgs) const;
+  virtual void checkTargetID(const llvm::opt::ArgList &DriverArgs) const;
+
+  /// The struct type returned by getParsedTargetID.
+  struct ParsedTargetIDType {
+Optional OptionalTargetID;
+Optional OptionalGPUArch;
+Optional> OptionalFeatures;
+  };
+
+  /// Get target ID, GPU arch, and target ID features if the target ID is
+  /// specified and valid.
+  ParsedTargetIDType
+  getParsedTargetID(const llvm::opt::ArgList &DriverArgs) const;
 
   /// Get GPU arch from -mcpu without checking.
   StringRef getGPUArch(const llvm::opt::ArgList &DriverArgs) const;
Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -707,16 +707,26 @@
   getTriple(), DriverArgs.getLastArgValue(options::OPT_mcpu_EQ));
 }
 
-void AMDGPUToolChain::checkTargetID(
-const llvm::opt::ArgList &DriverArgs) const {
+AMDGPUToolChain::ParsedTargetIDType
+AMDGPUToolChain::getParsedTargetID(const llvm::opt::ArgList &DriverArgs) const {
   StringRef TargetID = DriverArgs.getLastArgValue(options::OPT_mcpu_EQ);
   if (TargetID.empty())
-return;
+return {None, None, None};
 
   llvm::StringMap FeatureMap;
   auto OptionalGpuArch = parseTar

[PATCH] D102026: Thread safety analysis: Allow exlusive/shared joins for managed and asserted capabilities

2021-05-25 Thread Delesley Hutchins via Phabricator via cfe-commits
delesley accepted this revision.
delesley added a comment.
This revision is now accepted and ready to land.

Thanks for taking the time to discuss things with me.  :-)

Wrt. to the TEST_LOCKED_FUNCTION, I agree that you can simulate the behavior 
using Assert and Lock.  But that pattern is too general/powerful, because it 
also allows you to write nonsensical and unsound code.  Philosophically, static 
analysis is concerned with allowing things that are sound, but preventing 
things that are not, so I would prefer to allow the valid case, but warn on the 
nonsensical/unsound code.  The goal is not to provide powerful back doors so 
that you can squeeze anything past the checker -- doing so kind of defeats the 
point.  :-)  That being said, I'm not certainly no asking you to implement 
TEST_LOCKED functionality in this particular patch, and I totally understand 
that it may simply not be worth the effort.

Wrt. to unlocking an Assert, I see no problem.  It makes perfect sense to 
dynamically assert that a mutex is held, then do something, and then unlock the 
mutex afterwards; after all, the caller asserted that it was held before 
unlocking.  You shouldn't disallow that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102026

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


[PATCH] D102026: Thread safety analysis: Allow exlusive/shared joins for managed and asserted capabilities

2021-05-25 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

In D102026#2779983 , @aaronpuchert 
wrote:

> So this change will allow shared/exclusive - asserted/unmanaged joins until 
> my follow-up will disallow them again, though because of the 
> asserted/unmanaged part and not the shared/exclusive part. If you're not 
> happy about this gap in warning coverage, we can also postpone this change 
> until we have the asserted/unmanaged joins disallowed.

Sorry, I got confused here. The change doesn't allow that. It's still 
disallowed as a shared/exclusive join, but I want to disallow it because it's 
an asserted/unmanaged join instead. So there is no gap in warning coverage.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102026

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


[PATCH] D103081: [analyzer] RetainCountChecker: Disable reference counting for OSMetaClass.

2021-05-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Amazing, thanks! Looks like the windows buildbot is broken and it's not our 
fault (sccache broke on their end).

I'll commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103081

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


[PATCH] D102724: Revert "[AIX] Avoid structor alias; die before bad alias codegen"

2021-05-25 Thread Steven Wan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5bc644aeca8f: Revert "[AIX] Avoid structor alias; die 
before bad alias codegen" (authored by Jake-Egan, committed by stevewan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102724

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/aix-constructor-alias.c


Index: clang/test/Driver/aix-constructor-alias.c
===
--- clang/test/Driver/aix-constructor-alias.c
+++ clang/test/Driver/aix-constructor-alias.c
@@ -1,7 +1,7 @@
-// Check that we don't pass -mconstructor-aliases when compiling for AIX.
+// Check that we pass -mconstructor-aliases when compiling for AIX.
 
 // RUN: %clang -### -target powerpc-ibm-aix7.1.0.0 %s -c -o %t.o 2>&1 \
 // RUN:   | FileCheck %s
 // RUN: %clang -### -target powerpc64-ibm-aix7.1.0.0 %s -c -o %t.o 2>&1 \
 // RUN:   | FileCheck %s
-// CHECK-NOT: "-mconstructor-aliases"
+// CHECK: "-mconstructor-aliases"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5028,10 +5028,8 @@
 
   // Enable -mconstructor-aliases except on darwin, where we have to work 
around
   // a linker bug (see ), and CUDA/AMDGPU device code,
-  // where aliases aren't supported. Similarly, aliases aren't yet supported
-  // for AIX.
-  if (!RawTriple.isOSDarwin() && !RawTriple.isNVPTX() &&
-  !RawTriple.isAMDGPU() && !RawTriple.isOSAIX())
+  // where aliases aren't supported.
+  if (!RawTriple.isOSDarwin() && !RawTriple.isNVPTX() && !RawTriple.isAMDGPU())
 CmdArgs.push_back("-mconstructor-aliases");
 
   // Darwin's kernel doesn't support guard variables; just die if we


Index: clang/test/Driver/aix-constructor-alias.c
===
--- clang/test/Driver/aix-constructor-alias.c
+++ clang/test/Driver/aix-constructor-alias.c
@@ -1,7 +1,7 @@
-// Check that we don't pass -mconstructor-aliases when compiling for AIX.
+// Check that we pass -mconstructor-aliases when compiling for AIX.
 
 // RUN: %clang -### -target powerpc-ibm-aix7.1.0.0 %s -c -o %t.o 2>&1 \
 // RUN:   | FileCheck %s
 // RUN: %clang -### -target powerpc64-ibm-aix7.1.0.0 %s -c -o %t.o 2>&1 \
 // RUN:   | FileCheck %s
-// CHECK-NOT: "-mconstructor-aliases"
+// CHECK: "-mconstructor-aliases"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5028,10 +5028,8 @@
 
   // Enable -mconstructor-aliases except on darwin, where we have to work around
   // a linker bug (see ), and CUDA/AMDGPU device code,
-  // where aliases aren't supported. Similarly, aliases aren't yet supported
-  // for AIX.
-  if (!RawTriple.isOSDarwin() && !RawTriple.isNVPTX() &&
-  !RawTriple.isAMDGPU() && !RawTriple.isOSAIX())
+  // where aliases aren't supported.
+  if (!RawTriple.isOSDarwin() && !RawTriple.isNVPTX() && !RawTriple.isAMDGPU())
 CmdArgs.push_back("-mconstructor-aliases");
 
   // Darwin's kernel doesn't support guard variables; just die if we
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5bc644a - Revert "[AIX] Avoid structor alias; die before bad alias codegen"

2021-05-25 Thread Steven Wan via cfe-commits

Author: Jake Egan
Date: 2021-05-25T15:07:40-04:00
New Revision: 5bc644aeca8fc6a734308d81781935de26ea4cde

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

LOG: Revert "[AIX] Avoid structor alias; die before bad alias codegen"

Avoiding structor alias is no longer needed because AIX now has an alias 
implementation here: https://reviews.llvm.org/D83252.

This reverts commit b116ded57da3530e661f871f4191c59cd9e091cd.

Reviewed By: jasonliu

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/aix-constructor-alias.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 677e2b635354..6ded23b316c8 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5028,10 +5028,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 
   // Enable -mconstructor-aliases except on darwin, where we have to work 
around
   // a linker bug (see ), and CUDA/AMDGPU device code,
-  // where aliases aren't supported. Similarly, aliases aren't yet supported
-  // for AIX.
-  if (!RawTriple.isOSDarwin() && !RawTriple.isNVPTX() &&
-  !RawTriple.isAMDGPU() && !RawTriple.isOSAIX())
+  // where aliases aren't supported.
+  if (!RawTriple.isOSDarwin() && !RawTriple.isNVPTX() && !RawTriple.isAMDGPU())
 CmdArgs.push_back("-mconstructor-aliases");
 
   // Darwin's kernel doesn't support guard variables; just die if we

diff  --git a/clang/test/Driver/aix-constructor-alias.c 
b/clang/test/Driver/aix-constructor-alias.c
index 18c5f5b5b877..0f53dee2be67 100644
--- a/clang/test/Driver/aix-constructor-alias.c
+++ b/clang/test/Driver/aix-constructor-alias.c
@@ -1,7 +1,7 @@
-// Check that we don't pass -mconstructor-aliases when compiling for AIX.
+// Check that we pass -mconstructor-aliases when compiling for AIX.
 
 // RUN: %clang -### -target powerpc-ibm-aix7.1.0.0 %s -c -o %t.o 2>&1 \
 // RUN:   | FileCheck %s
 // RUN: %clang -### -target powerpc64-ibm-aix7.1.0.0 %s -c -o %t.o 2>&1 \
 // RUN:   | FileCheck %s
-// CHECK-NOT: "-mconstructor-aliases"
+// CHECK: "-mconstructor-aliases"



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


[PATCH] D102650: Old work on P0388. For reference in D102645. Not for review / commit.

2021-05-25 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added subscribers: MaskRay, mehdi_amini.
dblaikie added a comment.

In D102650#2779193 , @urnathan wrote:

> dblaikie, do you know if there's a way to do it outside of arc? (for reasons, 
> I've not got arc to work from inside work).  I tried not setting a reviewer, 
> but then that got autofilled.

I'm not sure - @MaskRay & @mehdi_amini might know more there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102650

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


[PATCH] D103081: RetainCountChecker: Disable reference counting for OSMetaClass.

2021-05-25 Thread Georgeta Igna via Phabricator via cfe-commits
georgi_igna updated this revision to Diff 347748.
georgi_igna added a comment.

RetainCountChecker: Disable reference counting for OSMetaClass


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103081

Files:
  clang/lib/Analysis/RetainSummaryManager.cpp
  clang/test/Analysis/os_object_base.h
  clang/test/Analysis/osobject-retain-release.cpp


Index: clang/test/Analysis/osobject-retain-release.cpp
===
--- clang/test/Analysis/osobject-retain-release.cpp
+++ clang/test/Analysis/osobject-retain-release.cpp
@@ -720,6 +720,16 @@
   obj->release();
 }
 
+void test_osmetaclass_release() {
+  const char *name = "no_name";
+  const OSMetaClass *meta = OSMetaClass::copyMetaClassWithName(name);
+  if (!meta) {
+return;
+  } else {
+meta->releaseMetaClass();
+  }
+}
+
 OSObject *getRuleViolation() {
   return new OSObject; // expected-warning{{Potential leak of an object of 
type 'OSObject'}}
 // expected-note@-1{{Operator 'new' returns an OSObject of type 'OSObject' 
with a +1 retain count}}
Index: clang/test/Analysis/os_object_base.h
===
--- clang/test/Analysis/os_object_base.h
+++ clang/test/Analysis/os_object_base.h
@@ -67,6 +67,8 @@
 struct OSMetaClass : public OSMetaClassBase {
   virtual OSObject * alloc() const;
   static OSObject * allocClassWithName(const char * name);
+  static const OSMetaClass *copyMetaClassWithName(const char *name);
+  void releaseMetaClass() const;
   virtual ~OSMetaClass(){}
 };
 
Index: clang/lib/Analysis/RetainSummaryManager.cpp
===
--- clang/lib/Analysis/RetainSummaryManager.cpp
+++ clang/lib/Analysis/RetainSummaryManager.cpp
@@ -145,14 +145,20 @@
   return !(match(SubclassM, *D, D->getASTContext()).empty());
 }
 
-static bool isOSObjectSubclass(const Decl *D) {
-  return D && isSubclass(D, "OSMetaClassBase");
+static bool isExactClass(const Decl *D, StringRef ClassName) {
+  using namespace ast_matchers;
+  DeclarationMatcher sameClassM =
+  cxxRecordDecl(hasName(std::string(ClassName)));
+  return !(match(sameClassM, *D, D->getASTContext()).empty());
 }
 
-static bool isOSObjectDynamicCast(StringRef S) {
-  return S == "safeMetaCast";
+static bool isOSObjectSubclass(const Decl *D) {
+  return D && isSubclass(D, "OSMetaClassBase") &&
+ !isExactClass(D, "OSMetaClass");
 }
 
+static bool isOSObjectDynamicCast(StringRef S) { return S == "safeMetaCast"; }
+
 static bool isOSObjectRequiredCast(StringRef S) {
   return S == "requiredMetaCast";
 }


Index: clang/test/Analysis/osobject-retain-release.cpp
===
--- clang/test/Analysis/osobject-retain-release.cpp
+++ clang/test/Analysis/osobject-retain-release.cpp
@@ -720,6 +720,16 @@
   obj->release();
 }
 
+void test_osmetaclass_release() {
+  const char *name = "no_name";
+  const OSMetaClass *meta = OSMetaClass::copyMetaClassWithName(name);
+  if (!meta) {
+return;
+  } else {
+meta->releaseMetaClass();
+  }
+}
+
 OSObject *getRuleViolation() {
   return new OSObject; // expected-warning{{Potential leak of an object of type 'OSObject'}}
 // expected-note@-1{{Operator 'new' returns an OSObject of type 'OSObject' with a +1 retain count}}
Index: clang/test/Analysis/os_object_base.h
===
--- clang/test/Analysis/os_object_base.h
+++ clang/test/Analysis/os_object_base.h
@@ -67,6 +67,8 @@
 struct OSMetaClass : public OSMetaClassBase {
   virtual OSObject * alloc() const;
   static OSObject * allocClassWithName(const char * name);
+  static const OSMetaClass *copyMetaClassWithName(const char *name);
+  void releaseMetaClass() const;
   virtual ~OSMetaClass(){}
 };
 
Index: clang/lib/Analysis/RetainSummaryManager.cpp
===
--- clang/lib/Analysis/RetainSummaryManager.cpp
+++ clang/lib/Analysis/RetainSummaryManager.cpp
@@ -145,14 +145,20 @@
   return !(match(SubclassM, *D, D->getASTContext()).empty());
 }
 
-static bool isOSObjectSubclass(const Decl *D) {
-  return D && isSubclass(D, "OSMetaClassBase");
+static bool isExactClass(const Decl *D, StringRef ClassName) {
+  using namespace ast_matchers;
+  DeclarationMatcher sameClassM =
+  cxxRecordDecl(hasName(std::string(ClassName)));
+  return !(match(sameClassM, *D, D->getASTContext()).empty());
 }
 
-static bool isOSObjectDynamicCast(StringRef S) {
-  return S == "safeMetaCast";
+static bool isOSObjectSubclass(const Decl *D) {
+  return D && isSubclass(D, "OSMetaClassBase") &&
+ !isExactClass(D, "OSMetaClass");
 }
 
+static bool isOSObjectDynamicCast(StringRef S) { return S == "safeMetaCast"; }
+
 static bool isOSObjectRequiredCast(StringRef S) {
   return S == "requiredMetaCast";
 }

[PATCH] D103108: [CUDA][HIP] Promote const variables to constant

2021-05-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
yaxunl requested review of this revision.

Recently we added diagnosing ODR-use of host variables
in device functions, which includes ODR-use of const
host variables since they are not really emitted on
device side. This caused regressions since we used
to allow ODR-use of const host variables in device
functions.

This patch allows ODR-use of const variables in device
functions if the const variables can be statically initialized
and have an empty dtor. Such variables are marked with
implicit constant attrs and emitted on device side. This is
in line with what clang does for constexpr variables.


https://reviews.llvm.org/D103108

Files:
  clang/lib/Sema/SemaCUDA.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGenCUDA/device-use-host-var.cu
  clang/test/SemaCUDA/device-use-host-var.cu

Index: clang/test/SemaCUDA/device-use-host-var.cu
===
--- clang/test/SemaCUDA/device-use-host-var.cu
+++ clang/test/SemaCUDA/device-use-host-var.cu
@@ -5,6 +5,8 @@
 
 #include "Inputs/cuda.h"
 
+int func();
+
 struct A {
   int x;
   static int host_var;
@@ -16,6 +18,19 @@
   int host_var;
 }
 
+// struct with non-empty ctor.
+struct B1 {
+  int x;
+  B1() { x = 1; }
+};
+
+// struct with non-empty dtor.
+struct B2 {
+  int x;
+  B2() {}
+  ~B2() { x = 0; }
+};
+
 static int static_host_var;
 
 __device__ int global_dev_var;
@@ -34,6 +49,17 @@
 const A global_const_struct_var{1};
 constexpr A global_constexpr_struct_var{1};
 
+// Check const host var initialized with non-empty ctor is not allowed in
+// device function.
+const B1 b1;
+
+// Check const host var having non-empty dtor is not allowed in device function.
+const B2 b2;
+
+// Check const host var initialized by non-constant initializer is not allowed
+// in device function.
+const int b3 = func();
+
 template
 __global__ void kernel(F f) { f(); } // dev-note2 {{called by 'kernel<(lambda}}
 
@@ -53,11 +79,14 @@
   *out = global_host_var; // dev-error {{reference to __host__ variable 'global_host_var' in __device__ function}}
   *out = global_const_var;
   *out = global_constexpr_var;
+  *out = b1.x; // dev-error {{reference to __host__ variable 'b1' in __device__ function}}
+  *out = b2.x; // dev-error {{reference to __host__ variable 'b2' in __device__ function}}
+  *out = b3; // dev-error {{reference to __host__ variable 'b3' in __device__ function}}
   global_host_var = 1; // dev-error {{reference to __host__ variable 'global_host_var' in __device__ function}}
 
   // Check reference of non-constexpr host variables are not allowed.
   int &ref_host_var = global_host_var; // dev-error {{reference to __host__ variable 'global_host_var' in __device__ function}}
-  const int &ref_const_var = global_const_var; // dev-error {{reference to __host__ variable 'global_const_var' in __device__ function}}
+  const int &ref_const_var = global_const_var;
   const int &ref_constexpr_var = global_constexpr_var;
   *out = ref_host_var;
   *out = ref_constexpr_var;
@@ -65,18 +94,18 @@
 
   // Check access member of non-constexpr struct type host variable is not allowed.
   *out = global_host_struct_var.x; // dev-error {{reference to __host__ variable 'global_host_struct_var' in __device__ function}}
-  *out = global_const_struct_var.x; // dev-error {{reference to __host__ variable 'global_const_struct_var' in __device__ function}}
+  *out = global_const_struct_var.x;
   *out = global_constexpr_struct_var.x;
   global_host_struct_var.x = 1; // dev-error {{reference to __host__ variable 'global_host_struct_var' in __device__ function}}
 
   // Check address taking of non-constexpr host variables is not allowed.
   int *p = &global_host_var; // dev-error {{reference to __host__ variable 'global_host_var' in __device__ function}}
-  const int *cp = &global_const_var; // dev-error {{reference to __host__ variable 'global_const_var' in __device__ function}}
+  const int *cp = &global_const_var;
   const int *cp2 = &global_constexpr_var;
 
   // Check access elements of non-constexpr host array is not allowed.
   *out = global_host_array[1]; // dev-error {{reference to __host__ variable 'global_host_array' in __device__ function}}
-  *out = global_const_array[1]; // dev-error {{reference to __host__ variable 'global_const_array' in __device__ function}}
+  *out = global_const_array[1];
   *out = global_constexpr_array[1];
 
   // Check ODR-use of host variables in namespace is not allowed.
@@ -103,7 +132,7 @@
   int &ref_constant_var = global_constant_var;
   int &ref_shared_var = global_shared_var;
   const int &ref_constexpr_var = global_constexpr_var;
-  const int &ref_const_var = global_const_var; // dev-error {{reference to __host__ variable 'global_const_var' in __global__ function}}
+  const int &ref_const_var = global_const_var;
 
   *out = global_host_var; // dev-error {{reference to __host__ variable 'global_host_var' in __global__ function}}
   *out =

[PATCH] D101921: [MC] Make it possible for targets to define their own MCObjectFileInfo

2021-05-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: llvm/include/llvm/Support/TargetRegistry.h:26
 #include "llvm/ADT/iterator_range.h"
+#include "llvm/MC/MCObjectFileInfo.h"
 #include "llvm/Support/CodeGen.h"

`include/llvm/Support/TargetRegistry.h now has cyclic dependency on 
include/MC/*.h`.

The previous style isn't good as well: `include/llvm/Support/TargetRegistry.h` 
has forward declarations of a number of MC* classes.

I think this header probably should be moved to lib/Target.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101921

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


[PATCH] D101191: [InstCombine] Fully disable select to and/or i1 folding

2021-05-25 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added a comment.

In D101191#2779631 , @spatel wrote:

> In D101191#2779007 , @fhahn wrote:
>
>> Looks like this is causing an infinite loop in instcombine: 
>> https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=34661
>
> This seems likely to be another partial undef/poison vector problem ( 
> 1894c6c59e 
>  ). I'll 
> take a look.

The fuzzer test can be reduced to a single line. I committed a minimal fix here:
ae1bc9ebf3 
...but some follow-up seems necessary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101191

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


[PATCH] D102026: Thread safety analysis: Allow exlusive/shared joins for managed and asserted capabilities

2021-05-25 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

In D102026#2777438 , @delesley wrote:

> The warn/not-warn is consistent with more relaxed handling of managed locks, 
> but exclusive/shared difference could lead to confusion.  Both mechanisms are 
> sound; they're just not consistent.  Any thoughts?

Essentially I'm suggesting here to treat exclusive/shared joins the same way as 
locked/unlocked joins: we allow them for managed locks and take the "weaker" 
state afterwards to prevent false negatives, but not for unmanaged locks, where 
we take the "stronger" state afterwards to prevent spamming the user.

> Second, the mixing of AssertHeld() and Lock() on different control flow 
> branches looks very weird to me.  I can see one obvious case where you might 
> want to do that, e.g.  if (mu_.is_locked()) mu_.AssertHeld(); else mu_.Lock().

This pattern already works, but not with exclusive/shared mismatch.

> However, if a function locks mu_ on one branch, and assert mu_ on the other, 
> then that usually indicates a problem.  It means that the lock-state going 
> into that function was unknown; the programmer didn't know whether mu_ was 
> locked or not, and that's never good.

Generally I agree with you. It's something that repeatedly came up though, 
people were having these functions that were called sometimes with lock, 
sometimes without. It's not incredibly common, but I saw it a few times. I 
recommended the above pattern to get rid of the warnings that popped up, when 
reworking this into a function with clear preconditions didn't work.

> The //only// valid condition in that case is to check whether mu_ is locked 
> -- any other condition would be unsound.

Well, that information might not always come from `mu_` itself. It might be 
tracked in the class that owns `mu_`.

> The correct way to deal with this situation is to mark the is_locked() method 
> with an attribute, e.g. TEST_LOCKED_FUNCTION, rather than relying on the 
> AssertHeld mechanism.  That's a lot more work, but I would prefer to at least 
> have a TODO comment indicating that the AssertHeld is a workaround,

It certainly is a workaround, but it's powerful enough to cover everything that 
we could do with `TEST_LOCKED_FUNCTION`, except that we can't find cases where 
the branches have been mixed up.

I've thought about such an attribute (after all it shouldn't be much different 
from `try_acquire` implementation-wise), but I've found it hard to justify 
because we can just use these assertions to achieve the same thing. You can 
even do

  if (mu.isLocked())
  []() ASSERT_CAPABILITY(mu) {}();
  else
  mu.Lock();



> and restrict the mixing of assert/lock to managed locks in the mean time.

I think we should disallow releasing asserted locks, and then naturally we 
can't allow assert/lock joins for unmanaged locks. I'm planning another change 
for this.

It is the status quo: we allow these joins, just not with mixed mode 
(shared/exclusive). So this change will allow shared/exclusive - 
asserted/unmanaged joins until my follow-up will disallow them again, though 
because of the asserted/unmanaged part and not the shared/exclusive part. If 
you're not happy about this gap in warning coverage, we can also postpone this 
change until we have the asserted/unmanaged joins disallowed.




Comment at: clang/test/SemaCXX/warn-thread-safety-analysis.cpp:4570
 mu_.AssertHeld();
-mu_.Unlock();
-  }  // should this be a warning?
+mu_.Unlock(); // should this be a warning?
+  }

delesley wrote:
> This function should have a warning because is not marked with 
> UNLOCK_FUNCTION.  The lock was held on entry, and not held on exit.  So the 
> original location of the comment, on the closing curly brace, was correct.  
Putting it on the `Unlock` call would some more natural to me, and also more 
helpful. Natural, because that's where we (should) discover the issue, and 
helpful, because in a longer function you wouldn't know what's going on if the 
unlock is somewhere in the middle.

If we didn't have `AssertHeld`, we would also warn on the `Unlock` call, and I 
think we should treat this no different (other than having a different warning 
message).



Comment at: clang/test/SemaCXX/warn-thread-safety-analysis.cpp:4629
+  mu_.AssertHeld(); // expected-note {{the other acquisition of mutex 
'mu_' is here}}
+// FIXME: should instead warn because it's unclear whether we need to 
release or not.
+int b = a;

delesley wrote:
> I'm not wild about having FIXMEs in test code.  I would prefer to have the 
> patch actually issue a warning here (but see below).
> 
> HOWEVER, does the current code issue a warning in this situation?  If not, 
> leave it as-is and keep the FIXME.  You can't make the analysis more strict 
> without checking with the C++ compiler team at Google (which I am no longer 
> on), because it may break the build on our e

[PATCH] D101868: [clang-format] Adds a formatter for aligning arrays of structs

2021-05-25 Thread Fred Grim via Phabricator via cfe-commits
feg208 updated this revision to Diff 347709.
feg208 added a comment.

Addresses review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101868

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/ContinuationIndenter.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/TokenAnnotator.h
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16367,6 +16367,162 @@
getLLVMStyle());
 }
 
+TEST_F(FormatTest, CatchAlignArrayOfStructures) {
+  auto Style = getLLVMStyle();
+  Style.AlignArrayOfStructures = true;
+  Style.AlignConsecutiveAssignments =
+  FormatStyle::AlignConsecutiveStyle::ACS_Consecutive;
+  Style.AlignConsecutiveDeclarations =
+  FormatStyle::AlignConsecutiveStyle::ACS_Consecutive;
+  verifyFormat("struct test demo[] = {\n"
+   "{56,23, \"hello\" },\n"
+   "{-1, 93463, \"world\" },\n"
+   "{ 7, 5,\"!!\" }\n"
+   "};\n",
+   Style);
+
+  verifyFormat("struct test demo[] = {\n"
+   "{56,23, \"hello\" }, // first line\n"
+   "{-1, 93463, \"world\" }, // second line\n"
+   "{ 7, 5,\"!!\" }  // third line\n"
+   "};\n",
+   Style);
+
+  verifyFormat("struct test demo[4] = {\n"
+   "{ 56,23, 21,   \"oh\" }, // first line\n"
+   "{ -1, 93463, 22,   \"my\" }, // second line\n"
+   "{  7, 5,  1, \"goodness\" }  // third line\n"
+   "{234, 5,  1, \"gracious\" }  // fourth line\n"
+   "};\n",
+   Style);
+
+  verifyFormat("struct test demo[3] = {\n"
+   "{56,23, \"hello\" },\n"
+   "{-1, 93463, \"world\" },\n"
+   "{ 7, 5,\"!!\" }\n"
+   "};\n",
+   Style);
+  verifyFormat("struct test demo[3] = {\n"
+   "{int{56},23, \"hello\" },\n"
+   "{int{-1}, 93463, \"world\" },\n"
+   "{ int{7}, 5,\"!!\" }\n"
+   "};\n",
+   Style);
+  verifyFormat("struct test demo[] = {\n"
+   "{56,23, \"hello\" },\n"
+   "{-1, 93463, \"world\" },\n"
+   "{ 7, 5,\"!!\" },\n"
+   "};\n",
+   Style);
+  verifyFormat("test demo[] = {\n"
+   "{56,23, \"hello\" },\n"
+   "{-1, 93463, \"world\" },\n"
+   "{ 7, 5,\"!!\" },\n"
+   "};\n",
+   Style);
+  verifyFormat("demo = std::array{\n"
+   "test{56,23, \"hello\" },\n"
+   "test{-1, 93463, \"world\" },\n"
+   "test{ 7, 5,\"!!\" },\n"
+   "};\n",
+   Style);
+  verifyFormat("test demo[] = {\n"
+   "{56,23, \"hello\" },\n"
+   "#if X\n"
+   "{-1, 93463, \"world\" },\n"
+   "#endif\n"
+   "{ 7, 5,\"!!\" }\n"
+   "};\n",
+   Style);
+
+  verifyFormat("test demo[] = {\n"
+   "{ 7,23,\n"
+   "\"hello world i am a very long line that really, in any\"\n"
+   "\"just world, ought to be split over multiple lines\" },\n"
+   "{-1, 93463, \"world\" },\n"
+   "{56, 5,\"!!\" }\n"
+   "};\n",
+   Style);
+
+  verifyFormat("return GradForUnaryCwise(g, {\n"
+   "{{\"sign\"}, \"Sign\",  "
+   "{\"x\", \"dy\"} },\n"
+   "{  {\"dx\"},  \"Mul\", {\"dy\""
+   ", \"sign\"} },\n"
+   "});\n",
+   Style);
+
+  Style.ColumnLimit = 0;
+  EXPECT_EQ(
+  "test demo[] = {\n"
+  "{56,23, \"hello world i am a very long line that really, "
+  "in any just world, ought to be split over multiple lines\" },\n"
+  "{-1, 93463,  "
+  " \"world\" },\n"
+  "{ 7, 5,  "
+  "\"!!\" },\n"
+  "};",
+  format("test demo[] = {{56, 23, \"

[PATCH] D101868: [clang-format] Adds a formatter for aligning arrays of structs

2021-05-25 Thread Fred Grim via Phabricator via cfe-commits
feg208 marked 2 inline comments as done.
feg208 added a comment.

The tests still need to be added


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101868

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


[PATCH] D103097: Add DWARF address spaces mapping for SPIR

2021-05-25 Thread Jason Zheng via Phabricator via cfe-commits
jzzheng22 updated this revision to Diff 347708.

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

https://reviews.llvm.org/D103097

Files:
  clang/lib/Basic/Targets/SPIR.h
  clang/test/CodeGenOpenCL/spir-debug-info-pointer-address-space.cl

Index: clang/test/CodeGenOpenCL/spir-debug-info-pointer-address-space.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/spir-debug-info-pointer-address-space.cl
@@ -0,0 +1,128 @@
+// RUN: %clang_cc1 -cl-std=CL2.0 -debug-info-kind=limited -dwarf-version=5 -emit-llvm -O0 -triple spir-unknown-unknown -o - %s | FileCheck %s
+// RUN: %clang_cc1 -cl-std=CL2.0 -debug-info-kind=limited -dwarf-version=5 -emit-llvm -O0 -triple spir64-unknown-unknown -o - %s | FileCheck %s
+
+// CHECK-DAG: ![[DWARF_ADDRESS_SPACE_GLOBAL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !{{[0-9]+}}, size: {{[0-9]+}}, dwarfAddressSpace: 1)
+// CHECK-DAG: ![[DWARF_ADDRESS_SPACE_CONSTANT:[0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !{{[0-9]+}}, size: {{[0-9]+}}, dwarfAddressSpace: 2)
+// CHECK-DAG: ![[DWARF_ADDRESS_SPACE_LOCAL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !{{[0-9]+}}, size: {{[0-9]+}}, dwarfAddressSpace: 3)
+// CHECK-DAG: ![[DWARF_ADDRESS_SPACE_PRIVATE:[0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !{{[0-9]+}}, size: {{[0-9]+}}, dwarfAddressSpace: 0)
+// CHECK-DAG: ![[DWARF_ADDRESS_SPACE_GENERIC:[0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !{{[0-9]+}}, size: {{[0-9]+}}, dwarfAddressSpace: 4)
+
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar0", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_GLOBAL]], isLocal: false, isDefinition: true)
+global int *FileVar0;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar1", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_CONSTANT]], isLocal: false, isDefinition: true)
+constant int *FileVar1;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar2", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_LOCAL]], isLocal: false, isDefinition: true)
+local int *FileVar2;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar3", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_PRIVATE]], isLocal: false, isDefinition: true)
+private int *FileVar3;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar4", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_GENERIC]], isLocal: false, isDefinition: true)
+int *FileVar4;
+
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar5", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_GLOBAL]], isLocal: false, isDefinition: true)
+global int *global FileVar5;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar6", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_CONSTANT]], isLocal: false, isDefinition: true)
+constant int *global FileVar6;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar7", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_LOCAL]], isLocal: false, isDefinition: true)
+local int *global FileVar7;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar8", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_PRIVATE]], isLocal: false, isDefinition: true)
+private int *global FileVar8;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar9", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_GENERIC]], isLocal: false, isDefinition: true)
+int *global FileVar9;
+
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar10", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_GLOBAL]], isLocal: false, isDefinition: true)
+global int *constant FileVar10 = 0;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar11", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_CONSTANT]], isLocal: false, isDefinition: true)
+constant int *constant FileVar11 = 0;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar12", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_LOCAL]], isLocal: false, isDefinition: true)
+local int *constant FileVar12 = 0;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar13", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_PRIVATE]], isLocal: false, isDefinition: true)
+private int *constant FileVar13 = 0;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar14", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_GENERIC]], isLocal: false, isDefinition: true)
+int *constant FileVar14 = 0;
+
+kernel void kernel1(
+// CHECK-DAG: !DILocalVariab

[PATCH] D103097: Add DWARF address spaces mapping for SPIR

2021-05-25 Thread Jason Zheng via Phabricator via cfe-commits
jzzheng22 created this revision.
jzzheng22 added reviewers: cfe-commits, Anastasia.
jzzheng22 requested review of this revision.
Herald added a project: clang.

Extend debug info handling by adding DWARF address space mapping for SPIR, with 
corresponding test case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103097

Files:
  clang/lib/Basic/Targets/SPIR.h
  clang/test/CodeGenOpenCL/spir-debug-info-pointer-address-space.cl

Index: clang/test/CodeGenOpenCL/spir-debug-info-pointer-address-space.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/spir-debug-info-pointer-address-space.cl
@@ -0,0 +1,128 @@
+// RUN: %clang_cc1 -cl-std=CL2.0 -debug-info-kind=limited -dwarf-version=5 -emit-llvm -O0 -triple spir-unknown-unknown -o - %s | FileCheck %s
+// RUN: %clang_cc1 -cl-std=CL2.0 -debug-info-kind=limited -dwarf-version=5 -emit-llvm -O0 -triple spir64-unknown-unknown -o - %s | FileCheck %s
+
+// CHECK-DAG: ![[DWARF_ADDRESS_SPACE_GLOBAL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !{{[0-9]+}}, size: {{[0-9]+}}, dwarfAddressSpace: 1)
+// CHECK-DAG: ![[DWARF_ADDRESS_SPACE_CONSTANT:[0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !{{[0-9]+}}, size: {{[0-9]+}}, dwarfAddressSpace: 2)
+// CHECK-DAG: ![[DWARF_ADDRESS_SPACE_LOCAL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !{{[0-9]+}}, size: {{[0-9]+}}, dwarfAddressSpace: 3)
+// CHECK-DAG: ![[DWARF_ADDRESS_SPACE_PRIVATE:[0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !{{[0-9]+}}, size: {{[0-9]+}}, dwarfAddressSpace: 0)
+// CHECK-DAG: ![[DWARF_ADDRESS_SPACE_GENERIC:[0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !{{[0-9]+}}, size: {{[0-9]+}}, dwarfAddressSpace: 4)
+
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar0", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_GLOBAL]], isLocal: false, isDefinition: true)
+global int *FileVar0;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar1", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_CONSTANT]], isLocal: false, isDefinition: true)
+constant int *FileVar1;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar2", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_LOCAL]], isLocal: false, isDefinition: true)
+local int *FileVar2;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar3", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_PRIVATE]], isLocal: false, isDefinition: true)
+private int *FileVar3;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar4", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_GENERIC]], isLocal: false, isDefinition: true)
+int *FileVar4;
+
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar5", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_GLOBAL]], isLocal: false, isDefinition: true)
+global int *global FileVar5;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar6", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_CONSTANT]], isLocal: false, isDefinition: true)
+constant int *global FileVar6;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar7", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_LOCAL]], isLocal: false, isDefinition: true)
+local int *global FileVar7;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar8", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_PRIVATE]], isLocal: false, isDefinition: true)
+private int *global FileVar8;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar9", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_GENERIC]], isLocal: false, isDefinition: true)
+int *global FileVar9;
+
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar10", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_GLOBAL]], isLocal: false, isDefinition: true)
+global int *constant FileVar10 = 0;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar11", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_CONSTANT]], isLocal: false, isDefinition: true)
+constant int *constant FileVar11 = 0;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar12", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_LOCAL]], isLocal: false, isDefinition: true)
+local int *constant FileVar12 = 0;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar13", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_PRIVATE]], isLocal: false, isDefinition: true)
+private int *constant FileVar13 = 0;
+// CHECK-DAG: distinct !DIGlobalVariable(name: "FileVar14", scope: !{{[0-9]+}}, file: !{

[PATCH] D103096: [analyzer] Implement cast for ranges of symbolic integers.

2021-05-25 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov created this revision.
ASDenysPetrov added reviewers: NoQ, vsavchenko, steakhal, martong, dcoughlin, 
baloghadamsoftware.
ASDenysPetrov added a project: clang.
Herald added subscribers: manas, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, xazax.hun.
ASDenysPetrov requested review of this revision.
Herald added a subscriber: cfe-commits.

Support integral cast for ranges of symbolic integers. Previously we only 
support integral cast for concrete integers.

Reason about the ranges of `SymbolCast` expressions. Apply truncations, 
promotions and conversions to get a correct range set using nested types of a 
`SymbolCast`. Replace `SValBuilder::evalIntegralCast` with 
`SValBuilder::evalCast`. Remove `SValBuilder::evalIntegralCast` as unnecessary 
one.

See tests in //symbol-integral-cast.cpp// for examples.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103096

Files:
  clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  clang/test/Analysis/bool-assignment.c
  clang/test/Analysis/constant-folding.c
  clang/test/Analysis/constraint_manager_negate_difference.c
  clang/test/Analysis/explain-svals.cpp
  clang/test/Analysis/expr-inspection.cpp
  clang/test/Analysis/malloc.c
  clang/test/Analysis/std-c-library-functions.c
  clang/test/Analysis/svalbuilder-rearrange-comparisons.c
  clang/test/Analysis/symbol-integral-cast.cpp

Index: clang/test/Analysis/symbol-integral-cast.cpp
===
--- /dev/null
+++ clang/test/Analysis/symbol-integral-cast.cpp
@@ -0,0 +1,353 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection -analyzer-config eagerly-assume=false -verify %s
+
+template 
+void clang_analyzer_eval(T);
+void clang_analyzer_warnIfReached();
+
+typedef short int16_t;
+typedef int int32_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+
+void test1(int x) {
+  // Even if two lower bytes of `x` equal to zero, it doesn't mean that
+  // the entire `x` is zero. We are not able to know the exact value of x.
+  // It can be one of  65536 possible values like [0, 65536, 131072, ...]
+  // and so on. To avoid huge range sets we still assume `x` in the range
+  // [INT_MIN, INT_MAX].
+  if (!(short)x) {
+if (!x)
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+else
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  }
+}
+
+void test2(int x) {
+  // If two lower bytes of `x` equal to zero, and we know x to be 65537,
+  // which is not truncated to short as zero. Thus the branch is infisible.
+  short s = x;
+  if (!s) {
+if (x == 65537)
+  clang_analyzer_warnIfReached(); // no-warning
+else
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  }
+}
+
+void test3(int x, short s) {
+  s = x;
+  if ((short)x > -10 && s < 10) {
+if (x > 0 && x < 10) {
+  // If the range of the whole variable was constrained then reason again
+  // about truncated bytes to make the ranges more precise.
+  clang_analyzer_eval((short)x <= 0); // expected-warning {{FALSE}}
+}
+  }
+}
+
+void test4(unsigned x) {
+  if ((char)x > 8) {
+// Constraint the range of the lowest byte of `x` to [9, CHAR_MAX].
+// The original range of `x` still remains [0, UINT_MAX].
+clang_analyzer_eval((char)x < 42); // expected-warning {{UNKNOWN}}
+if (x < 42) {
+  // Constraint the original range to [0, 42] and update (re-constraint)
+  // the range of the lowest byte of 'x' to [9, 42].
+  clang_analyzer_eval((char)x < 42); // expected-warning {{TRUE}}
+}
+  }
+}
+
+void test5(unsigned x) {
+  if ((char)x > -10 && (char)x < 10) {
+if ((short)x == 8) {
+  // If the range of higher bytes(short) was constrained then reason again
+  // about smaller truncated ranges(char) to make it more precise.
+  clang_analyzer_eval((char)x == 8);  // expected-warning {{TRUE}}
+  clang_analyzer_eval((short)x == 8); // expected-warning {{TRUE}}
+  // We still assume full version of `x` in the range [INT_MIN, INT_MAX].
+  clang_analyzer_eval(x == 8); // expected-warning {{UNKNOWN}}
+}
+  }
+}
+
+void test6(int x) {
+  // Even if two lower bytes of `x` less than zero, it doesn't mean that `x`
+  // can't be greater than zero. Thence we don't change the native range of
+  // `x` and this branch is feasible.
+  if (x > 0)
+if ((short)x < 0)
+  clang_analyzer_eval(x > 0); // expected-warning {{TRUE}}
+}
+
+void test7(int x) {
+  // The range of two lower bytes of `x` [1, SHORT_MAX] is enough to cover
+  // all p

[PATCH] D98798: Produce warning for performing pointer arithmetic on a null pointer.

2021-05-25 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added a comment.

@thakis, can you please verify that the changes no longer affect the MS 
headers?  Thanks.


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

https://reviews.llvm.org/D98798

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


[PATCH] D103094: [analyzer] Implemented RangeSet::Factory::castTo function to perform promotions, truncations and conversions.

2021-05-25 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov created this revision.
ASDenysPetrov added reviewers: vsavchenko, NoQ, steakhal, xazax.hun.
ASDenysPetrov added a project: clang.
Herald added subscribers: manas, martong, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware.
ASDenysPetrov requested review of this revision.
Herald added a subscriber: cfe-commits.

Handle casts for ranges working similarly to APSIntType::apply function but for 
the whole range set. Support promotions, truncations and conversions.
Example:
Promotion: `char [0, 42] -> short [0, 42] -> int [0, 42] -> llong [0, 42]`
Truncation: `llong [4295033088, 4295033130] -> int [65792, 65834] -> short 
[256, 298] -> char [0, 42]`
Conversion: `char [-42, 42] -> uint [0, 42]U[4294967254, 4294967295] -> 
short[-42, 42]`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103094

Files:
  
clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/unittests/StaticAnalyzer/RangeSetTest.cpp

Index: clang/unittests/StaticAnalyzer/RangeSetTest.cpp
===
--- clang/unittests/StaticAnalyzer/RangeSetTest.cpp
+++ clang/unittests/StaticAnalyzer/RangeSetTest.cpp
@@ -35,12 +35,18 @@
   const RangeSet &Set) {
   return OS << toString(Set);
 }
+LLVM_ATTRIBUTE_UNUSED static std::ostream &operator<<(std::ostream &OS,
+  APSIntType Ty) {
+  return OS << (Ty.isUnsigned() ? "u" : "s") << Ty.getBitWidth();
+}
 
 } // namespace ento
 } // namespace clang
 
 namespace {
 
+template  constexpr bool is_signed_v = std::is_signed::value;
+
 template  struct TestValues {
   static constexpr T MIN = std::numeric_limits::min();
   static constexpr T MAX = std::numeric_limits::max();
@@ -48,7 +54,7 @@
   // which unary minus does not affect on,
   // e.g. int8/int32(0), uint8(128), uint32(2147483648).
   static constexpr T MID =
-  std::is_signed::value ? 0 : ~(static_cast(-1) / static_cast(2));
+  is_signed_v ? 0 : ~(static_cast(-1) / static_cast(2));
   static constexpr T A = MID - (MAX - MID) / 3 * 2;
   static constexpr T B = MID - (MAX - MID) / 3;
   static constexpr T C = -B;
@@ -56,6 +62,34 @@
 
   static_assert(MIN < A && A < B && B < MID && MID < C && C < D && D < MAX,
 "Values shall be in an ascending order");
+  // Clear bits in low bytes by the given amount.
+  template 
+  static const T ClearLowBytes = static_cast(static_cast(Value)
+<< ((Bytes >= 8) ? 0 : Bytes) *
+   8);
+
+  template 
+  static constexpr T TruncZeroOf = ClearLowBytes;
+
+  // Random number with active bits in every byte. 0x'
+  static constexpr T XAAA = static_cast(
+  0b10101010'10101010'10101010'10101010'10101010'10101010'10101010'10101010);
+  template 
+  static constexpr T XAAATruncZeroOf = TruncZeroOf; // 0x'AB00
+
+  // Random number with active bits in every byte. 0x'
+  static constexpr T X555 = static_cast(
+  0b01010101'01010101'01010101'01010101'01010101'01010101'01010101'01010101);
+  template 
+  static constexpr T X555TruncZeroOf = TruncZeroOf; // 0x'5600
+
+  // Numbers for ranges with the same bits in the lowest byte.
+  // 0x'AA2A
+  static constexpr T FromA = ClearLowBytes + 42;
+  static constexpr T ToA = FromA + 2; // 0x'AA2C
+  // 0x'552A
+  static constexpr T FromB = ClearLowBytes + 42;
+  static constexpr T ToB = FromB + 2; // 0x'552C
 };
 
 template  class RangeSetTest : public testing::Test {
@@ -69,8 +103,11 @@
   // End init block
 
   using Self = RangeSetTest;
-  using RawRange = std::pair;
-  using RawRangeSet = std::initializer_list;
+  template  using RawRangeT = std::pair;
+  template 
+  using RawRangeSetT = std::initializer_list>;
+  using RawRange = RawRangeT;
+  using RawRangeSet = RawRangeSetT;
 
   const llvm::APSInt &from(BaseType X) {
 static llvm::APSInt Base{sizeof(BaseType) * 8,
@@ -84,9 +121,21 @@
   }
 
   RangeSet from(const RawRangeSet &Init) {
+static APSIntType Ty{sizeof(BaseType) * 8,
+ std::is_unsigned::value};
+return from(Ty, Init);
+  }
+
+  template  RangeSet from(APSIntType Ty, RawRangeSetT Init) {
+llvm::APSInt First, Second;
+Ty.apply(First);
+Ty.apply(Second);
 RangeSet RangeSet = F.getEmptySet();
 for (const auto &Raw : Init) {
-  RangeSet = F.add(RangeSet, from(Raw));
+  First = Raw.first;
+  Second = Raw.second;
+  RangeSet =
+  F.add(RangeSet, Range(BVF.getValue(First), BVF.getValue(Second)));
 }
 return RangeSet;
   }
@@ -206,9 +255,27 @@
RawRangeSet RawExpected) {
 wrap(&Self::checkDeleteImpl, Point, RawFrom, RawExpected);
   }
-};
 
-} // namespace
+  void checkCastToImpl(R

[PATCH] D99031: [clang-format] Fix CompactNamespaces corner case when AllowShortLambdasOnASingleLine/BraceWrapping.BeforeLambdaBody are set

2021-05-25 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks requested changes to this revision.
HazardyKnusperkeks added inline comments.
This revision now requires changes to proceed.



Comment at: clang/lib/Format/TokenAnnotator.cpp:3496-3501
+  assert(!Tok.is(tok::l_brace) || !Tok.is(BK_Block) ||
+ !Tok.isOneOf(TT_ObjCBlockLBrace, TT_DictLiteral) ||
+ (Tok.Previous && Tok.Previous->Previous));
   return (Tok.is(tok::l_brace) && Tok.is(BK_Block) &&
-  !Tok.isOneOf(TT_ObjCBlockLBrace, TT_DictLiteral));
+  !Tok.isOneOf(TT_ObjCBlockLBrace, TT_DictLiteral) &&
+  !Tok.Previous->Previous->is(tok::kw_namespace));

I find this really hard to read. Maybe you have to split the return.


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

https://reviews.llvm.org/D99031

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


[PATCH] D101868: [clang-format] Adds a formatter for aligning arrays of structs

2021-05-25 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D101868#2777423 , @feg208 wrote:

> In D101868#2776633 , 
> @HazardyKnusperkeks wrote:
>
>> In D101868#2775550 , @feg208 wrote:
>>
>>> This reworks substantially this commit. I recognize there are lacking/broken
>>> tests but I just would like to ensure that the general direction doesn't
>>> seem likely to end in tears
>>
>> I'm not deep enough in clang-format and currently have not enough time to 
>> check that in depth. But why are you right aligning?
>
> So the basic approach here is to add the column aligning at the point that 
> the lines are broken to make sure that we can align to the indented, now 
> broken, columns. The right alignment was the easier path (at the moment) 
> since the spaces attached to tokens in the change list proceeded the token 
> and since I was calculating the column size with spaces based on a pointer 
> attached to the token in the same column. To left align at each column I'd 
> need to look at the adjacent column to determine the right number of spaces.
>
>> I would love to have a right aligning for numbers (or even better aligning 
>> around the decimal dot) in all my code, but strings I wouldn't want to right 
>> align.
>
> I think we could certainly do that. I guess at this point (and this is 
> somewhat motivated by the fact that I don't, and probably shouldn't, have 
> commit rights the to llvm repo) I think if we want to move this commit 
> forward we ought to agree on a set of changes and subsequent tests that we 
> can all be comfortable with that would make this a viable bit of code. I 
> don't think it has deep problems in the sense the prior one did and so should 
> be amenable to laundry listing what we need and I'll move it forward. I think 
> this set of tests should be added/fixed:
>
> A test where the line is broken in the middle and/or first column (line 
> breaking is really the sticky bit)
> Fixing the test where the 100 column limit doesn't format correctly
> Adding a test with several arrays to format and varying the other alignment 
> options to make sure that doesn't confuse anything
>
> I guess a final question I have would be, if we get this list sorted who 
> can/would be capable of committing this change to the repo?

As said, I would really love more advanced alignment options, but I think we 
should keep to what clang-format does now, left aligning.

The tests seem to be reasonable, a combination of previous (mis)alignment and 
comments (end of line and in the middle) should be added.




Comment at: clang/lib/Format/TokenAnnotator.cpp:2650
+
+// NOLINTNEXTLINE(misc-no-recursion)
+FormatToken *TokenAnnotator::calculateInitializerColumnList(

I don't know if there are already NOLINTs in the code and if there should be, 
on a different change I saw there are some messages from clang-tidy in the 
existing code which are ignored (not NOLINTed). That's something maybe someone 
with more experience can answer.



Comment at: clang/lib/Format/TokenAnnotator.cpp:2662
+  while (CurrentToken != nullptr && CurrentToken != Line.Last) {
+if (CurrentToken->is(tok::l_brace)) {
+  ++Depth;

Although I'm not a big fan of it, I think the LLVM style is no braces for one 
line if and else.



Comment at: clang/lib/Format/TokenAnnotator.cpp:2681
+CurrentToken->Next, Depth);
+  // NOLINTNEXTLINE(llvm-else-after-return)
+} else if (Depth == 1) {

This one I'm against, just do what clang-tidy says remove the else. (Others may 
disagree.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101868

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


[PATCH] D101191: [InstCombine] Fully disable select to and/or i1 folding

2021-05-25 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added a comment.

In D101191#2779007 , @fhahn wrote:

> Looks like this is causing an infinite loop in instcombine: 
> https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=34661

This seems likely to be another partial undef/poison vector problem ( 
1894c6c59e 
 ). I'll 
take a look.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101191

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


[clang] 21aa107 - Reland "Do not create LLVM IR `constant`s for objects with dynamic initialisation"

2021-05-25 Thread Momchil Velikov via cfe-commits

Author: Momchil Velikov
Date: 2021-05-25T15:54:40+01:00
New Revision: 21aa107eb79f8ddc5e7ca4e8f3476338dfa90049

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

LOG: Reland "Do not create LLVM IR `constant`s for objects with dynamic 
initialisation"

This relands commit 13dd65b3a1a3ac049b5f3a9712059f7c61649bea.

The original commit contained a test, which failed when compiled
for a MACH-O target.

This patch changes the test to run for x86_64-linux instead of
`%itanium_abi_triple`, to avoid having invalid syntax for MACH-O
sections. The patch itself does not care about section attribute
syntax and a x86 backend does not even need to be included in the
build.

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

Added: 
clang/test/CodeGenCXX/clang-sections-1.cpp
clang/test/CodeGenCXX/const-dynamic-init.cpp

Modified: 
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 601f4f2502f0..e08e8d8346c0 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13047,43 +13047,6 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl 
*var) {
 }
   }
 
-  // Apply section attributes and pragmas to global variables.
-  bool GlobalStorage = var->hasGlobalStorage();
-  if (GlobalStorage && var->isThisDeclarationADefinition() &&
-  !inTemplateInstantiation()) {
-PragmaStack *Stack = nullptr;
-int SectionFlags = ASTContext::PSF_Read;
-if (var->getType().isConstQualified())
-  Stack = &ConstSegStack;
-else if (!var->getInit()) {
-  Stack = &BSSSegStack;
-  SectionFlags |= ASTContext::PSF_Write;
-} else {
-  Stack = &DataSegStack;
-  SectionFlags |= ASTContext::PSF_Write;
-}
-if (const SectionAttr *SA = var->getAttr()) {
-  if (SA->getSyntax() == AttributeCommonInfo::AS_Declspec)
-SectionFlags |= ASTContext::PSF_Implicit;
-  UnifySection(SA->getName(), SectionFlags, var);
-} else if (Stack->CurrentValue) {
-  SectionFlags |= ASTContext::PSF_Implicit;
-  auto SectionName = Stack->CurrentValue->getString();
-  var->addAttr(SectionAttr::CreateImplicit(
-  Context, SectionName, Stack->CurrentPragmaLocation,
-  AttributeCommonInfo::AS_Pragma, SectionAttr::Declspec_allocate));
-  if (UnifySection(SectionName, SectionFlags, var))
-var->dropAttr();
-}
-
-// Apply the init_seg attribute if this has an initializer.  If the
-// initializer turns out to not be dynamic, we'll end up ignoring this
-// attribute.
-if (CurInitSeg && var->getInit())
-  var->addAttr(InitSegAttr::CreateImplicit(Context, 
CurInitSeg->getString(),
-   CurInitSegLoc,
-   
AttributeCommonInfo::AS_Pragma));
-  }
 
   if (!var->getType()->isStructureType() && var->hasInit() &&
   isa(var->getInit())) {
@@ -13133,14 +13096,6 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl 
*var) {
   }
   }
 
-  // All the following checks are C++ only.
-  if (!getLangOpts().CPlusPlus) {
-// If this variable must be emitted, add it as an initializer for the
-// current module.
-if (Context.DeclMustBeEmitted(var) && !ModuleScopes.empty())
-  Context.addModuleInitializer(ModuleScopes.back().Module, var);
-return;
-  }
 
   QualType type = var->getType();
 
@@ -13148,11 +13103,14 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl 
*var) {
 getCurFunction()->addByrefBlockVar(var);
 
   Expr *Init = var->getInit();
+  bool GlobalStorage = var->hasGlobalStorage();
   bool IsGlobal = GlobalStorage && !var->isStaticLocal();
   QualType baseType = Context.getBaseElementType(type);
+  bool HasConstInit = true;
 
   // Check whether the initializer is sufficiently constant.
-  if (!type->isDependentType() && Init && !Init->isValueDependent() &&
+  if (getLangOpts().CPlusPlus && !type->isDependentType() && Init &&
+  !Init->isValueDependent() &&
   (GlobalStorage || var->isConstexpr() ||
var->mightBeUsableInConstantExpressions(Context))) {
 // If this variable might have a constant initializer or might be usable in
@@ -13160,7 +13118,6 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl 
*var) {
 // do this lazily, because the result might depend on things that change
 // later, such as which constexpr functions happen to be defined.
 SmallVector Notes;
-bool HasConstInit;
 if (!getLangOpts().CPlusPlus11) {
   // Prior to C++11, in contexts where a constant initializer is required,
   // the set of valid constant initializers is described by syntactic rules
@@ -13225,6 +13182,57 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl 
*var) {
 }
   }

[PATCH] D102693: Do not create LLVM IR `constant`s for objects with dynamic initialisation

2021-05-25 Thread Momchil Velikov via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG21aa107eb79f: Reland "Do not create LLVM IR `constant`s 
for objects with dynamic… (authored by chill).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102693

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGenCXX/clang-sections-1.cpp
  clang/test/CodeGenCXX/const-dynamic-init.cpp

Index: clang/test/CodeGenCXX/const-dynamic-init.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/const-dynamic-init.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s | FileCheck %s
+
+__attribute__((section("A")))
+const int a = 1;
+const int *f() { return &a; }
+// CHECK: @_ZL1a = internal constant i32 1, section "A"
+
+int init();
+__attribute__((section("B")))
+const int b = init();
+// Even if it's const-qualified, it must not be LLVM IR `constant` since it's
+// dynamically initialised.
+// CHECK: @_ZL1b = internal global i32 0, section "B"
+
+__attribute__((section("C")))
+int c = 2;
+// CHECK: @c = {{.*}}global i32 2, section "C"
+
+__attribute__((section("D")))
+int d = init();
+// CHECK: @d = {{.*}}global i32 0, section "D"
+
+__attribute__((section("E")))
+int e;
+// CHECK: @e = {{.*}}global i32 0, section "E", align 4
Index: clang/test/CodeGenCXX/clang-sections-1.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/clang-sections-1.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s | FileCheck %s --check-prefix=LLVM
+// RUN: %clang_cc1 -triple x86_64-linux -S -o - %s | FileCheck %s --check-prefix=ASM
+// Actually, any ELF target would do
+// REQUIRES: x86_64-linux
+
+#pragma clang section bss = "B$$" data = "d@t@" rodata = "r0d@t@"
+
+const int a = 1;
+const int *f() { return &a; }
+
+int init();
+const int b = init();
+
+int c = 2;
+
+int d = init();
+
+int e;
+
+// LLVM: @_ZL1a = internal constant i32 1, align 4 #[[#A:]]
+// LLVM: @_ZL1b = internal global i32 0, align 4 #[[#A]]
+// LLVM: @c = {{.*}}global i32 2, align 4 #[[#A]]
+// LLVM: @d = {{.*}}global i32 0, align 4 #[[#A]]
+// LLVM: @e = {{.*}}global i32 0, align 4 #[[#A]]
+
+// LLVM: attributes #[[#A]] = { "bss-section"="B$$" "data-section"="d@t@" "rodata-section"="r0d@t@" }
+
+// ASM:   .section "r0d@t@","a",@progbits
+// ASM-NOT:   .section
+// ASM-LABEL: _ZL1a:
+// ASM-NEXT:  .long 1
+
+// ASM:   .section "B$$","aw",@nobits
+// ASM-NOT:   .section
+// ASM-LABEL: _ZL1b:
+// ASM-NEXT: .long 0
+
+// ASM:   .section "d@t@","aw",@progbits
+// ASM-NOT:   .section
+// ASM-LABEL: c:
+// ASM:   .long 2
+
+// ASM:   .section "B$$","aw",@nobits
+// ASM-NOT:   .section
+// ASM-LABEL: d:
+// ASM:   .long 0
+
+// ASM-NOT:   .section
+// ASM-LABEL: e:
+// ASM.long 0
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13047,43 +13047,6 @@
 }
   }
 
-  // Apply section attributes and pragmas to global variables.
-  bool GlobalStorage = var->hasGlobalStorage();
-  if (GlobalStorage && var->isThisDeclarationADefinition() &&
-  !inTemplateInstantiation()) {
-PragmaStack *Stack = nullptr;
-int SectionFlags = ASTContext::PSF_Read;
-if (var->getType().isConstQualified())
-  Stack = &ConstSegStack;
-else if (!var->getInit()) {
-  Stack = &BSSSegStack;
-  SectionFlags |= ASTContext::PSF_Write;
-} else {
-  Stack = &DataSegStack;
-  SectionFlags |= ASTContext::PSF_Write;
-}
-if (const SectionAttr *SA = var->getAttr()) {
-  if (SA->getSyntax() == AttributeCommonInfo::AS_Declspec)
-SectionFlags |= ASTContext::PSF_Implicit;
-  UnifySection(SA->getName(), SectionFlags, var);
-} else if (Stack->CurrentValue) {
-  SectionFlags |= ASTContext::PSF_Implicit;
-  auto SectionName = Stack->CurrentValue->getString();
-  var->addAttr(SectionAttr::CreateImplicit(
-  Context, SectionName, Stack->CurrentPragmaLocation,
-  AttributeCommonInfo::AS_Pragma, SectionAttr::Declspec_allocate));
-  if (UnifySection(SectionName, SectionFlags, var))
-var->dropAttr();
-}
-
-// Apply the init_seg attribute if this has an initializer.  If the
-// initializer turns out to not be dynamic, we'll end up ignoring this
-// attribute.
-if (CurInitSeg && var->getInit())
-  var->addAttr(InitSegAttr::CreateImplicit(Context, CurInitSeg->getString(),
-   CurInitSegLoc,
-   AttributeCommonInfo::AS_Pragma));
-  }
 
   if (!var->getType()->isStructureType() && var->hasInit() &&
   isa(var->getInit())) {
@@ -13133,14 +13096,6 @@

[clang] 8427053 - [clang][ARM] When handling multiple -mimplicit-it mark all as used

2021-05-25 Thread David Spickett via cfe-commits

Author: David Spickett
Date: 2021-05-25T14:53:07Z
New Revision: 8427053f81922b0665a1ad3f561c09f8c0b8dd30

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

LOG: [clang][ARM] When handling multiple -mimplicit-it mark all as used

Since 4468e5b8999291cc84b78f33f207dcd0e58146bc clang will prefer
the last one it finds of "-mimplicit-it" or "-Wa,-mimplicit-it".

Due to a mistake in that patch the compiler argument "-mimplicit-it"
was never marked as used, even if it was the last one and was passed
to llvm.

Move the Claim call back to the start of the loop and update
the testing to check we don't get any unused argument warnings.

Reviewed By: mstorsjo

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/arm-target-as-mimplicit-it.s

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 45b41c8bf53e..677e2b635354 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2410,6 +2410,8 @@ static void CollectArgsForIntegratedAssembler(Compilation 
&C,
   for (const Arg *A :
Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler,
  options::OPT_mimplicit_it_EQ)) {
+A->claim();
+
 if (A->getOption().getID() == options::OPT_mimplicit_it_EQ) {
   switch (C.getDefaultToolChain().getArch()) {
   case llvm::Triple::arm:
@@ -2427,8 +2429,6 @@ static void CollectArgsForIntegratedAssembler(Compilation 
&C,
   }
 }
 
-A->claim();
-
 for (StringRef Value : A->getValues()) {
   if (TakeNextArg) {
 CmdArgs.push_back(Value.data());

diff  --git a/clang/test/Driver/arm-target-as-mimplicit-it.s 
b/clang/test/Driver/arm-target-as-mimplicit-it.s
index eb02aa94e9ad..b4eed3e50632 100644
--- a/clang/test/Driver/arm-target-as-mimplicit-it.s
+++ b/clang/test/Driver/arm-target-as-mimplicit-it.s
@@ -35,6 +35,8 @@
 // RUN: %clang -target arm-linux-gnueabi -### 
-Wa,-mimplicit-it=always,-mimplicit-it=foo %s 2>&1 | FileCheck %s 
--check-prefix=INVALID
 
 
+/// Check that the argument we ignore is still marked as used.
+// ALWAYS-NOT: warning: argument unused during compilation: 
{{.*}}-mimplicit-it={{.*}}
 /// Check that there isn't a second -arm-implicit-it before or after the one
 /// that was the indended match.
 // ALWAYS-NOT: "-arm-implicit-it={{.*}}"



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


[PATCH] D103086: [clang][ARM] When handling multiple -mimplicit-it mark all as used

2021-05-25 Thread David Spickett via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8427053f8192: [clang][ARM] When handling multiple 
-mimplicit-it mark all as used (authored by DavidSpickett).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103086

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/arm-target-as-mimplicit-it.s


Index: clang/test/Driver/arm-target-as-mimplicit-it.s
===
--- clang/test/Driver/arm-target-as-mimplicit-it.s
+++ clang/test/Driver/arm-target-as-mimplicit-it.s
@@ -35,6 +35,8 @@
 // RUN: %clang -target arm-linux-gnueabi -### 
-Wa,-mimplicit-it=always,-mimplicit-it=foo %s 2>&1 | FileCheck %s 
--check-prefix=INVALID
 
 
+/// Check that the argument we ignore is still marked as used.
+// ALWAYS-NOT: warning: argument unused during compilation: 
{{.*}}-mimplicit-it={{.*}}
 /// Check that there isn't a second -arm-implicit-it before or after the one
 /// that was the indended match.
 // ALWAYS-NOT: "-arm-implicit-it={{.*}}"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2410,6 +2410,8 @@
   for (const Arg *A :
Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler,
  options::OPT_mimplicit_it_EQ)) {
+A->claim();
+
 if (A->getOption().getID() == options::OPT_mimplicit_it_EQ) {
   switch (C.getDefaultToolChain().getArch()) {
   case llvm::Triple::arm:
@@ -2427,8 +2429,6 @@
   }
 }
 
-A->claim();
-
 for (StringRef Value : A->getValues()) {
   if (TakeNextArg) {
 CmdArgs.push_back(Value.data());


Index: clang/test/Driver/arm-target-as-mimplicit-it.s
===
--- clang/test/Driver/arm-target-as-mimplicit-it.s
+++ clang/test/Driver/arm-target-as-mimplicit-it.s
@@ -35,6 +35,8 @@
 // RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=always,-mimplicit-it=foo %s 2>&1 | FileCheck %s --check-prefix=INVALID
 
 
+/// Check that the argument we ignore is still marked as used.
+// ALWAYS-NOT: warning: argument unused during compilation: {{.*}}-mimplicit-it={{.*}}
 /// Check that there isn't a second -arm-implicit-it before or after the one
 /// that was the indended match.
 // ALWAYS-NOT: "-arm-implicit-it={{.*}}"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2410,6 +2410,8 @@
   for (const Arg *A :
Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler,
  options::OPT_mimplicit_it_EQ)) {
+A->claim();
+
 if (A->getOption().getID() == options::OPT_mimplicit_it_EQ) {
   switch (C.getDefaultToolChain().getArch()) {
   case llvm::Triple::arm:
@@ -2427,8 +2429,6 @@
   }
 }
 
-A->claim();
-
 for (StringRef Value : A->getValues()) {
   if (TakeNextArg) {
 CmdArgs.push_back(Value.data());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D103087: [clang-tidy] performances-unnecessary-* checks: Extend isOnlyUsedAsConst to expressions and catch const methods returning non-const references/pointers.

2021-05-25 Thread Felix Berger via Phabricator via cfe-commits
flx created this revision.
flx added reviewers: aaron.ballman, hokein, ymandel.
Herald added a subscriber: xazax.hun.
flx requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

This change extends isOnlyUsedAsConst() to avoid false positives in cases where
a const method returns a mutable pointer or refernce and the pointed to object
is modified.

To achieve this we look at each const method or operator call and check if it
returns a mutable pointer/reference. If that's the case the call expression
itself is checked for constant use.

We also capture assignments of expressions to non-const references/pointers and
then check that the declared alias variables are used in a const-only fasion as
well.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103087

Files:
  clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
  clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.h
  clang-tools-extra/clang-tidy/utils/Matchers.h
  
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -6,6 +6,9 @@
   const ExpensiveToCopyType &reference() const;
   void nonConstMethod();
   bool constMethod() const;
+  ExpensiveToCopyType &operator*() const;
+  ExpensiveToCopyType *operator->() const;
+  ExpensiveToCopyType *get() const;
 };
 
 struct TrivialToCopyType {
@@ -508,3 +511,79 @@
   // CHECK-FIXES: const auto& UnnecessaryCopy = Ref.reference();
   Orig.constMethod();
 }
+
+void negativePointerIsModifiedThroughConstOperator() {
+  ExpensiveToCopyType Orig;
+  auto NecessaryCopy = Orig;
+  NecessaryCopy->nonConstMethod();
+}
+
+void negativeReferenceIsModifiedThroughConstOperator() {
+  ExpensiveToCopyType Orig;
+  auto NecessaryCopy = Orig;
+  (*NecessaryCopy).nonConstMethod();
+}
+
+void negativePointerIsModifiedThroughConstOperatorChain() {
+  ExpensiveToCopyType Orig;
+  auto NecessaryCopy = Orig;
+  (*NecessaryCopy)->nonConstMethod();
+}
+
+void positivePointerIsNotModifiedThroughConstOperator() {
+  ExpensiveToCopyType Orig;
+  auto UnnecessaryCopy = Orig;
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: local copy 'UnnecessaryCopy' of the variable 'Orig' is never modified;
+  // CHECK-FIXES: const auto& UnnecessaryCopy = Orig;
+  UnnecessaryCopy->constMethod();
+}
+
+void positiveReferenceIsNotModifiedThroughConstOperator() {
+  ExpensiveToCopyType Orig;
+  auto UnnecessaryCopy = Orig;
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: local copy 'UnnecessaryCopy' of the variable 'Orig' is never modified;
+  // CHECK-FIXES: const auto& UnnecessaryCopy = Orig;
+  (*UnnecessaryCopy).constMethod();
+}
+
+void negativeReferenceIsAssignedToVarAndModified() {
+  ExpensiveToCopyType Orig;
+  auto NecessaryCopy = Orig;
+  auto &Ref = *NecessaryCopy;
+  Ref.nonConstMethod();
+}
+
+void positiveReferenceIsAssignedToVarAndNotModified() {
+  ExpensiveToCopyType Orig;
+  auto UnnecessaryCopy = Orig;
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: local copy 'UnnecessaryCopy' of the variable 'Orig' is never modified;
+  // CHECK-FIXES: const auto& UnnecessaryCopy = Orig;
+  auto &Ref = *UnnecessaryCopy;
+  Ref.constMethod();
+}
+
+void negativePointerIsAssignedToVarAndModified() {
+  ExpensiveToCopyType Orig;
+  auto NecessaryCopy = Orig;
+  auto *Pointer = NecessaryCopy.get();
+  Pointer->nonConstMethod();
+}
+
+void positivePointerIsAssignedToVarAndNotModified() {
+  ExpensiveToCopyType Orig;
+  auto UnnecessaryCopy = Orig;
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: local copy 'UnnecessaryCopy' of the variable 'Orig' is never modified;
+  // CHECK-FIXES: const auto& UnnecessaryCopy = Orig;
+  auto *Pointer = UnnecessaryCopy.get();
+  Pointer->constMethod();
+}
+
+void positiveConstMethodReturningPointer() {
+  ExpensiveToCopyType Orig;
+  auto UnnecessaryCopy = Orig;
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: local copy 'UnnecessaryCopy' of the variable 'Orig' is never modified;
+  // CHECK-FIXES: const auto& UnnecessaryCopy = Orig;
+  // Test that a const method that returns a mutable pointer/reference that is
+  // unused counts as a const use.
+  UnnecessaryCopy.get();
+}
Index: clang-tools-extra/clang-tidy/utils/Matchers.h
===
--- clang-tools-extra/clang-tidy/utils/Matchers.h
+++ clang-tools-extra/clang-tidy/utils/Matchers.h
@@ -43,12 +43,24 @@
   return referenceType(pointee(qualType(isConstQualified(;
 }
 
+AST_MATCHER_FUNCTION(ast_matchers::TypeMatcher, isReferenceToNonConst) {
+  using namespace ast_matchers;
+  return allOf(referenceType(),
+   referenceType(pointee(qualType

[PATCH] D98895: [X86][Draft] Disable long double type for -mno-x87 option

2021-05-25 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/test/Sema/x86-no-x87.c:2
+// RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-linux-gnu 
-target-feature -x87
+// RUN: %clang_cc1 -fsyntax-only -verify %s -triple i686-linux-gnu 
-target-feature -x87
+// RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-windows-msvc 
-target-feature -x87 -DNOERROR

asavonic wrote:
> pengfei wrote:
> > Should i686 expect no error like GCC?
> GCC seems to fallback to soft-float for i686 if -mno-80387 is used:
> 
>   long double orig(long double x, long double y)
>   {
> long double z = x + y;
> if (z < 0.0)
>   return z;
> else
>   return 0.0;
>   }
> 
> i686-linux-gnu-gcc-8 -c -S -mno-80387 -O3:
> call  __addxf3@PLT
> [...]
> call  __ltxf2@PLT
> addl  $32, %esp
> testl %eax, %eax
> js.L3
> xorl  %esi, %esi
> xorl  %edi, %edi
> xorl  %ebp, %ebp
>   .L3:
> addl  $12, %esp
> movl  %esi, %eax
> movl  %edi, %edx
> movl  %ebp, %ecx
> popl  %ebx
> popl  %esi
> popl  %edi
> popl  %ebp
> ret
> 
> This looks like a different ABI.
> X87 instructions are not used, so no error is reported.
> 
I found it's a bit complex for 32 bits.
1. i686 ABI specifies the return of floating point type must be put in %st0, so 
any FP type returning should be error out w/o x87.
2. GCC doesn't respect above ABI.
3. FP types are passed from stack, so a function like `void orig(long double x, 
long double y, long double *z)` should not be error out w/o x87. 
x86_64 only uses ST registers when returning FP80.
Considering it is rare for case 3, I think we can ignore it this time, but I 
suggest we should add check for float and double on 32 bits.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98895

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


[PATCH] D103086: [clang][ARM] When handling multiple -mimplicit-it mark all as used

2021-05-25 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo accepted this revision.
mstorsjo added a comment.
This revision is now accepted and ready to land.

LGTM, and sorry for not testning this aspect in the updated version of the 
patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103086

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


[PATCH] D103086: [clang][ARM] When handling multiple -mimplcit-it mark all as used

2021-05-25 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a reviewer: mstorsjo.
DavidSpickett added a comment.

You could argue that one of them is actually "unused" but I tried `-march` 
which also takes the last value and that does not warn when it ignores earlier 
values.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103086

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


[PATCH] D103086: [clang][ARM] When handling multiple -mimplcit-it mark all as used

2021-05-25 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett created this revision.
Herald added subscribers: danielkiss, kristof.beyls.
DavidSpickett requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Since 4468e5b8999291cc84b78f33f207dcd0e58146bc 
 clang 
will prefer
the last one it finds of "-mimplicit-it" or "-Wa,-mimplicit-it".

Due to a mistake in that patch the compiler argument "-mimplicit-it"
was never marked as used, even if it was the last one and was passed
to llvm.

Move the Claim call back to the start of the loop and update
the testing to check we don't get any unused argument warnings.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103086

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/arm-target-as-mimplicit-it.s


Index: clang/test/Driver/arm-target-as-mimplicit-it.s
===
--- clang/test/Driver/arm-target-as-mimplicit-it.s
+++ clang/test/Driver/arm-target-as-mimplicit-it.s
@@ -35,6 +35,8 @@
 // RUN: %clang -target arm-linux-gnueabi -### 
-Wa,-mimplicit-it=always,-mimplicit-it=foo %s 2>&1 | FileCheck %s 
--check-prefix=INVALID
 
 
+/// Check that the argument we ignore is still marked as used.
+// ALWAYS-NOT: warning: argument unused during compilation: 
{{.*}}-mimplicit-it={{.*}}
 /// Check that there isn't a second -arm-implicit-it before or after the one
 /// that was the indended match.
 // ALWAYS-NOT: "-arm-implicit-it={{.*}}"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2410,6 +2410,8 @@
   for (const Arg *A :
Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler,
  options::OPT_mimplicit_it_EQ)) {
+A->claim();
+
 if (A->getOption().getID() == options::OPT_mimplicit_it_EQ) {
   switch (C.getDefaultToolChain().getArch()) {
   case llvm::Triple::arm:
@@ -2427,8 +2429,6 @@
   }
 }
 
-A->claim();
-
 for (StringRef Value : A->getValues()) {
   if (TakeNextArg) {
 CmdArgs.push_back(Value.data());


Index: clang/test/Driver/arm-target-as-mimplicit-it.s
===
--- clang/test/Driver/arm-target-as-mimplicit-it.s
+++ clang/test/Driver/arm-target-as-mimplicit-it.s
@@ -35,6 +35,8 @@
 // RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=always,-mimplicit-it=foo %s 2>&1 | FileCheck %s --check-prefix=INVALID
 
 
+/// Check that the argument we ignore is still marked as used.
+// ALWAYS-NOT: warning: argument unused during compilation: {{.*}}-mimplicit-it={{.*}}
 /// Check that there isn't a second -arm-implicit-it before or after the one
 /// that was the indended match.
 // ALWAYS-NOT: "-arm-implicit-it={{.*}}"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2410,6 +2410,8 @@
   for (const Arg *A :
Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler,
  options::OPT_mimplicit_it_EQ)) {
+A->claim();
+
 if (A->getOption().getID() == options::OPT_mimplicit_it_EQ) {
   switch (C.getDefaultToolChain().getArch()) {
   case llvm::Triple::arm:
@@ -2427,8 +2429,6 @@
   }
 }
 
-A->claim();
-
 for (StringRef Value : A->getValues()) {
   if (TakeNextArg) {
 CmdArgs.push_back(Value.data());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 16e78ec - [Headers][WASM] adjust test that runs the optimizer; NFC

2021-05-25 Thread Sanjay Patel via cfe-commits

Author: Sanjay Patel
Date: 2021-05-25T09:17:10-04:00
New Revision: 16e78ec0b43c33c818525ea9b5d39731022f1cbb

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

LOG: [Headers][WASM] adjust test that runs the optimizer; NFC

This broke with the LLVM change in 0bab0f616119

Added: 


Modified: 
clang/test/Headers/wasm.c

Removed: 




diff  --git a/clang/test/Headers/wasm.c b/clang/test/Headers/wasm.c
index 8b87eb2c0e2e..c170e75259d1 100644
--- a/clang/test/Headers/wasm.c
+++ b/clang/test/Headers/wasm.c
@@ -1,6 +1,8 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --force-update
 // REQUIRES: webassembly-registered-target, asserts
 
+// FIXME: This should not be using -O2 and implicitly testing the entire IR 
opt pipeline.
+
 // RUN: %clang %s -O2 -emit-llvm -S -o - -target wasm32-unknown-unknown 
-msimd128 -Wcast-qual -fno-lax-vector-conversions -Werror | FileCheck %s
 
 #include 
@@ -582,7 +584,7 @@ v128_t test_i64x2_replace_lane(v128_t a, int64_t b) {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[VECINIT_I:%.*]] = insertelement <4 x float> undef, float 
[[A:%.*]], i32 0
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x float> [[VECINIT_I]] to <4 x i32>
-// CHECK-NEXT:[[TMP1:%.*]] = shufflevector <4 x i32> [[TMP0]], <4 x i32> 
poison, <4 x i32> zeroinitializer
+// CHECK-NEXT:[[TMP1:%.*]] = shufflevector <4 x i32> [[TMP0]], <4 x i32> 
undef, <4 x i32> zeroinitializer
 // CHECK-NEXT:ret <4 x i32> [[TMP1]]
 //
 v128_t test_f32x4_splat(float a) {



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


[PATCH] D99797: [analyzer] Implemented RangeSet::Factory::unite function to handle intersections and adjacency

2021-05-25 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 347662.
ASDenysPetrov added a comment.

More minor improvements in unit tests.


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

https://reviews.llvm.org/D99797

Files:
  
clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/unittests/StaticAnalyzer/RangeSetTest.cpp

Index: clang/unittests/StaticAnalyzer/RangeSetTest.cpp
===
--- clang/unittests/StaticAnalyzer/RangeSetTest.cpp
+++ clang/unittests/StaticAnalyzer/RangeSetTest.cpp
@@ -41,6 +41,23 @@
 
 namespace {
 
+template  struct TestValues {
+  static constexpr T MIN = std::numeric_limits::min();
+  static constexpr T MAX = std::numeric_limits::max();
+  // MID is a value in the middle of the range
+  // which unary minus does not affect on,
+  // e.g. int8/int32(0), uint8(128), uint32(2147483648).
+  static constexpr T MID =
+  std::is_signed::value ? 0 : ~(static_cast(-1) / static_cast(2));
+  static constexpr T A = MID - (MAX - MID) / 3 * 2;
+  static constexpr T B = MID - (MAX - MID) / 3;
+  static constexpr T C = -B;
+  static constexpr T D = -A;
+
+  static_assert(MIN < A && A < B && B < MID && MID < C && C < D && D < MAX,
+"Values shall be in an ascending order");
+};
+
 template  class RangeSetTest : public testing::Test {
 public:
   // Init block
@@ -55,24 +72,11 @@
   using RawRange = std::pair;
   using RawRangeSet = std::initializer_list;
 
-  static constexpr BaseType getMin() {
-return std::numeric_limits::min();
-  }
-  static constexpr BaseType getMax() {
-return std::numeric_limits::max();
-  }
-  static constexpr BaseType getMid() {
-return isSigned() ? 0 : ~(fromInt(-1) / fromInt(2));
-  }
-
-  static constexpr bool isSigned() { return std::is_signed::value; }
-  static constexpr BaseType fromInt(int X) { return static_cast(X); }
-
-  static llvm::APSInt Base;
   const llvm::APSInt &from(BaseType X) {
-llvm::APSInt Dummy = Base;
-Dummy = X;
-return BVF.getValue(Dummy);
+static llvm::APSInt Base{sizeof(BaseType) * 8,
+ std::is_unsigned::value};
+Base = X;
+return BVF.getValue(Base);
   }
 
   Range from(const RawRange &Init) {
@@ -160,7 +164,7 @@
 
   void checkAdd(RawRangeSet RawLHS, RawRangeSet RawRHS,
 RawRangeSet RawExpected) {
-wrap(&Self::checkAddImpl, RawRHS, RawLHS, RawExpected);
+wrap(&Self::checkAddImpl, RawLHS, RawRHS, RawExpected);
   }
 
   void checkAdd(RawRangeSet RawLHS, BaseType RawRHS, RawRangeSet RawExpected) {
@@ -168,6 +172,29 @@
  RawExpected);
   }
 
+  template 
+  void checkUniteImpl(RangeSet LHS, RHSType RHS, RangeSet Expected) {
+RangeSet Result = F.unite(LHS, RHS);
+EXPECT_EQ(Result, Expected)
+<< "while uniting " << toString(LHS) << " and " << toString(RHS);
+  }
+
+  void checkUnite(RawRangeSet RawLHS, RawRange RawRHS,
+  RawRangeSet RawExpected) {
+wrap(&Self::checkUniteImpl, RawLHS, RawRHS, RawExpected);
+  }
+
+  void checkUnite(RawRangeSet RawLHS, RawRangeSet RawRHS,
+  RawRangeSet RawExpected) {
+wrap(&Self::checkUniteImpl, RawLHS, RawRHS, RawExpected);
+  }
+
+  void checkUnite(RawRangeSet RawLHS, BaseType RawRHS,
+  RawRangeSet RawExpected) {
+wrap(&Self::checkUniteImpl, RawLHS, RawRHS,
+ RawExpected);
+  }
+
   void checkDeleteImpl(const llvm::APSInt &Point, RangeSet From,
RangeSet Expected) {
 RangeSet Result = F.deletePoint(From, Point);
@@ -183,29 +210,19 @@
 
 } // namespace
 
-template 
-llvm::APSInt RangeSetTest::Base{sizeof(BaseType) * 8, !isSigned()};
-
 using IntTypes = ::testing::Types;
 TYPED_TEST_CASE(RangeSetTest, IntTypes);
 
 TYPED_TEST(RangeSetTest, RangeSetNegateTest) {
-  // Use next values of the range {MIN, A, B, MID, C, D, MAX}.
-
-  constexpr TypeParam MIN = TestFixture::getMin();
-  constexpr TypeParam MAX = TestFixture::getMax();
-  // MID is a value in the middle of the range
-  // which unary minus does not affect on,
-  // e.g. int8/int32(0), uint8(128), uint32(2147483648).
-  constexpr TypeParam MID = TestFixture::getMid();
-  constexpr TypeParam A = MID - TestFixture::fromInt(42 + 42);
-  constexpr TypeParam B = MID - TestFixture::fromInt(42);
-  constexpr TypeParam C = -B;
-  constexpr TypeParam D = -A;
-
-  static_assert(MIN < A && A < B && B < MID && MID < C && C < D && D < MAX,
-"Values shall be in an ascending order");
+  using TV = TestValues;
+  constexpr auto MIN = TV::MIN;
+  constexpr auto MAX = TV::MAX;
+  constexpr auto MID = TV::MID;
+  constexpr auto A = TV::A;
+  constexpr auto B = TV::B;
+  constexpr auto C = TV::C;
+  constexpr auto D = TV::D;
 
   this->checkNegate({{MIN, A}}, {{MIN, MIN}, {D, MAX}});
   this->checkNegate({{MIN, C}}, {{MIN, MIN}, {B, MAX}});
@@ -234,8 +251,9 @@
 }
 
 TYPED_TEST(Ran

[PATCH] D99797: [analyzer] Implemented RangeSet::Factory::unite function to handle intersections and adjacency

2021-05-25 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 347658.
ASDenysPetrov added a comment.

Minor improvements in unit tests.


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

https://reviews.llvm.org/D99797

Files:
  
clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/unittests/StaticAnalyzer/RangeSetTest.cpp

Index: clang/unittests/StaticAnalyzer/RangeSetTest.cpp
===
--- clang/unittests/StaticAnalyzer/RangeSetTest.cpp
+++ clang/unittests/StaticAnalyzer/RangeSetTest.cpp
@@ -41,6 +41,23 @@
 
 namespace {
 
+template  struct TestValues {
+  static constexpr T MIN = std::numeric_limits::min();
+  static constexpr T MAX = std::numeric_limits::max();
+  // MID is a value in the middle of the range
+  // which unary minus does not affect on,
+  // e.g. int8/int32(0), uint8(128), uint32(2147483648).
+  static constexpr T MID =
+  std::is_signed::value ? 0 : ~(static_cast(-1) / static_cast(2));
+  static constexpr T A = MID - (MAX - MID) / 3 * 2;
+  static constexpr T B = MID - (MAX - MID) / 3;
+  static constexpr T C = -B;
+  static constexpr T D = -A;
+
+  static_assert(MIN < A && A < B && B < MID && MID < C && C < D && D < MAX,
+"Values shall be in an ascending order");
+};
+
 template  class RangeSetTest : public testing::Test {
 public:
   // Init block
@@ -55,18 +72,14 @@
   using RawRange = std::pair;
   using RawRangeSet = std::initializer_list;
 
-  static constexpr BaseType getMin() {
-return std::numeric_limits::min();
-  }
-  static constexpr BaseType getMax() {
-return std::numeric_limits::max();
-  }
-  static constexpr BaseType getMid() {
-return isSigned() ? 0 : ~(fromInt(-1) / fromInt(2));
-  }
-
-  static constexpr bool isSigned() { return std::is_signed::value; }
-  static constexpr BaseType fromInt(int X) { return static_cast(X); }
+  using TV = TestValues;
+  static constexpr auto MIN = TV::MIN;
+  static constexpr auto MAX = TV::MAX;
+  static constexpr auto MID = TV::MID;
+  static constexpr auto A = TV::A;
+  static constexpr auto B = TV::B;
+  static constexpr auto C = TV::C;
+  static constexpr auto D = TV::D;
 
   static llvm::APSInt Base;
   const llvm::APSInt &from(BaseType X) {
@@ -160,7 +173,7 @@
 
   void checkAdd(RawRangeSet RawLHS, RawRangeSet RawRHS,
 RawRangeSet RawExpected) {
-wrap(&Self::checkAddImpl, RawRHS, RawLHS, RawExpected);
+wrap(&Self::checkAddImpl, RawLHS, RawRHS, RawExpected);
   }
 
   void checkAdd(RawRangeSet RawLHS, BaseType RawRHS, RawRangeSet RawExpected) {
@@ -168,6 +181,29 @@
  RawExpected);
   }
 
+  template 
+  void checkUniteImpl(RangeSet LHS, RHSType RHS, RangeSet Expected) {
+RangeSet Result = F.unite(LHS, RHS);
+EXPECT_EQ(Result, Expected)
+<< "while uniting " << toString(LHS) << " and " << toString(RHS);
+  }
+
+  void checkUnite(RawRangeSet RawLHS, RawRange RawRHS,
+  RawRangeSet RawExpected) {
+wrap(&Self::checkUniteImpl, RawLHS, RawRHS, RawExpected);
+  }
+
+  void checkUnite(RawRangeSet RawLHS, RawRangeSet RawRHS,
+  RawRangeSet RawExpected) {
+wrap(&Self::checkUniteImpl, RawLHS, RawRHS, RawExpected);
+  }
+
+  void checkUnite(RawRangeSet RawLHS, BaseType RawRHS,
+  RawRangeSet RawExpected) {
+wrap(&Self::checkUniteImpl, RawLHS, RawRHS,
+ RawExpected);
+  }
+
   void checkDeleteImpl(const llvm::APSInt &Point, RangeSet From,
RangeSet Expected) {
 RangeSet Result = F.deletePoint(From, Point);
@@ -184,7 +220,8 @@
 } // namespace
 
 template 
-llvm::APSInt RangeSetTest::Base{sizeof(BaseType) * 8, !isSigned()};
+llvm::APSInt RangeSetTest::Base{sizeof(BaseType) * 8,
+  std::is_unsigned::value};
 
 using IntTypes = ::testing::Types;
@@ -192,17 +229,13 @@
 
 TYPED_TEST(RangeSetTest, RangeSetNegateTest) {
   // Use next values of the range {MIN, A, B, MID, C, D, MAX}.
-
-  constexpr TypeParam MIN = TestFixture::getMin();
-  constexpr TypeParam MAX = TestFixture::getMax();
-  // MID is a value in the middle of the range
-  // which unary minus does not affect on,
-  // e.g. int8/int32(0), uint8(128), uint32(2147483648).
-  constexpr TypeParam MID = TestFixture::getMid();
-  constexpr TypeParam A = MID - TestFixture::fromInt(42 + 42);
-  constexpr TypeParam B = MID - TestFixture::fromInt(42);
-  constexpr TypeParam C = -B;
-  constexpr TypeParam D = -A;
+  constexpr TypeParam MIN = TestFixture::MIN;
+  constexpr TypeParam MAX = TestFixture::MAX;
+  constexpr TypeParam MID = TestFixture::MID;
+  constexpr TypeParam A = TestFixture::A;
+  constexpr TypeParam B = TestFixture::B;
+  constexpr TypeParam C = TestFixture::C;
+  constexpr TypeParam D = TestFixture::D;
 
   static_assert(MIN < A && A < B && B < MID && MID < C && C < D && D < MAX,
 "Values shall be in an a

[PATCH] D98895: [X86][Draft] Disable long double type for -mno-x87 option

2021-05-25 Thread Andrew Savonichev via Phabricator via cfe-commits
asavonic added inline comments.



Comment at: clang/test/Sema/x86-no-x87.c:2
+// RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-linux-gnu 
-target-feature -x87
+// RUN: %clang_cc1 -fsyntax-only -verify %s -triple i686-linux-gnu 
-target-feature -x87
+// RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-windows-msvc 
-target-feature -x87 -DNOERROR

pengfei wrote:
> Should i686 expect no error like GCC?
GCC seems to fallback to soft-float for i686 if -mno-80387 is used:

  long double orig(long double x, long double y)
  {
long double z = x + y;
if (z < 0.0)
  return z;
else
  return 0.0;
  }

i686-linux-gnu-gcc-8 -c -S -mno-80387 -O3:
  call  __addxf3@PLT
  [...]
  call  __ltxf2@PLT
  addl  $32, %esp
  testl %eax, %eax
  js.L3
  xorl  %esi, %esi
  xorl  %edi, %edi
  xorl  %ebp, %ebp
  .L3:
  addl  $12, %esp
  movl  %esi, %eax
  movl  %edi, %edx
  movl  %ebp, %ecx
  popl  %ebx
  popl  %esi
  popl  %edi
  popl  %ebp
  ret

This looks like a different ABI.
X87 instructions are not used, so no error is reported.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98895

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


[PATCH] D103082: [AArch64][SVE] Optimize svbool dupq ACLE intrinsic to fixed predicate patterns

2021-05-25 Thread Bradley Smith via Phabricator via cfe-commits
bsmith created this revision.
bsmith added reviewers: paulwalker-arm, peterwaller-arm, joechrisellis, 
sdesmalen.
Herald added subscribers: psnobl, hiraditya, kristof.beyls, tschuett.
Herald added a reviewer: efriedma.
bsmith requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This patch introduces a new dupq LLVM intrinsic which is emitted upon
encountering the svbool dupq ACLE intrinsics, instead of expanding them
directly.

This allows us to defer the expansion of said intrinsic until much
later when we can reasonably optimize to fixed predicates using ptrue.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103082

Files:
  clang/include/clang/Basic/arm_sve.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.h
  llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
  llvm/test/CodeGen/AArch64/sve-intrinsics-dupq.ll
  llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-opts-dupq.ll

Index: llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-opts-dupq.ll
===
--- /dev/null
+++ llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-opts-dupq.ll
@@ -0,0 +1,195 @@
+; RUN: opt -S -instcombine < %s | FileCheck %s
+
+target triple = "aarch64-unknown-linux-gnu"
+
+; DUPQ b8
+
+define  @dupq_b_0() #0 {
+; CHECK-LABEL: @dupq_b_0(
+; CHECK: ret  zeroinitializer
+  %1 = tail call  @llvm.aarch64.sve.dupq.b8(i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false,
+  i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false)
+  ret  %1
+}
+
+define  @dupq_b_d() #0 {
+; CHECK-LABEL: @dupq_b_d(
+; CHECK: %1 = call  @llvm.aarch64.sve.ptrue.nxv2i1(i32 31)
+; CHECK-NEXT: %2 = call  @llvm.aarch64.sve.convert.to.svbool.nxv2i1( %1)
+; CHECK-NEXT: ret  %2
+  %1 = tail call  @llvm.aarch64.sve.dupq.b8(i1 true, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false,
+  i1 true, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false)
+  ret  %1
+}
+
+define  @dupq_b_w() #0 {
+; CHECK-LABEL: @dupq_b_w(
+; CHECK: %1 = call  @llvm.aarch64.sve.ptrue.nxv4i1(i32 31)
+; CHECK-NEXT: %2 = call  @llvm.aarch64.sve.convert.to.svbool.nxv4i1( %1)
+; CHECK-NEXT: ret  %2
+  %1 = tail call  @llvm.aarch64.sve.dupq.b8(i1 true, i1 false, i1 false, i1 false, i1 true, i1 false, i1 false, i1 false,
+  i1 true, i1 false, i1 false, i1 false, i1 true, i1 false, i1 false, i1 false)
+  ret  %1
+}
+
+define  @dupq_b_h() #0 {
+; CHECK-LABEL: @dupq_b_h(
+; CHECK: %1 = call  @llvm.aarch64.sve.ptrue.nxv8i1(i32 31)
+; CHECK-NEXT: %2 = call  @llvm.aarch64.sve.convert.to.svbool.nxv8i1( %1)
+; CHECK-NEXT: ret  %2
+  %1 = tail call  @llvm.aarch64.sve.dupq.b8(i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false,
+  i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false)
+  ret  %1
+}
+
+define  @dupq_b_b() #0 {
+; CHECK-LABEL: @dupq_b_b(
+; CHECK: %1 = call  @llvm.aarch64.sve.ptrue.nxv16i1(i32 31)
+; CHECK-NEXT: ret  %1
+  %1 = tail call  @llvm.aarch64.sve.dupq.b8(i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true,
+  i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true)
+  ret  %1
+}
+
+; DUPQ b16
+
+define  @dupq_h_0() #0 {
+; CHECK-LABEL: @dupq_h_0(
+; CHECK: ret  zeroinitializer
+  %1 = tail call  @llvm.aarch64.sve.dupq.b16(i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false)
+  ret  %1
+}
+
+define  @dupq_h_d() #0 {
+; CHECK-LABEL: @dupq_h_d(
+; CHECK: %1 = call  @llvm.aarch64.sve.ptrue.nxv2i1(i32 31)
+; CHECK-NEXT: %2 = call  @llvm.aarch64.sve.convert.to.svbool.nxv2i1( %1)
+; CHECK-NEXT: %3 = call  @llvm.aarch64.sve.convert.from.svbool.nxv8i1( %2)
+; CHECK-NEXT: ret  %3
+  %1 = tail call  @llvm.aarch64.sve.dupq.b16(i1 true, i1 false, i1 false, i1 false, i1 true, i1 false, i1 false, i1 false)
+  ret  %1
+}
+
+define  @dupq_h_w() #0 {
+; CHECK-LABEL: @dupq_h_w(
+; CHECK: %1 = call  @llvm.aarch64.sve.ptrue.nxv4i1(i32 31)
+; CHECK-NEXT: %2 = call  @llvm.aarch64.sve.convert.to.svbool.nxv4i1( %1)
+; CHECK-NEXT: %3 = call  @llvm.aarch64.sve.convert.from.svbool.nxv8i1( %2)
+; CHECK-NEXT: ret  %3
+  %1 = tail call  @llvm.aarch64.sve.dupq.b16(i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false)
+  ret  %1
+}
+
+define  @dupq_h_h() #0 {
+; CHECK-LABEL: @dupq_h_h(
+; CHECK: %1 = call  @llvm.aarch64.sve.ptrue.nxv8i1(i32 31)
+; CHECK-NEXT: ret  

[PATCH] D103081: RetainCountChecker: Disable reference counting for OSMetaClass.

2021-05-25 Thread Georgeta Igna via Phabricator via cfe-commits
georgi_igna created this revision.
georgi_igna requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103081

Files:
  clang/lib/Analysis/RetainSummaryManager.cpp
  clang/test/Analysis/os_object_base.h
  clang/test/Analysis/osobject-retain-release.cpp


Index: clang/test/Analysis/osobject-retain-release.cpp
===
--- clang/test/Analysis/osobject-retain-release.cpp
+++ clang/test/Analysis/osobject-retain-release.cpp
@@ -720,6 +720,16 @@
   obj->release();
 }
 
+void test_osmetaclass_release(){
+const char *name = "no_name";
+const OSMetaClass *meta = OSMetaClass::copyMetaClassWithName(name);
+if (!meta) {
+return;
+} else {
+meta->releaseMetaClass();
+}
+}
+
 OSObject *getRuleViolation() {
   return new OSObject; // expected-warning{{Potential leak of an object of 
type 'OSObject'}}
 // expected-note@-1{{Operator 'new' returns an OSObject of type 'OSObject' 
with a +1 retain count}}
Index: clang/test/Analysis/os_object_base.h
===
--- clang/test/Analysis/os_object_base.h
+++ clang/test/Analysis/os_object_base.h
@@ -67,6 +67,8 @@
 struct OSMetaClass : public OSMetaClassBase {
   virtual OSObject * alloc() const;
   static OSObject * allocClassWithName(const char * name);
+  static const OSMetaClass * copyMetaClassWithName(const char * name);
+  void releaseMetaClass() const;
   virtual ~OSMetaClass(){}
 };
 
Index: clang/lib/Analysis/RetainSummaryManager.cpp
===
--- clang/lib/Analysis/RetainSummaryManager.cpp
+++ clang/lib/Analysis/RetainSummaryManager.cpp
@@ -145,14 +145,20 @@
   return !(match(SubclassM, *D, D->getASTContext()).empty());
 }
 
-static bool isOSObjectSubclass(const Decl *D) {
-  return D && isSubclass(D, "OSMetaClassBase");
+static bool isExactClass(const Decl *D, StringRef ClassName) {
+  using namespace ast_matchers;
+  DeclarationMatcher sameClassM =
+  cxxRecordDecl(hasName(std::string(ClassName)));
+  return !(match(sameClassM, *D, D->getASTContext()).empty());
 }
 
-static bool isOSObjectDynamicCast(StringRef S) {
-  return S == "safeMetaCast";
+static bool isOSObjectSubclass(const Decl *D) {
+  return D && isSubclass(D, "OSMetaClassBase") &&
+ !isExactClass(D, "OSMetaClass");
 }
 
+static bool isOSObjectDynamicCast(StringRef S) { return S == "safeMetaCast"; }
+
 static bool isOSObjectRequiredCast(StringRef S) {
   return S == "requiredMetaCast";
 }


Index: clang/test/Analysis/osobject-retain-release.cpp
===
--- clang/test/Analysis/osobject-retain-release.cpp
+++ clang/test/Analysis/osobject-retain-release.cpp
@@ -720,6 +720,16 @@
   obj->release();
 }
 
+void test_osmetaclass_release(){
+const char *name = "no_name";
+const OSMetaClass *meta = OSMetaClass::copyMetaClassWithName(name);
+if (!meta) {
+return;
+} else {
+meta->releaseMetaClass();
+}
+}
+
 OSObject *getRuleViolation() {
   return new OSObject; // expected-warning{{Potential leak of an object of type 'OSObject'}}
 // expected-note@-1{{Operator 'new' returns an OSObject of type 'OSObject' with a +1 retain count}}
Index: clang/test/Analysis/os_object_base.h
===
--- clang/test/Analysis/os_object_base.h
+++ clang/test/Analysis/os_object_base.h
@@ -67,6 +67,8 @@
 struct OSMetaClass : public OSMetaClassBase {
   virtual OSObject * alloc() const;
   static OSObject * allocClassWithName(const char * name);
+  static const OSMetaClass * copyMetaClassWithName(const char * name);
+  void releaseMetaClass() const;
   virtual ~OSMetaClass(){}
 };
 
Index: clang/lib/Analysis/RetainSummaryManager.cpp
===
--- clang/lib/Analysis/RetainSummaryManager.cpp
+++ clang/lib/Analysis/RetainSummaryManager.cpp
@@ -145,14 +145,20 @@
   return !(match(SubclassM, *D, D->getASTContext()).empty());
 }
 
-static bool isOSObjectSubclass(const Decl *D) {
-  return D && isSubclass(D, "OSMetaClassBase");
+static bool isExactClass(const Decl *D, StringRef ClassName) {
+  using namespace ast_matchers;
+  DeclarationMatcher sameClassM =
+  cxxRecordDecl(hasName(std::string(ClassName)));
+  return !(match(sameClassM, *D, D->getASTContext()).empty());
 }
 
-static bool isOSObjectDynamicCast(StringRef S) {
-  return S == "safeMetaCast";
+static bool isOSObjectSubclass(const Decl *D) {
+  return D && isSubclass(D, "OSMetaClassBase") &&
+ !isExactClass(D, "OSMetaClass");
 }
 
+static bool isOSObjectDynamicCast(StringRef S) { return S == "safeMetaCast"; }
+
 static bool isOSObjectRequiredCast(StringRef S) {
   return S == "requiredMetaCast";
 }

[PATCH] D102839: [RISCV][Clang] Add -mno-div option to disable hardware int division

2021-05-25 Thread ksyx via Phabricator via cfe-commits
ksyx updated this revision to Diff 347637.
ksyx added a comment.

fix: indent


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

https://reviews.llvm.org/D102839

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-no-div.c
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfoM.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/no-div.ll
  llvm/test/MC/RISCV/rv32m-no-div-div.s
  llvm/test/MC/RISCV/rv32m-no-div-mul.s
  llvm/test/MC/RISCV/rv64m-no-div-div.s
  llvm/test/MC/RISCV/rv64m-no-div-mul.s

Index: llvm/test/MC/RISCV/rv64m-no-div-mul.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64m-no-div-mul.s
@@ -0,0 +1,5 @@
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+m,+no-div -riscv-no-aliases 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-INST %s
+
+# CHECK-INST: mulw ra, sp, gp
+mulw ra, sp, gp
Index: llvm/test/MC/RISCV/rv64m-no-div-div.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64m-no-div-div.s
@@ -0,0 +1,14 @@
+# RUN: not llvm-mc %s -triple=riscv64 -mattr=+m,+no-div -riscv-no-aliases 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-ERROR %s
+
+# CHECK-ERROR: 5:1: error: instruction requires the following: Hardware integral division not disabled
+divw tp, t0, t1
+
+# CHECK-ERROR: 8:1: error: instruction requires the following: Hardware integral division not disabled
+divuw t2, s0, s2
+
+# CHECK-ERROR: 11:1: error: instruction requires the following: Hardware integral division not disabled
+remw a0, a1, a2
+
+# CHECK-ERROR: 14:1: error: instruction requires the following: Hardware integral division not disabled
+remuw a3, a4, a5
Index: llvm/test/MC/RISCV/rv32m-no-div-mul.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32m-no-div-mul.s
@@ -0,0 +1,14 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+m,+no-div -riscv-no-aliases 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-INST %s
+
+# CHECK-INST: mul a4, ra, s0
+mul a4, ra, s0
+
+# CHECK-INST: mulh ra, zero, zero
+mulh x1, x0, x0
+
+# CHECK-INST: mulhsu t0, t2, t1
+mulhsu t0, t2, t1
+
+# CHECK-INST: mulhu a5, a4, a3
+mulhu a5, a4, a3
Index: llvm/test/MC/RISCV/rv32m-no-div-div.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32m-no-div-div.s
@@ -0,0 +1,14 @@
+# RUN: not llvm-mc %s -triple=riscv32 -mattr=+m,+no-div -riscv-no-aliases 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-ERROR %s
+
+# CHECK-ERROR: 5:1: error: instruction requires the following: Hardware integral division not disabled
+div s0, s0, s0
+
+# CHECK-ERROR: 8:1: error: instruction requires the following: Hardware integral division not disabled
+divu gp, a0, a1
+
+# CHECK-ERROR: 11:1: error: instruction requires the following: Hardware integral division not disabled
+rem s2, s2, s8
+
+# CHECK-ERROR: 14:1: error: instruction requires the following: Hardware integral division not disabled
+remu x18, x18, x24
Index: llvm/test/CodeGen/RISCV/no-div.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/no-div.ll
@@ -0,0 +1,45 @@
+; RUN: llc -mtriple=riscv32 -mattr=+m,+no-div -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-DIV %s
+; RUN: llc -mtriple=riscv64 -mattr=+m,+no-div -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-DIV %s
+; RUN: llc -mtriple=riscv32 -mattr=+m,+no-div -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-REM %s
+; RUN: llc -mtriple=riscv64 -mattr=+m,+no-div -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-REM %s
+
+; RUN: llc -mtriple=riscv32 -mattr=+m,+no-div -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-UDIV %s
+; RUN: llc -mtriple=riscv64 -mattr=+m,+no-div -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-UDIV %s
+; RUN: llc -mtriple=riscv32 -mattr=+m,+no-div -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-UREM %s
+; RUN: llc -mtriple=riscv64 -mattr=+m,+no-div -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-UREM %s
+
+; RUN: llc -mtriple=riscv32 -mattr=+m,+no-div -verify-machineinstrs < %s \
+; RUN:  | FileCheck -check-prefix=CHECK-MUL %s
+; RUN: llc -mtriple=riscv64 -mattr=+m,+no-div -verify-machineinstrs < %s \
+; RUN:  | FileCheck -check-prefix=CHECK-MUL %s
+
+; RUN: llc -mtriple=riscv32 -mattr=+m -verify-machineinstrs < %s \
+; RUN:  | FileCheck -check-prefixes=CHECK-MUL,CHECK-UDIV,CHECK-DIV,CHECK-UREM,CHECK-REM %s
+; RUN: llc -mtriple=riscv64 -mattr=+m -verify-machineinstrs < %s \
+; RUN:  | FileCheck -check-prefixes=CHECK-

[PATCH] D103080: [CMake] Ignore arm_*.h for non-ARM build

2021-05-25 Thread lin.sun via Phabricator via cfe-commits
sunlin created this revision.
Herald added subscribers: kristof.beyls, mgorny.
sunlin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Copy the arm_*.h files only "ARM" is in build targets.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103080

Files:
  clang/lib/Headers/CMakeLists.txt


Index: clang/lib/Headers/CMakeLists.txt
===
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -3,10 +3,6 @@
   altivec.h
   ammintrin.h
   amxintrin.h
-  arm_acle.h
-  arm_cmse.h
-  armintr.h
-  arm64intr.h
   avx2intrin.h
   avx512bf16intrin.h
   avx512bwintrin.h
@@ -138,6 +134,15 @@
   xtestintrin.h
   )
 
+if ("ARM" IN_LIST LLVM_TARGETS_TO_BUILD)
+  set(files ${files}
+  arm_acle.h
+  arm_cmse.h
+  armintr.h
+  arm64intr.h
+  )
+endif()
+
 set(cuda_wrapper_files
   cuda_wrappers/algorithm
   cuda_wrappers/complex
@@ -196,19 +201,21 @@
   copy_header_to_output_dir(${CMAKE_CURRENT_SOURCE_DIR} ${f})
 endforeach( f )
 
-# Generate header files and copy them to the build directory
-# Generate arm_neon.h
-clang_generate_header(-gen-arm-neon arm_neon.td arm_neon.h)
-# Generate arm_fp16.h
-clang_generate_header(-gen-arm-fp16 arm_fp16.td arm_fp16.h)
-# Generate arm_sve.h
-clang_generate_header(-gen-arm-sve-header arm_sve.td arm_sve.h)
-# Generate arm_bf16.h
-clang_generate_header(-gen-arm-bf16 arm_bf16.td arm_bf16.h)
-# Generate arm_mve.h
-clang_generate_header(-gen-arm-mve-header arm_mve.td arm_mve.h)
-# Generate arm_cde.h
-clang_generate_header(-gen-arm-cde-header arm_cde.td arm_cde.h)
+if ("ARM" IN_LIST LLVM_TARGETS_TO_BUILD)
+  # Generate header files and copy them to the build directory
+  # Generate arm_neon.h
+  clang_generate_header(-gen-arm-neon arm_neon.td arm_neon.h)
+  # Generate arm_fp16.h
+  clang_generate_header(-gen-arm-fp16 arm_fp16.td arm_fp16.h)
+  # Generate arm_sve.h
+  clang_generate_header(-gen-arm-sve-header arm_sve.td arm_sve.h)
+  # Generate arm_bf16.h
+  clang_generate_header(-gen-arm-bf16 arm_bf16.td arm_bf16.h)
+  # Generate arm_mve.h
+  clang_generate_header(-gen-arm-mve-header arm_mve.td arm_mve.h)
+  # Generate arm_cde.h
+  clang_generate_header(-gen-arm-cde-header arm_cde.td arm_cde.h)
+endif()
 # Generate riscv_vector.h
 clang_generate_header(-gen-riscv-vector-header riscv_vector.td riscv_vector.h)
 


Index: clang/lib/Headers/CMakeLists.txt
===
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -3,10 +3,6 @@
   altivec.h
   ammintrin.h
   amxintrin.h
-  arm_acle.h
-  arm_cmse.h
-  armintr.h
-  arm64intr.h
   avx2intrin.h
   avx512bf16intrin.h
   avx512bwintrin.h
@@ -138,6 +134,15 @@
   xtestintrin.h
   )
 
+if ("ARM" IN_LIST LLVM_TARGETS_TO_BUILD)
+  set(files ${files}
+  arm_acle.h
+  arm_cmse.h
+  armintr.h
+  arm64intr.h
+  )
+endif()
+
 set(cuda_wrapper_files
   cuda_wrappers/algorithm
   cuda_wrappers/complex
@@ -196,19 +201,21 @@
   copy_header_to_output_dir(${CMAKE_CURRENT_SOURCE_DIR} ${f})
 endforeach( f )
 
-# Generate header files and copy them to the build directory
-# Generate arm_neon.h
-clang_generate_header(-gen-arm-neon arm_neon.td arm_neon.h)
-# Generate arm_fp16.h
-clang_generate_header(-gen-arm-fp16 arm_fp16.td arm_fp16.h)
-# Generate arm_sve.h
-clang_generate_header(-gen-arm-sve-header arm_sve.td arm_sve.h)
-# Generate arm_bf16.h
-clang_generate_header(-gen-arm-bf16 arm_bf16.td arm_bf16.h)
-# Generate arm_mve.h
-clang_generate_header(-gen-arm-mve-header arm_mve.td arm_mve.h)
-# Generate arm_cde.h
-clang_generate_header(-gen-arm-cde-header arm_cde.td arm_cde.h)
+if ("ARM" IN_LIST LLVM_TARGETS_TO_BUILD)
+  # Generate header files and copy them to the build directory
+  # Generate arm_neon.h
+  clang_generate_header(-gen-arm-neon arm_neon.td arm_neon.h)
+  # Generate arm_fp16.h
+  clang_generate_header(-gen-arm-fp16 arm_fp16.td arm_fp16.h)
+  # Generate arm_sve.h
+  clang_generate_header(-gen-arm-sve-header arm_sve.td arm_sve.h)
+  # Generate arm_bf16.h
+  clang_generate_header(-gen-arm-bf16 arm_bf16.td arm_bf16.h)
+  # Generate arm_mve.h
+  clang_generate_header(-gen-arm-mve-header arm_mve.td arm_mve.h)
+  # Generate arm_cde.h
+  clang_generate_header(-gen-arm-cde-header arm_cde.td arm_cde.h)
+endif()
 # Generate riscv_vector.h
 clang_generate_header(-gen-riscv-vector-header riscv_vector.td riscv_vector.h)
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102693: Do not create LLVM IR `constant`s for objects with dynamic initialisation

2021-05-25 Thread Momchil Velikov via Phabricator via cfe-commits
chill updated this revision to Diff 347631.
chill added a comment.
This revision is now accepted and ready to land.

Updated a test to run for `x86_64-linux` instead of `%itanium_abi_triple`, to 
avoid having invalid
syntax for MACH-O sections. The patch itself does not care about section 
attribute syntax and x86 target
does not even need to be compiled.


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

https://reviews.llvm.org/D102693

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGenCXX/clang-sections-1.cpp
  clang/test/CodeGenCXX/const-dynamic-init.cpp

Index: clang/test/CodeGenCXX/const-dynamic-init.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/const-dynamic-init.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s | FileCheck %s
+
+__attribute__((section("A")))
+const int a = 1;
+const int *f() { return &a; }
+// CHECK: @_ZL1a = internal constant i32 1, section "A"
+
+int init();
+__attribute__((section("B")))
+const int b = init();
+// Even if it's const-qualified, it must not be LLVM IR `constant` since it's
+// dynamically initialised.
+// CHECK: @_ZL1b = internal global i32 0, section "B"
+
+__attribute__((section("C")))
+int c = 2;
+// CHECK: @c = {{.*}}global i32 2, section "C"
+
+__attribute__((section("D")))
+int d = init();
+// CHECK: @d = {{.*}}global i32 0, section "D"
+
+__attribute__((section("E")))
+int e;
+// CHECK: @e = {{.*}}global i32 0, section "E", align 4
Index: clang/test/CodeGenCXX/clang-sections-1.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/clang-sections-1.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s | FileCheck %s --check-prefix=LLVM
+// RUN: %clang_cc1 -triple x86_64-linux -S -o - %s | FileCheck %s --check-prefix=ASM
+// Actually, any ELF target would do
+// REQUIRES: x86_64-linux
+
+#pragma clang section bss = "B$$" data = "d@t@" rodata = "r0d@t@"
+
+const int a = 1;
+const int *f() { return &a; }
+
+int init();
+const int b = init();
+
+int c = 2;
+
+int d = init();
+
+int e;
+
+// LLVM: @_ZL1a = internal constant i32 1, align 4 #[[#A:]]
+// LLVM: @_ZL1b = internal global i32 0, align 4 #[[#A]]
+// LLVM: @c = {{.*}}global i32 2, align 4 #[[#A]]
+// LLVM: @d = {{.*}}global i32 0, align 4 #[[#A]]
+// LLVM: @e = {{.*}}global i32 0, align 4 #[[#A]]
+
+// LLVM: attributes #[[#A]] = { "bss-section"="B$$" "data-section"="d@t@" "rodata-section"="r0d@t@" }
+
+// ASM:   .section "r0d@t@","a",@progbits
+// ASM-NOT:   .section
+// ASM-LABEL: _ZL1a:
+// ASM-NEXT:  .long 1
+
+// ASM:   .section "B$$","aw",@nobits
+// ASM-NOT:   .section
+// ASM-LABEL: _ZL1b:
+// ASM-NEXT: .long 0
+
+// ASM:   .section "d@t@","aw",@progbits
+// ASM-NOT:   .section
+// ASM-LABEL: c:
+// ASM:   .long 2
+
+// ASM:   .section "B$$","aw",@nobits
+// ASM-NOT:   .section
+// ASM-LABEL: d:
+// ASM:   .long 0
+
+// ASM-NOT:   .section
+// ASM-LABEL: e:
+// ASM.long 0
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13047,43 +13047,6 @@
 }
   }
 
-  // Apply section attributes and pragmas to global variables.
-  bool GlobalStorage = var->hasGlobalStorage();
-  if (GlobalStorage && var->isThisDeclarationADefinition() &&
-  !inTemplateInstantiation()) {
-PragmaStack *Stack = nullptr;
-int SectionFlags = ASTContext::PSF_Read;
-if (var->getType().isConstQualified())
-  Stack = &ConstSegStack;
-else if (!var->getInit()) {
-  Stack = &BSSSegStack;
-  SectionFlags |= ASTContext::PSF_Write;
-} else {
-  Stack = &DataSegStack;
-  SectionFlags |= ASTContext::PSF_Write;
-}
-if (const SectionAttr *SA = var->getAttr()) {
-  if (SA->getSyntax() == AttributeCommonInfo::AS_Declspec)
-SectionFlags |= ASTContext::PSF_Implicit;
-  UnifySection(SA->getName(), SectionFlags, var);
-} else if (Stack->CurrentValue) {
-  SectionFlags |= ASTContext::PSF_Implicit;
-  auto SectionName = Stack->CurrentValue->getString();
-  var->addAttr(SectionAttr::CreateImplicit(
-  Context, SectionName, Stack->CurrentPragmaLocation,
-  AttributeCommonInfo::AS_Pragma, SectionAttr::Declspec_allocate));
-  if (UnifySection(SectionName, SectionFlags, var))
-var->dropAttr();
-}
-
-// Apply the init_seg attribute if this has an initializer.  If the
-// initializer turns out to not be dynamic, we'll end up ignoring this
-// attribute.
-if (CurInitSeg && var->getInit())
-  var->addAttr(InitSegAttr::CreateImplicit(Context, CurInitSeg->getString(),
-   CurInitSegLoc,
-   AttributeCommonInfo::AS_Pragma));
-  }
 
   if (!var->getType()->isStructureType() && var->h

[PATCH] D102772: [SanitizeCoverage] Add support for NoSanitizeCoverage function attribute

2021-05-25 Thread Marco Elver via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG280333021e95: [SanitizeCoverage] Add support for 
NoSanitizeCoverage function attribute (authored by melver).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102772

Files:
  clang/docs/SanitizerCoverage.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/sanitize-coverage.c
  llvm/bindings/go/llvm/ir_test.go
  llvm/docs/BitCodeFormat.rst
  llvm/docs/LangRef.rst
  llvm/include/llvm/AsmParser/LLToken.h
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/Attributes.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Transforms/IPO/ForceFunctionAttrs.cpp
  llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/test/Bitcode/attributes.ll
  llvm/test/Bitcode/compatibility.ll
  llvm/utils/emacs/llvm-mode.el
  llvm/utils/llvm.grm
  llvm/utils/vim/syntax/llvm.vim
  llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml

Index: llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml
===
--- llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml
+++ llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml
@@ -237,6 +237,7 @@
 \\bnosync\\b|\
 \\bnoundef\\b|\
 \\bnounwind\\b|\
+\\bnosanitize_coverage\\b|\
 \\bnull_pointer_is_valid\\b|\
 \\boptforfuzzing\\b|\
 \\boptnone\\b|\
Index: llvm/utils/vim/syntax/llvm.vim
===
--- llvm/utils/vim/syntax/llvm.vim
+++ llvm/utils/vim/syntax/llvm.vim
@@ -138,6 +138,7 @@
   \ nosync
   \ noundef
   \ nounwind
+  \ nosanitize_coverage
   \ null_pointer_is_valid
   \ optforfuzzing
   \ optnone
Index: llvm/utils/llvm.grm
===
--- llvm/utils/llvm.grm
+++ llvm/utils/llvm.grm
@@ -176,6 +176,7 @@
  | sanitize_thread
  | sanitize_memory
  | mustprogress
+ | nosanitize_coverage
  ;
 
 OptFuncAttrs  ::= + _ | OptFuncAttrs FuncAttr ;
Index: llvm/utils/emacs/llvm-mode.el
===
--- llvm/utils/emacs/llvm-mode.el
+++ llvm/utils/emacs/llvm-mode.el
@@ -25,7 +25,7 @@
'("alwaysinline" "argmemonly" "allocsize" "builtin" "cold" "convergent" "dereferenceable" "dereferenceable_or_null" "hot" "inaccessiblememonly"
  "inaccessiblemem_or_argmemonly" "inalloca" "inlinehint" "jumptable" "minsize" "mustprogress" "naked" "nobuiltin" "nonnull"
  "nocallback" "nocf_check" "noduplicate" "nofree" "noimplicitfloat" "noinline" "nomerge" "nonlazybind" "noprofile" "noredzone" "noreturn"
- "norecurse" "nosync" "noundef" "nounwind" "null_pointer_is_valid" "optforfuzzing" "optnone" "optsize" "preallocated" "readnone" "readonly" "returned" "returns_twice"
+ "norecurse" "nosync" "noundef" "nounwind" "nosanitize_coverage" "null_pointer_is_valid" "optforfuzzing" "optnone" "optsize" "preallocated" "readnone" "readonly" "returned" "returns_twice"
  "shadowcallstack" "speculatable" "speculative_load_hardening" "ssp" "sspreq" "sspstrong" "safestack" "sanitize_address" "sanitize_hwaddress" "sanitize_memtag"
  "sanitize_thread" "sanitize_memory" "strictfp" "swifterror" "uwtable" "vscale_range" "willreturn" "writeonly" "immarg") 'symbols) . font-lock-constant-face)
;; Variables
Index: llvm/test/Bitcode/compatibility.ll
===
--- llvm/test/Bitcode/compatibility.ll
+++ llvm/test/Bitcode/compatibility.ll
@@ -1510,7 +1510,7 @@
   ; CHECK: select <2 x i1> , <2 x i8> , <2 x i8> 
 
   call void @f.nobuiltin() builtin
-  ; CHECK: call void @f.nobuiltin() #44
+  ; CHECK: call void @f.nobuiltin() #45
 
   call fastcc noalias i32* @f.noalias() noinline
   ; CHECK: call fastcc noalias i32* @f.noalias() #12
@@ -1904,6 +1904,9 @@
   ret void
 }
 
+declare void @f.nosanitize_coverage() nosanitize_coverage
+; CHECK: declare void @f.nosanitize_coverage() #44
+
 ; immarg attribute
 declare void @llvm.test.immarg.intrinsic(i32 immarg)
 ; CHECK: declare void @llvm.test.immarg.intrinsic(i32 immarg)
@@ -1961,7 +1964,8 @@
 ; CHECK: attributes #41 = { writeonly }
 ; CHECK: attributes #42 = { speculatable }
 ; CHECK: attributes #43 = { strictfp }
-; CHECK: attributes #44 = { builtin }
+; CHECK: attributes #44 = { nosanitize_coverage }
+; CHECK: attributes #45 = { builtin }
 
 ;; Metadata
 
Index: llvm/test/Bitcod

[PATCH] D102927: [NFC][CodeGenOptions] Refactor checking SanitizeCoverage options

2021-05-25 Thread Marco Elver via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGca6df734069a: [NFC][CodeGenOptions] Refactor checking 
SanitizeCoverage options (authored by melver).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102927

Files:
  clang/include/clang/Basic/CodeGenOptions.h
  clang/lib/CodeGen/BackendUtil.cpp


Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -727,9 +727,7 @@
addBoundsCheckingPass);
   }
 
-  if (CodeGenOpts.SanitizeCoverageType ||
-  CodeGenOpts.SanitizeCoverageIndirectCalls ||
-  CodeGenOpts.SanitizeCoverageTraceCmp) {
+  if (CodeGenOpts.hasSanitizeCoverage()) {
 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
addSanitizerCoveragePass);
 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
@@ -1099,9 +1097,7 @@
   const LangOptions &LangOpts, PassBuilder &PB) {
   PB.registerOptimizerLastEPCallback([&](ModulePassManager &MPM,
  PassBuilder::OptimizationLevel Level) 
{
-if (CodeGenOpts.SanitizeCoverageType ||
-CodeGenOpts.SanitizeCoverageIndirectCalls ||
-CodeGenOpts.SanitizeCoverageTraceCmp) {
+if (CodeGenOpts.hasSanitizeCoverage()) {
   auto SancovOpts = getSancovOptsFromCGOpts(CodeGenOpts);
   MPM.addPass(ModuleSanitizerCoveragePass(
   SancovOpts, CodeGenOpts.SanitizeCoverageAllowlistFiles,
Index: clang/include/clang/Basic/CodeGenOptions.h
===
--- clang/include/clang/Basic/CodeGenOptions.h
+++ clang/include/clang/Basic/CodeGenOptions.h
@@ -452,6 +452,12 @@
   bool hasMaybeUnusedDebugInfo() const {
 return getDebugInfo() >= codegenoptions::UnusedTypeInfo;
   }
+
+  // Check if any one of SanitizeCoverage* is enabled.
+  bool hasSanitizeCoverage() const {
+return SanitizeCoverageType || SanitizeCoverageIndirectCalls ||
+   SanitizeCoverageTraceCmp;
+  }
 };
 
 }  // end namespace clang


Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -727,9 +727,7 @@
addBoundsCheckingPass);
   }
 
-  if (CodeGenOpts.SanitizeCoverageType ||
-  CodeGenOpts.SanitizeCoverageIndirectCalls ||
-  CodeGenOpts.SanitizeCoverageTraceCmp) {
+  if (CodeGenOpts.hasSanitizeCoverage()) {
 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
addSanitizerCoveragePass);
 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
@@ -1099,9 +1097,7 @@
   const LangOptions &LangOpts, PassBuilder &PB) {
   PB.registerOptimizerLastEPCallback([&](ModulePassManager &MPM,
  PassBuilder::OptimizationLevel Level) {
-if (CodeGenOpts.SanitizeCoverageType ||
-CodeGenOpts.SanitizeCoverageIndirectCalls ||
-CodeGenOpts.SanitizeCoverageTraceCmp) {
+if (CodeGenOpts.hasSanitizeCoverage()) {
   auto SancovOpts = getSancovOptsFromCGOpts(CodeGenOpts);
   MPM.addPass(ModuleSanitizerCoveragePass(
   SancovOpts, CodeGenOpts.SanitizeCoverageAllowlistFiles,
Index: clang/include/clang/Basic/CodeGenOptions.h
===
--- clang/include/clang/Basic/CodeGenOptions.h
+++ clang/include/clang/Basic/CodeGenOptions.h
@@ -452,6 +452,12 @@
   bool hasMaybeUnusedDebugInfo() const {
 return getDebugInfo() >= codegenoptions::UnusedTypeInfo;
   }
+
+  // Check if any one of SanitizeCoverage* is enabled.
+  bool hasSanitizeCoverage() const {
+return SanitizeCoverageType || SanitizeCoverageIndirectCalls ||
+   SanitizeCoverageTraceCmp;
+  }
 };
 
 }  // end namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102929: [NFC][SanitizeCoverage] Test always_inline functions work

2021-05-25 Thread Marco Elver via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG85feebf5a340: [NFC][SanitizeCoverage] Test always_inline 
functions work (authored by melver).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102929

Files:
  clang/test/CodeGen/sanitize-coverage.c


Index: clang/test/CodeGen/sanitize-coverage.c
===
--- clang/test/CodeGen/sanitize-coverage.c
+++ clang/test/CodeGen/sanitize-coverage.c
@@ -19,4 +19,16 @@
   if (n)
 x[n] = 42;
 }
+
+static inline __attribute__((__always_inline__)) void always_inlined_fn(int n) 
{
+  if (n)
+x[n] = 42;
+}
+// CHECK-LABEL: define dso_local void @test_always_inline(
+void test_always_inline(int n) {
+  // CHECK-DAG: call void @__sanitizer_cov_trace_pc
+  // CHECK-DAG: call void @__sanitizer_cov_trace_const_cmp
+  always_inlined_fn(n);
+}
+
 // CHECK-LABEL: declare void


Index: clang/test/CodeGen/sanitize-coverage.c
===
--- clang/test/CodeGen/sanitize-coverage.c
+++ clang/test/CodeGen/sanitize-coverage.c
@@ -19,4 +19,16 @@
   if (n)
 x[n] = 42;
 }
+
+static inline __attribute__((__always_inline__)) void always_inlined_fn(int n) {
+  if (n)
+x[n] = 42;
+}
+// CHECK-LABEL: define dso_local void @test_always_inline(
+void test_always_inline(int n) {
+  // CHECK-DAG: call void @__sanitizer_cov_trace_pc
+  // CHECK-DAG: call void @__sanitizer_cov_trace_const_cmp
+  always_inlined_fn(n);
+}
+
 // CHECK-LABEL: declare void
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2803330 - [SanitizeCoverage] Add support for NoSanitizeCoverage function attribute

2021-05-25 Thread Marco Elver via cfe-commits

Author: Marco Elver
Date: 2021-05-25T12:57:14+02:00
New Revision: 280333021e9550d80f5c1152a34e33e81df1e178

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

LOG: [SanitizeCoverage] Add support for NoSanitizeCoverage function attribute

We really ought to support no_sanitize("coverage") in line with other
sanitizers. This came up again in discussions on the Linux-kernel
mailing lists, because we currently do workarounds using objtool to
remove coverage instrumentation. Since that support is only on x86, to
continue support coverage instrumentation on other architectures, we
must support selectively disabling coverage instrumentation via function
attributes.

Unfortunately, for SanitizeCoverage, it has not been implemented as a
sanitizer via fsanitize= and associated options in Sanitizers.def, but
rolls its own option fsanitize-coverage. This meant that we never got
"automatic" no_sanitize attribute support.

Implement no_sanitize attribute support by special-casing the string
"coverage" in the NoSanitizeAttr implementation. To keep the feature as
unintrusive to existing IR generation as possible, define a new negative
function attribute NoSanitizeCoverage to propagate the information
through to the instrumentation pass.

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

Reviewed By: vitalybuka, morehouse

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

Added: 


Modified: 
clang/docs/SanitizerCoverage.rst
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/CodeGen/sanitize-coverage.c
llvm/bindings/go/llvm/ir_test.go
llvm/docs/BitCodeFormat.rst
llvm/docs/LangRef.rst
llvm/include/llvm/AsmParser/LLToken.h
llvm/include/llvm/Bitcode/LLVMBitCodes.h
llvm/include/llvm/IR/Attributes.td
llvm/lib/AsmParser/LLLexer.cpp
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/IR/Attributes.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Transforms/IPO/ForceFunctionAttrs.cpp
llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
llvm/lib/Transforms/Utils/CodeExtractor.cpp
llvm/test/Bitcode/attributes.ll
llvm/test/Bitcode/compatibility.ll
llvm/utils/emacs/llvm-mode.el
llvm/utils/llvm.grm
llvm/utils/vim/syntax/llvm.vim
llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml

Removed: 




diff  --git a/clang/docs/SanitizerCoverage.rst 
b/clang/docs/SanitizerCoverage.rst
index 485a73d273aed..b0bb9823eb043 100644
--- a/clang/docs/SanitizerCoverage.rst
+++ b/clang/docs/SanitizerCoverage.rst
@@ -312,11 +312,17 @@ will not be instrumented.
   // for every non-constant array index.
   void __sanitizer_cov_trace_gep(uintptr_t Idx);
 
-Partially disabling instrumentation
-===
+Disabling instrumentation with ``__attribute__((no_sanitize("coverage")))``
+===
+
+It is possible to disable coverage instrumentation for select functions via the
+function attribute ``__attribute__((no_sanitize("coverage")))``.
+
+Disabling instrumentation without source modification
+=
 
 It is sometimes useful to tell SanitizerCoverage to instrument only a subset 
of the
-functions in your target.
+functions in your target without modifying source files.
 With ``-fsanitize-coverage-allowlist=allowlist.txt``
 and ``-fsanitize-coverage-blocklist=blocklist.txt``,
 you can specify such a subset through the combination of an allowlist and a 
blocklist.

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 5e04f32187cd2..6a39453153930 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2897,6 +2897,10 @@ def NoSanitize : InheritableAttr {
   }
   return Mask;
 }
+
+bool hasCoverage() const {
+  return llvm::is_contained(sanitizers(), "coverage");
+}
   }];
 }
 

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index cae9cec804ce9..e9ee45d91dc50 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -2564,12 +2564,17 @@ def NoSanitizeDocs : Documentation {
   let Content = [{
 Use the ``no_sanitize`` attribute on a function or a global variable
 declaration to specify that a particular instrumentation or set of
-instrumentations should not be applied. The attribute takes a list of
-string literals, which have the same meaning as values accepted by the
-``-fno-sanitize=`` flag. For example,
-``__attribute__((no_sanitize("address"

[clang] 85feebf - [NFC][SanitizeCoverage] Test always_inline functions work

2021-05-25 Thread Marco Elver via cfe-commits

Author: Marco Elver
Date: 2021-05-25T12:57:14+02:00
New Revision: 85feebf5a3401eab4c71288e2dc089faf547ab4c

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

LOG: [NFC][SanitizeCoverage] Test always_inline functions work

Test that always_inline functions are instrumented as expected.

Reviewed By: vitalybuka

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

Added: 


Modified: 
clang/test/CodeGen/sanitize-coverage.c

Removed: 




diff  --git a/clang/test/CodeGen/sanitize-coverage.c 
b/clang/test/CodeGen/sanitize-coverage.c
index 6fc8e39354d4f..b3e44e28cbce9 100644
--- a/clang/test/CodeGen/sanitize-coverage.c
+++ b/clang/test/CodeGen/sanitize-coverage.c
@@ -19,4 +19,16 @@ void foo(int n) {
   if (n)
 x[n] = 42;
 }
+
+static inline __attribute__((__always_inline__)) void always_inlined_fn(int n) 
{
+  if (n)
+x[n] = 42;
+}
+// CHECK-LABEL: define dso_local void @test_always_inline(
+void test_always_inline(int n) {
+  // CHECK-DAG: call void @__sanitizer_cov_trace_pc
+  // CHECK-DAG: call void @__sanitizer_cov_trace_const_cmp
+  always_inlined_fn(n);
+}
+
 // CHECK-LABEL: declare void



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


[clang] ca6df73 - [NFC][CodeGenOptions] Refactor checking SanitizeCoverage options

2021-05-25 Thread Marco Elver via cfe-commits

Author: Marco Elver
Date: 2021-05-25T12:57:14+02:00
New Revision: ca6df734069ae590d1632e920ceba03bea317549

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

LOG: [NFC][CodeGenOptions] Refactor checking SanitizeCoverage options

Refactor checking SanitizeCoverage options into
CodeGenOptions::hasSanitizeCoverage().

Reviewed By: vitalybuka

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

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.h
clang/lib/CodeGen/BackendUtil.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index c77c34a8a57d6..617c255641efd 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -452,6 +452,12 @@ class CodeGenOptions : public CodeGenOptionsBase {
   bool hasMaybeUnusedDebugInfo() const {
 return getDebugInfo() >= codegenoptions::UnusedTypeInfo;
   }
+
+  // Check if any one of SanitizeCoverage* is enabled.
+  bool hasSanitizeCoverage() const {
+return SanitizeCoverageType || SanitizeCoverageIndirectCalls ||
+   SanitizeCoverageTraceCmp;
+  }
 };
 
 }  // end namespace clang

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index a2d219e92d6b0..ca1067dbb79f5 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -727,9 +727,7 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager 
&MPM,
addBoundsCheckingPass);
   }
 
-  if (CodeGenOpts.SanitizeCoverageType ||
-  CodeGenOpts.SanitizeCoverageIndirectCalls ||
-  CodeGenOpts.SanitizeCoverageTraceCmp) {
+  if (CodeGenOpts.hasSanitizeCoverage()) {
 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
addSanitizerCoveragePass);
 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
@@ -1099,9 +1097,7 @@ static void addSanitizers(const Triple &TargetTriple,
   const LangOptions &LangOpts, PassBuilder &PB) {
   PB.registerOptimizerLastEPCallback([&](ModulePassManager &MPM,
  PassBuilder::OptimizationLevel Level) 
{
-if (CodeGenOpts.SanitizeCoverageType ||
-CodeGenOpts.SanitizeCoverageIndirectCalls ||
-CodeGenOpts.SanitizeCoverageTraceCmp) {
+if (CodeGenOpts.hasSanitizeCoverage()) {
   auto SancovOpts = getSancovOptsFromCGOpts(CodeGenOpts);
   MPM.addPass(ModuleSanitizerCoveragePass(
   SancovOpts, CodeGenOpts.SanitizeCoverageAllowlistFiles,



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


[PATCH] D102839: [RISCV][Clang] Add -mno-div option to disable hardware int division

2021-05-25 Thread ksyx via Phabricator via cfe-commits
ksyx updated this revision to Diff 347603.
ksyx marked 2 inline comments as done.
ksyx retitled this revision from "[RISCV][Clang] Add -mno-idiv option to 
disable hardware int division" to "[RISCV][Clang] Add -mno-div option to 
disable hardware int division".
ksyx edited the summary of this revision.
ksyx added a reviewer: craig.topper.
ksyx added a comment.

- remove redundant macro definition
- split mul and div handling in `RISCVISelLowering.cpp`
- rename `no-idiv` into `no-div`


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

https://reviews.llvm.org/D102839

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-no-div.c
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfoM.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/no-div.ll
  llvm/test/MC/RISCV/rv32m-no-div-div.s
  llvm/test/MC/RISCV/rv32m-no-div-mul.s
  llvm/test/MC/RISCV/rv64m-no-div-div.s
  llvm/test/MC/RISCV/rv64m-no-div-mul.s

Index: llvm/test/MC/RISCV/rv64m-no-div-mul.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64m-no-div-mul.s
@@ -0,0 +1,5 @@
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+m,+no-div -riscv-no-aliases 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-INST %s
+
+# CHECK-INST: mulw ra, sp, gp
+mulw ra, sp, gp
Index: llvm/test/MC/RISCV/rv64m-no-div-div.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64m-no-div-div.s
@@ -0,0 +1,14 @@
+# RUN: not llvm-mc %s -triple=riscv64 -mattr=+m,+no-div -riscv-no-aliases 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-ERROR %s
+
+# CHECK-ERROR: 5:1: error: instruction requires the following: Hardware integral division not disabled
+divw tp, t0, t1
+
+# CHECK-ERROR: 8:1: error: instruction requires the following: Hardware integral division not disabled
+divuw t2, s0, s2
+
+# CHECK-ERROR: 11:1: error: instruction requires the following: Hardware integral division not disabled
+remw a0, a1, a2
+
+# CHECK-ERROR: 14:1: error: instruction requires the following: Hardware integral division not disabled
+remuw a3, a4, a5
Index: llvm/test/MC/RISCV/rv32m-no-div-mul.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32m-no-div-mul.s
@@ -0,0 +1,14 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+m,+no-div -riscv-no-aliases 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-INST %s
+
+# CHECK-INST: mul a4, ra, s0
+mul a4, ra, s0
+
+# CHECK-INST: mulh ra, zero, zero
+mulh x1, x0, x0
+
+# CHECK-INST: mulhsu t0, t2, t1
+mulhsu t0, t2, t1
+
+# CHECK-INST: mulhu a5, a4, a3
+mulhu a5, a4, a3
Index: llvm/test/MC/RISCV/rv32m-no-div-div.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32m-no-div-div.s
@@ -0,0 +1,14 @@
+# RUN: not llvm-mc %s -triple=riscv32 -mattr=+m,+no-div -riscv-no-aliases 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-ERROR %s
+
+# CHECK-ERROR: 5:1: error: instruction requires the following: Hardware integral division not disabled
+div s0, s0, s0
+
+# CHECK-ERROR: 8:1: error: instruction requires the following: Hardware integral division not disabled
+divu gp, a0, a1
+
+# CHECK-ERROR: 11:1: error: instruction requires the following: Hardware integral division not disabled
+rem s2, s2, s8
+
+# CHECK-ERROR: 14:1: error: instruction requires the following: Hardware integral division not disabled
+remu x18, x18, x24
Index: llvm/test/CodeGen/RISCV/no-div.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/no-div.ll
@@ -0,0 +1,45 @@
+; RUN: llc -mtriple=riscv32 -mattr=+m,+no-div -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-DIV %s
+; RUN: llc -mtriple=riscv64 -mattr=+m,+no-div -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-DIV %s
+; RUN: llc -mtriple=riscv32 -mattr=+m,+no-div -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-REM %s
+; RUN: llc -mtriple=riscv64 -mattr=+m,+no-div -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-REM %s
+
+; RUN: llc -mtriple=riscv32 -mattr=+m,+no-div -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-UDIV %s
+; RUN: llc -mtriple=riscv64 -mattr=+m,+no-div -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-UDIV %s
+; RUN: llc -mtriple=riscv32 -mattr=+m,+no-div -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-UREM %s
+; RUN: llc -mtriple=riscv64 -mattr=+m,+no-div -verify-machineinstrs < %s \
+; RUN:  | not FileCheck -check-prefix=CHECK-UREM %s
+
+; RUN: llc -mtriple=riscv32 -mattr=+m,+no-div -verify-machineinstrs < %s \
+; RUN:  | FileCheck -check-prefix

[PATCH] D102650: Old work on P0388. For reference in D102645. Not for review / commit.

2021-05-25 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan added a comment.

dblaikie, do you know if there's a way to do it outside of arc? (for reasons, 
I've not got arc to work from inside work).  I tried not setting a reviewer, 
but then that got autofilled.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102650

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


[PATCH] D49864: [clang-tidy] The script clang-tidy-diff.py doesn't accept 'pass by' options (--)

2021-05-25 Thread Jano Simas via Phabricator via cfe-commits
janosimas updated this revision to Diff 347622.
janosimas added a comment.

Fix test issue.

Use correct clang-tidy flag


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D49864

Files:
  clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
  clang-tools-extra/test/clang-tidy/infrastructure/clang-tidy-diff.cpp

Index: clang-tools-extra/test/clang-tidy/infrastructure/clang-tidy-diff.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/clang-tidy-diff.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/clang-tidy-diff.cpp
@@ -1,11 +1,11 @@
 // REQUIRES: shell
 // RUN: sed 's/placeholder_for_f/f/' %s > %t.cpp
 // RUN: clang-tidy -checks=-*,modernize-use-override %t.cpp -- -std=c++11 | FileCheck -check-prefix=CHECK-SANITY %s
-// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -- -std=c++11 2>&1 | FileCheck %s
-// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -quiet -- -std=c++11 2>&1 | FileCheck -check-prefix=CHECK-QUIET %s
+// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -- -checks=-*,modernize-use-override -- -std=c++11 2>&1 | FileCheck %s
+// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -- -checks=-*,modernize-use-override -quiet -- -std=c++11 2>&1 | FileCheck -check-prefix=CHECK-QUIET %s
 // RUN: mkdir -p %T/compilation-database-test/
 // RUN: echo '[{"directory": "%T", "command": "clang++ -o test.o -std=c++11 %t.cpp", "file": "%t.cpp"}]' > %T/compilation-database-test/compile_commands.json
-// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -path %T/compilation-database-test 2>&1 | FileCheck -check-prefix=CHECK %s
+// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -- -checks=-*,modernize-use-override -p=%T/compilation-database-test 2>&1 | FileCheck -check-prefix=CHECK %s
 struct A {
   virtual void f() {}
   virtual void g() {}
Index: clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
===
--- clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -17,9 +17,9 @@
 detect clang-tidy regressions in the lines touched by a specific patch.
 Example usage for git/svn users:
 
-  git diff -U0 HEAD^ | clang-tidy-diff.py -p1
+  git diff -U0 HEAD^ | clang-tidy-diff.py -strip 1
   svn diff --diff-cmd=diff -x-U0 | \
-  clang-tidy-diff.py -fix -checks=-*,modernize-use-override
+  clang-tidy-diff.py -- -fix -checks=-*,modernize-use-override
 
 """
 
@@ -119,12 +119,13 @@
   parser = argparse.ArgumentParser(description=
'Run clang-tidy against changed files, and '
'output diagnostics only for modified '
-   'lines.')
+   'lines.'
+   '\nclang-tidy arguments should be passed after a \'--\' .')
   parser.add_argument('-clang-tidy-binary', metavar='PATH',
   default='clang-tidy',
   help='path to clang-tidy binary')
-  parser.add_argument('-p', metavar='NUM', default=0,
-  help='strip the smallest prefix containing P slashes')
+  parser.add_argument('-strip', metavar='NUM', default=0,
+  help='strip the smallest prefix containing NUM slashes')
   parser.add_argument('-regex', metavar='PATTERN', default=None,
   help='custom pattern selecting file paths to check '
   '(case sensitive, overrides -iregex)')
@@ -136,34 +137,14 @@
   help='number of tidy instances to be run in parallel.')
   parser.add_argument('-timeout', type=int, default=None,
   help='timeout per each file in seconds.')
-  parser.add_argument('-fix', action='store_true', default=False,
-  help='apply suggested fixes')
-  parser.add_argument('-checks',
-  help='checks filter, when not specified, use clang-tidy '
-  'default',
-  default='')
-  parser.add_argument('-use-color', action='store_true',
-  help='Use colors in output')
-  parser.add_argument('-path', dest='build_path',
-  help='Path used to read a compile command database.')
   if yaml:
 parser.add_argument('-export-fixes', metavar='FILE', dest='export_fixes',
 help='Create a yaml file to store suggested fixes in, '
 'which can be applied with clang-apply-replacements.')
-  parser.add_argument('-extra-arg', dest='extra_arg',
-  action='append', default=[],
-  help='Additional argument to append to the compiler '
-  'command line.')
-  parser.add_argument('-extra-

[PATCH] D102761: [clangd] New ParsingCallback for semantics changes

2021-05-25 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

> It seems like a lit test for this would be terrible. A ClangdServer one 
> should be possible, but I can't quite wrap my head around how to write it.
> (Delivering the PreambleData as a param would make the test easier, you could 
> assert that the preamble version was > any previously notified preamble & 
> also > any preamble previously obtained via runWithPreamble.)

I also put some thought into it, but couldn't figure out a way that wouldn't be 
flaky. we can write a test that might catch a regression, but it won't catch 
all of them for sure unless we somehow block the execution of threads.
I tried to find some locking solution that wouldn't depend too much on the 
TUScheduler's implementation details but couldn't find any, and eventually gave 
up :/.

I can include a test that ensures `runWithAST` always sees a new preamble after 
`onPreamblePublished`, but as mentioned it is going to be a flaky at best. WDYT?




Comment at: clang-tools-extra/clangd/TUScheduler.h:175
+  /// on the file are guranteed to see new semantics after the callback.
+  virtual void onSemanticsMaybeChanged(PathRef File) {}
 };

sammccall wrote:
> This seems a little vague/abstract for TUScheduler.
> The "caller" (i.e. ClangdServer impl) needs to know about preambles etc, c.f. 
> onPreambleAST in this same interface.
> 
> I'd suggest `onPreambleActive` or `onPreamblePublished` or something like 
> that.
> (Passing the PreambleData struct as a param would also hint nicely at the 
> distinction vs onPreambleAST but is maybe too cute if we're not actually 
> going to use it...)
going with `onPreamblePublished`, since `Active` might mean it wasn't 
previously before (e.g. first preamble for a TU).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102761

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


[PATCH] D102761: [clangd] New ParsingCallback for semantics changes

2021-05-25 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 347621.
kadircet marked an inline comment as done.
kadircet added a comment.

- s/onSemanticsMaybeChanged/onPreamblePublished


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102761

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h


Index: clang-tools-extra/clangd/TUScheduler.h
===
--- clang-tools-extra/clangd/TUScheduler.h
+++ clang-tools-extra/clangd/TUScheduler.h
@@ -169,6 +169,11 @@
 
   /// Called whenever the TU status is updated.
   virtual void onFileUpdated(PathRef File, const TUStatus &Status) {}
+
+  /// Preamble for the TU have changed. This might imply new semantics (e.g.
+  /// different highlightings). Any actions on the file are guranteed to see 
new
+  /// preamble after the callback.
+  virtual void onPreamblePublished(PathRef File) {}
 };
 
 /// Handles running tasks for ClangdServer and managing the resources (e.g.,
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -909,6 +909,7 @@
 ASTPeer.updatePreamble(std::move(Req.CI), std::move(Req.Inputs),
LatestBuild, std::move(Req.CIDiags),
std::move(Req.WantDiags));
+Callbacks.onPreamblePublished(FileName);
   });
 
   if (!LatestBuild || Inputs.ForceRebuild) {
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -75,8 +75,6 @@
  const CanonicalIncludes &CanonIncludes) override {
 if (FIndex)
   FIndex->updatePreamble(Path, Version, Ctx, std::move(PP), CanonIncludes);
-if (ServerCallbacks)
-  ServerCallbacks->onSemanticsMaybeChanged(Path);
   }
 
   void onMainAST(PathRef Path, ParsedAST &AST, PublishFn Publish) override {
@@ -105,6 +103,11 @@
   ServerCallbacks->onFileUpdated(File, Status);
   }
 
+  void onPreamblePublished(PathRef File) override {
+if (ServerCallbacks)
+  ServerCallbacks->onSemanticsMaybeChanged(File);
+  }
+
 private:
   FileIndex *FIndex;
   ClangdServer::Callbacks *ServerCallbacks;


Index: clang-tools-extra/clangd/TUScheduler.h
===
--- clang-tools-extra/clangd/TUScheduler.h
+++ clang-tools-extra/clangd/TUScheduler.h
@@ -169,6 +169,11 @@
 
   /// Called whenever the TU status is updated.
   virtual void onFileUpdated(PathRef File, const TUStatus &Status) {}
+
+  /// Preamble for the TU have changed. This might imply new semantics (e.g.
+  /// different highlightings). Any actions on the file are guranteed to see new
+  /// preamble after the callback.
+  virtual void onPreamblePublished(PathRef File) {}
 };
 
 /// Handles running tasks for ClangdServer and managing the resources (e.g.,
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -909,6 +909,7 @@
 ASTPeer.updatePreamble(std::move(Req.CI), std::move(Req.Inputs),
LatestBuild, std::move(Req.CIDiags),
std::move(Req.WantDiags));
+Callbacks.onPreamblePublished(FileName);
   });
 
   if (!LatestBuild || Inputs.ForceRebuild) {
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -75,8 +75,6 @@
  const CanonicalIncludes &CanonIncludes) override {
 if (FIndex)
   FIndex->updatePreamble(Path, Version, Ctx, std::move(PP), CanonIncludes);
-if (ServerCallbacks)
-  ServerCallbacks->onSemanticsMaybeChanged(Path);
   }
 
   void onMainAST(PathRef Path, ParsedAST &AST, PublishFn Publish) override {
@@ -105,6 +103,11 @@
   ServerCallbacks->onFileUpdated(File, Status);
   }
 
+  void onPreamblePublished(PathRef File) override {
+if (ServerCallbacks)
+  ServerCallbacks->onSemanticsMaybeChanged(File);
+  }
+
 private:
   FileIndex *FIndex;
   ClangdServer::Callbacks *ServerCallbacks;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D100834: Bug 49739 - [Matrix] Support #pragma clang fp

2021-05-25 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

@effective-light just FYI,  if you are interested in improving fast-math flags 
handling during matrix lowering on the LLVM side, there's 
https://bugs.llvm.org/show_bug.cgi?id=49738


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100834

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


[PATCH] D102761: [clangd] New ParsingCallback for semantics changes

2021-05-25 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.

It seems like a lit test for this would be terrible. A ClangdServer one should 
be possible, but I can't quite wrap my head around how to write it.

(Delivering the PreambleData as a param would make the test easier, you could 
assert that the preamble version was > any previously notified preamble & also 
> any preamble previously obtained via runWithPreamble.)




Comment at: clang-tools-extra/clangd/TUScheduler.h:175
+  /// on the file are guranteed to see new semantics after the callback.
+  virtual void onSemanticsMaybeChanged(PathRef File) {}
 };

This seems a little vague/abstract for TUScheduler.
The "caller" (i.e. ClangdServer impl) needs to know about preambles etc, c.f. 
onPreambleAST in this same interface.

I'd suggest `onPreambleActive` or `onPreamblePublished` or something like that.
(Passing the PreambleData struct as a param would also hint nicely at the 
distinction vs onPreambleAST but is maybe too cute if we're not actually going 
to use it...)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102761

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


[PATCH] D101763: [analyzer][ctu] Avoid parsing invocation list again and again during on-demand parsing of CTU

2021-05-25 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

I've decided to land this without the test.
Thank you for your contribution.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101763

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


[PATCH] D102693: Do not create LLVM IR `constant`s for objects with dynamic initialisation

2021-05-25 Thread Momchil Velikov via Phabricator via cfe-commits
chill added a comment.

Thanks, I'll have a look.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102693

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


[PATCH] D101191: [InstCombine] Fully disable select to and/or i1 folding

2021-05-25 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.
Herald added a subscriber: foad.

Looks like this is causing an infinite loop in instcombine: 
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=34661

Reproducer test case: 
https://oss-fuzz.com/download?testcase_id=6383789942112256 , hangs with `opt 
-instcombine`, terminates with the patch reverted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101191

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


[PATCH] D102517: [clang] Add support for the "abstract" contextual keyword of MSVC

2021-05-25 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

Apologies for the slow reply, it was a long weekend here.




Comment at: clang/lib/Parse/ParseDeclCXX.cpp:3314
   if (getLangOpts().CPlusPlus && Tok.is(tok::identifier)) {
-VirtSpecifiers::Specifier Specifier = isCXX11VirtSpecifier(Tok);
-assert((Specifier == VirtSpecifiers::VS_Final ||
-Specifier == VirtSpecifiers::VS_GNU_Final ||
-Specifier == VirtSpecifiers::VS_Sealed) &&
+for (VirtSpecifiers::Specifier Specifier = isCXX11VirtSpecifier(Tok);
+ Specifier != VirtSpecifiers::VS_None;

AbbasSabra wrote:
> hans wrote:
> > This 'for' construct is hard to follow. I think it might be easier to 
> > follow as a while loop, maybe
> > 
> > ```
> > while ((Specifier = isCXX11VirtSpecifier(Tok)) != VirtSpecifiers::VS_None) {
> > ```
> > 
> > Also the "is" prefix in isCXX11VirtSpecifier is confusing given that it 
> > doesn't return a bool.
> For "for" vs "while" if you use while you will have to declare the variable 
> before the loop giving it the wrong scope which makes it less readable in my 
> opinion. 
> For  !!isCXX11VirtSpecifier!! I agree but I wouldn't separate the rename from 
> this patch(I'm not sure what is the guidelines here)
> 
I still think the for-loop is confusing. How about something like this, then?

```
while (true) {
  VirtSpecifiers::Specifier Specifier = isCXX11VirtSpecifier(Tok);
  if (Specifier == VirtSpecifiers::VS_None)
break;

  ...
}
```

I agree that renaming isCXX11VirtSpecifier in a separate patch is a good idea.



Comment at: clang/lib/Sema/DeclSpec.cpp:1479
+  case VS_Abstract:
+VS_abstractLoc = Loc;
+break;

AbbasSabra wrote:
> hans wrote:
> > nit: the other cases just use one line
> clang-format doesn't like it. Should I ignore it?
Yes, ignoring it is fine. (Re-formatting the whole switch would also be okay, 
as long as its consistent.)



Comment at: clang/lib/Sema/DeclSpec.cpp:1493
   case VS_Sealed: return "sealed";
+  case VS_Abstract:
+return "abstract";

AbbasSabra wrote:
> hans wrote:
> > nit: skip the newline for consistency here too
> same clang-format splits the line
Ignoring clang-format is fine, sticking to the current style is usually 
preferred..


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102517

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


[clang] d59b4ac - [analyzer][ctu] Reland "Avoid parsing invocation list again and again..

2021-05-25 Thread Balazs Benics via cfe-commits

Author: Ella Ma
Date: 2021-05-25T09:44:13+02:00
New Revision: d59b4acf80d59c461decd41400988febaf0af8ca

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

LOG: [analyzer][ctu] Reland "Avoid parsing invocation list again and again..

..during on-demand parsing of CTU"

During CTU, the *on-demand parsing* will read and parse the invocation
list to know how to compile the file being imported. However, it seems
that the invocation list will be parsed again if a previous parsing
has failed.
Then, parse again and fail again. This patch tries to overcome the
problem by storing the error code during the first parsing, and
re-create the stored error during the later parsings.

Reland without test.

Reviewed By: steakhal

Patch By: OikawaKirie!

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

Added: 


Modified: 
clang/include/clang/CrossTU/CrossTranslationUnit.h
clang/lib/CrossTU/CrossTranslationUnit.cpp

Removed: 




diff  --git a/clang/include/clang/CrossTU/CrossTranslationUnit.h 
b/clang/include/clang/CrossTU/CrossTranslationUnit.h
index b419b9be67cb9..d9f9c51fccd9c 100644
--- a/clang/include/clang/CrossTU/CrossTranslationUnit.h
+++ b/clang/include/clang/CrossTU/CrossTranslationUnit.h
@@ -38,6 +38,7 @@ class TranslationUnitDecl;
 namespace cross_tu {
 
 enum class index_error_code {
+  success = 0,
   unspecified = 1,
   missing_index_file,
   invalid_index_format,
@@ -253,6 +254,7 @@ class CrossTranslationUnitContext {
 /// In case of on-demand parsing, the invocations for parsing the source
 /// files is stored.
 llvm::Optional InvocationList;
+index_error_code PreviousParsingResult = index_error_code::success;
   };
 
   /// Maintain number of AST loads and check for reaching the load limit.

diff  --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp 
b/clang/lib/CrossTU/CrossTranslationUnit.cpp
index 640538cae3bbc..adee55304c871 100644
--- a/clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -92,6 +92,10 @@ class IndexErrorCategory : public std::error_category {
 
   std::string message(int Condition) const override {
 switch (static_cast(Condition)) {
+case index_error_code::success:
+  // There should not be a success error. Jump to unreachable directly.
+  // Add this case to make the compiler stop complaining.
+  break;
 case index_error_code::unspecified:
   return "An unknown error has occurred.";
 case index_error_code::missing_index_file:
@@ -667,12 +671,15 @@ llvm::Error 
CrossTranslationUnitContext::ASTLoader::lazyInitInvocationList() {
   /// Lazily initialize the invocation list member used for on-demand parsing.
   if (InvocationList)
 return llvm::Error::success();
+  if (index_error_code::success != PreviousParsingResult)
+return llvm::make_error(PreviousParsingResult);
 
   llvm::ErrorOr> FileContent =
   llvm::MemoryBuffer::getFile(InvocationListFilePath);
-  if (!FileContent)
-return llvm::make_error(
-index_error_code::invocation_list_file_not_found);
+  if (!FileContent) {
+PreviousParsingResult = index_error_code::invocation_list_file_not_found;
+return llvm::make_error(PreviousParsingResult);
+  }
   std::unique_ptr ContentBuffer = std::move(*FileContent);
   assert(ContentBuffer && "If no error was produced after loading, the pointer 
"
   "should not be nullptr.");
@@ -680,8 +687,13 @@ llvm::Error 
CrossTranslationUnitContext::ASTLoader::lazyInitInvocationList() {
   llvm::Expected ExpectedInvocationList =
   parseInvocationList(ContentBuffer->getBuffer(), PathStyle);
 
-  if (!ExpectedInvocationList)
-return ExpectedInvocationList.takeError();
+  // Handle the error to store the code for next call to this function.
+  if (!ExpectedInvocationList) {
+llvm::handleAllErrors(
+ExpectedInvocationList.takeError(),
+[&](const IndexError &E) { PreviousParsingResult = E.getCode(); });
+return llvm::make_error(PreviousParsingResult);
+  }
 
   InvocationList = *ExpectedInvocationList;
 



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


[clang] f05b70c - Revert "[analyzer][ctu] Avoid parsing invocation list again and again during on-demand parsing of CTU"

2021-05-25 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2021-05-25T09:29:56+02:00
New Revision: f05b70c23687fdf3de349ab1dd99ad79c4c40e85

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

LOG: Revert "[analyzer][ctu] Avoid parsing invocation list again and again 
during on-demand parsing of CTU"

This reverts commit db8af0f21dc9aad4d336754c857c24470afe53e3.

clang-x86_64-debian-fast fails on this.

+ : 'RUN: at line 4'
+ /usr/bin/ccache
/b/1/clang-x86_64-debian-fast/llvm.src/clang/test/Analysis/ctu-on-demand-parsing-multiple-invocation-list-parsing.cpp
-fPIC -shared -o
/b/1/clang-x86_64-debian-fast/llvm.obj/tools/clang/test/Analysis/Output/ctu-on-demand-parsing-multiple-invocation-list-parsing.cpp.tmp/mock_open.so
ccache: error: execv of
/b/1/clang-x86_64-debian-fast/llvm.src/clang/test/Analysis/ctu-on-demand-parsing-multiple-invocation-list-parsing.cpp
failed: Permission denied

Added: 


Modified: 
clang/include/clang/CrossTU/CrossTranslationUnit.h
clang/lib/CrossTU/CrossTranslationUnit.cpp

Removed: 

clang/test/Analysis/ctu-on-demand-parsing-multiple-invocation-list-parsing.cpp



diff  --git a/clang/include/clang/CrossTU/CrossTranslationUnit.h 
b/clang/include/clang/CrossTU/CrossTranslationUnit.h
index d9f9c51fccd9c..b419b9be67cb9 100644
--- a/clang/include/clang/CrossTU/CrossTranslationUnit.h
+++ b/clang/include/clang/CrossTU/CrossTranslationUnit.h
@@ -38,7 +38,6 @@ class TranslationUnitDecl;
 namespace cross_tu {
 
 enum class index_error_code {
-  success = 0,
   unspecified = 1,
   missing_index_file,
   invalid_index_format,
@@ -254,7 +253,6 @@ class CrossTranslationUnitContext {
 /// In case of on-demand parsing, the invocations for parsing the source
 /// files is stored.
 llvm::Optional InvocationList;
-index_error_code PreviousParsingResult = index_error_code::success;
   };
 
   /// Maintain number of AST loads and check for reaching the load limit.

diff  --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp 
b/clang/lib/CrossTU/CrossTranslationUnit.cpp
index adee55304c871..640538cae3bbc 100644
--- a/clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -92,10 +92,6 @@ class IndexErrorCategory : public std::error_category {
 
   std::string message(int Condition) const override {
 switch (static_cast(Condition)) {
-case index_error_code::success:
-  // There should not be a success error. Jump to unreachable directly.
-  // Add this case to make the compiler stop complaining.
-  break;
 case index_error_code::unspecified:
   return "An unknown error has occurred.";
 case index_error_code::missing_index_file:
@@ -671,15 +667,12 @@ llvm::Error 
CrossTranslationUnitContext::ASTLoader::lazyInitInvocationList() {
   /// Lazily initialize the invocation list member used for on-demand parsing.
   if (InvocationList)
 return llvm::Error::success();
-  if (index_error_code::success != PreviousParsingResult)
-return llvm::make_error(PreviousParsingResult);
 
   llvm::ErrorOr> FileContent =
   llvm::MemoryBuffer::getFile(InvocationListFilePath);
-  if (!FileContent) {
-PreviousParsingResult = index_error_code::invocation_list_file_not_found;
-return llvm::make_error(PreviousParsingResult);
-  }
+  if (!FileContent)
+return llvm::make_error(
+index_error_code::invocation_list_file_not_found);
   std::unique_ptr ContentBuffer = std::move(*FileContent);
   assert(ContentBuffer && "If no error was produced after loading, the pointer 
"
   "should not be nullptr.");
@@ -687,13 +680,8 @@ llvm::Error 
CrossTranslationUnitContext::ASTLoader::lazyInitInvocationList() {
   llvm::Expected ExpectedInvocationList =
   parseInvocationList(ContentBuffer->getBuffer(), PathStyle);
 
-  // Handle the error to store the code for next call to this function.
-  if (!ExpectedInvocationList) {
-llvm::handleAllErrors(
-ExpectedInvocationList.takeError(),
-[&](const IndexError &E) { PreviousParsingResult = E.getCode(); });
-return llvm::make_error(PreviousParsingResult);
-  }
+  if (!ExpectedInvocationList)
+return ExpectedInvocationList.takeError();
 
   InvocationList = *ExpectedInvocationList;
 

diff  --git 
a/clang/test/Analysis/ctu-on-demand-parsing-multiple-invocation-list-parsing.cpp
 
b/clang/test/Analysis/ctu-on-demand-parsing-multiple-invocation-list-parsing.cpp
deleted file mode 100644
index 7121a798e3c27..0
--- 
a/clang/test/Analysis/ctu-on-demand-parsing-multiple-invocation-list-parsing.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-// RUN: rm -rf %t
-// RUN: mkdir -p %t
-
-// RUN: %host_cxx %s -fPIC -shared -o %t/mock_open.so
-
-// RUN: echo "void bar(); void foo() { bar(); bar(); }" > %t/trigger.c
-// RUN: echo "void bar() {}" > %t/im

[PATCH] D101763: [analyzer][ctu] Avoid parsing invocation list again and again during on-demand parsing of CTU

2021-05-25 Thread Balázs Benics via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdb8af0f21dc9: [analyzer][ctu] Avoid parsing invocation list 
again and again during on-demand… (authored by OikawaKirie, committed by 
steakhal).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101763

Files:
  clang/include/clang/CrossTU/CrossTranslationUnit.h
  clang/lib/CrossTU/CrossTranslationUnit.cpp
  clang/test/Analysis/ctu-on-demand-parsing-multiple-invocation-list-parsing.cpp

Index: clang/test/Analysis/ctu-on-demand-parsing-multiple-invocation-list-parsing.cpp
===
--- /dev/null
+++ clang/test/Analysis/ctu-on-demand-parsing-multiple-invocation-list-parsing.cpp
@@ -0,0 +1,56 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+
+// RUN: %host_cxx %s -fPIC -shared -o %t/mock_open.so
+
+// RUN: echo "void bar(); void foo() { bar(); bar(); }" > %t/trigger.c
+// RUN: echo "void bar() {}" > %t/importee.c
+// RUN: echo '[{"directory":"%t", "command":"cc -c %t/importee.c", "file": "%t/importee.c"}]' > %t/compile_commands.json
+// RUN: %clang_extdef_map -p %t "%t/importee.c" > %t/externalDefMap.txt
+
+// Add an empty invocation list to make the on-demand parsing fail and load it again.
+// RUN: echo '' > %t/invocations.yaml
+
+// RUN: cd %t && \
+// RUN: LD_PRELOAD=%t/mock_open.so \
+// RUN: %clang_cc1 -fsyntax-only -analyze \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config ctu-dir=. \
+// RUN:   -analyzer-config ctu-invocation-list=invocations.yaml \
+// RUN:   %t/trigger.c | FileCheck %s
+
+// REQUIRES: shell, system-linux
+
+// CHECK: {{Opening file invocations.yaml: 1}}
+// CHECK-NOT: {{Opening file invocations.yaml: 2}}
+
+#define _GNU_SOURCE 1
+#include 
+#include 
+
+#include 
+#include 
+#include 
+using namespace std;
+
+extern "C" int open(const char *name, int flag, ...) {
+  // Log how many times the invocation list is opened.
+  if ("invocations.yaml" == string(name)) {
+static unsigned N = 0;
+cout << "Opening file invocations.yaml: " << ++N << endl;
+  }
+
+  // The original open function will be called to open the files.
+  using open_t = int (*)(const char *, int, mode_t);
+  static open_t o_open = nullptr;
+  if (!o_open)
+o_open = reinterpret_cast(dlsym(RTLD_NEXT, "open"));
+  assert(o_open && "Cannot find function `open'.");
+
+  va_list vl;
+  va_start(vl, flag);
+  auto mode = va_arg(vl, mode_t);
+  va_end(vl);
+  return o_open(name, flag, mode);
+}
Index: clang/lib/CrossTU/CrossTranslationUnit.cpp
===
--- clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -92,6 +92,10 @@
 
   std::string message(int Condition) const override {
 switch (static_cast(Condition)) {
+case index_error_code::success:
+  // There should not be a success error. Jump to unreachable directly.
+  // Add this case to make the compiler stop complaining.
+  break;
 case index_error_code::unspecified:
   return "An unknown error has occurred.";
 case index_error_code::missing_index_file:
@@ -667,12 +671,15 @@
   /// Lazily initialize the invocation list member used for on-demand parsing.
   if (InvocationList)
 return llvm::Error::success();
+  if (index_error_code::success != PreviousParsingResult)
+return llvm::make_error(PreviousParsingResult);
 
   llvm::ErrorOr> FileContent =
   llvm::MemoryBuffer::getFile(InvocationListFilePath);
-  if (!FileContent)
-return llvm::make_error(
-index_error_code::invocation_list_file_not_found);
+  if (!FileContent) {
+PreviousParsingResult = index_error_code::invocation_list_file_not_found;
+return llvm::make_error(PreviousParsingResult);
+  }
   std::unique_ptr ContentBuffer = std::move(*FileContent);
   assert(ContentBuffer && "If no error was produced after loading, the pointer "
   "should not be nullptr.");
@@ -680,8 +687,13 @@
   llvm::Expected ExpectedInvocationList =
   parseInvocationList(ContentBuffer->getBuffer(), PathStyle);
 
-  if (!ExpectedInvocationList)
-return ExpectedInvocationList.takeError();
+  // Handle the error to store the code for next call to this function.
+  if (!ExpectedInvocationList) {
+llvm::handleAllErrors(
+ExpectedInvocationList.takeError(),
+[&](const IndexError &E) { PreviousParsingResult = E.getCode(); });
+return llvm::make_error(PreviousParsingResult);
+  }
 
   InvocationList = *ExpectedInvocationList;
 
Index: clang/include/clang/CrossTU/CrossTranslationUnit.h
===
--- clang/include/clang/CrossTU/CrossTranslationUnit.h
+++ clang/include/clang/CrossTU/CrossTranslationUnit.h
@@ -38,6 +38,7 @@
 namespace cross_tu {
 
 enum cl

[clang] db8af0f - [analyzer][ctu] Avoid parsing invocation list again and again during on-demand parsing of CTU

2021-05-25 Thread Balazs Benics via cfe-commits

Author: Ella Ma
Date: 2021-05-25T09:19:14+02:00
New Revision: db8af0f21dc9aad4d336754c857c24470afe53e3

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

LOG: [analyzer][ctu] Avoid parsing invocation list again and again during 
on-demand parsing of CTU

During CTU, the *on-demand parsing* will read and parse the invocation
list to know how to compile the file being imported. However, it seems
that the invocation list will be parsed again if a previous parsing
has failed.
Then, parse again and fail again. This patch tries to overcome the
problem by storing the error code during the first parsing, and
re-create the stored error during the later parsings.

Reviewed By: steakhal

Patch By: OikawaKirie!

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

Added: 

clang/test/Analysis/ctu-on-demand-parsing-multiple-invocation-list-parsing.cpp

Modified: 
clang/include/clang/CrossTU/CrossTranslationUnit.h
clang/lib/CrossTU/CrossTranslationUnit.cpp

Removed: 




diff  --git a/clang/include/clang/CrossTU/CrossTranslationUnit.h 
b/clang/include/clang/CrossTU/CrossTranslationUnit.h
index b419b9be67cb9..d9f9c51fccd9c 100644
--- a/clang/include/clang/CrossTU/CrossTranslationUnit.h
+++ b/clang/include/clang/CrossTU/CrossTranslationUnit.h
@@ -38,6 +38,7 @@ class TranslationUnitDecl;
 namespace cross_tu {
 
 enum class index_error_code {
+  success = 0,
   unspecified = 1,
   missing_index_file,
   invalid_index_format,
@@ -253,6 +254,7 @@ class CrossTranslationUnitContext {
 /// In case of on-demand parsing, the invocations for parsing the source
 /// files is stored.
 llvm::Optional InvocationList;
+index_error_code PreviousParsingResult = index_error_code::success;
   };
 
   /// Maintain number of AST loads and check for reaching the load limit.

diff  --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp 
b/clang/lib/CrossTU/CrossTranslationUnit.cpp
index 640538cae3bbc..adee55304c871 100644
--- a/clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -92,6 +92,10 @@ class IndexErrorCategory : public std::error_category {
 
   std::string message(int Condition) const override {
 switch (static_cast(Condition)) {
+case index_error_code::success:
+  // There should not be a success error. Jump to unreachable directly.
+  // Add this case to make the compiler stop complaining.
+  break;
 case index_error_code::unspecified:
   return "An unknown error has occurred.";
 case index_error_code::missing_index_file:
@@ -667,12 +671,15 @@ llvm::Error 
CrossTranslationUnitContext::ASTLoader::lazyInitInvocationList() {
   /// Lazily initialize the invocation list member used for on-demand parsing.
   if (InvocationList)
 return llvm::Error::success();
+  if (index_error_code::success != PreviousParsingResult)
+return llvm::make_error(PreviousParsingResult);
 
   llvm::ErrorOr> FileContent =
   llvm::MemoryBuffer::getFile(InvocationListFilePath);
-  if (!FileContent)
-return llvm::make_error(
-index_error_code::invocation_list_file_not_found);
+  if (!FileContent) {
+PreviousParsingResult = index_error_code::invocation_list_file_not_found;
+return llvm::make_error(PreviousParsingResult);
+  }
   std::unique_ptr ContentBuffer = std::move(*FileContent);
   assert(ContentBuffer && "If no error was produced after loading, the pointer 
"
   "should not be nullptr.");
@@ -680,8 +687,13 @@ llvm::Error 
CrossTranslationUnitContext::ASTLoader::lazyInitInvocationList() {
   llvm::Expected ExpectedInvocationList =
   parseInvocationList(ContentBuffer->getBuffer(), PathStyle);
 
-  if (!ExpectedInvocationList)
-return ExpectedInvocationList.takeError();
+  // Handle the error to store the code for next call to this function.
+  if (!ExpectedInvocationList) {
+llvm::handleAllErrors(
+ExpectedInvocationList.takeError(),
+[&](const IndexError &E) { PreviousParsingResult = E.getCode(); });
+return llvm::make_error(PreviousParsingResult);
+  }
 
   InvocationList = *ExpectedInvocationList;
 

diff  --git 
a/clang/test/Analysis/ctu-on-demand-parsing-multiple-invocation-list-parsing.cpp
 
b/clang/test/Analysis/ctu-on-demand-parsing-multiple-invocation-list-parsing.cpp
new file mode 100644
index 0..7121a798e3c27
--- /dev/null
+++ 
b/clang/test/Analysis/ctu-on-demand-parsing-multiple-invocation-list-parsing.cpp
@@ -0,0 +1,56 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+
+// RUN: %host_cxx %s -fPIC -shared -o %t/mock_open.so
+
+// RUN: echo "void bar(); void foo() { bar(); bar(); }" > %t/trigger.c
+// RUN: echo "void bar() {}" > %t/importee.c
+// RUN: echo '[{"directory":"%t", "command":"cc -c %t/importee.c", "file": 
"%t/importee.c"}

[PATCH] D102989: Align documentation in Format.h and ClangFormatStyleOptions.rst for EmptyLineAfterAccessModifier

2021-05-25 Thread Max Sagebaum via Phabricator via cfe-commits
Max_S added a comment.

I added the setting in the title.

Could you please land this for me. Thank.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102989

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


[PATCH] D98895: [X86][Draft] Disable long double type for -mno-x87 option

2021-05-25 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/test/Sema/x86-no-x87.c:2
+// RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-linux-gnu 
-target-feature -x87
+// RUN: %clang_cc1 -fsyntax-only -verify %s -triple i686-linux-gnu 
-target-feature -x87
+// RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-windows-msvc 
-target-feature -x87 -DNOERROR

Should i686 expect no error like GCC?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98895

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