[PATCH] D79744: clang: Add address space to indirect abi info and use it for kernels

2020-05-16 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

I don't understand why `noalias` is even a concern if the whole buffer passed 
to the kernel is read-only.  `noalias` is primarily about proving 
non-interference, but if you can tell IR that the buffer is read-only, that's a 
much more powerful statement.

Regardless, if you do need `noalias`, you should be able to emit the same IR 
that we'd emit if pointers to all the fields were assigned into `restrict` 
local variables and then only those variables were subsequently used.


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

https://reviews.llvm.org/D79744



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


[PATCH] D77491: [Sema] Introduce BuiltinAttr, per-declaration builtin-ness

2020-05-16 Thread Raul Tambre via Phabricator via cfe-commits
tambre updated this revision to Diff 264447.
tambre marked 3 inline comments as done.
tambre added a comment.

Fix adding BuiltinAttr in C++ mode. Update one test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77491

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/IdentifierTable.h
  clang/lib/AST/Decl.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/AST/ast-dump-attr.cpp
  clang/test/CodeGen/builtin-redeclaration.c
  clang/test/Sema/implicit-builtin-decl.c

Index: clang/test/Sema/implicit-builtin-decl.c
===
--- clang/test/Sema/implicit-builtin-decl.c
+++ clang/test/Sema/implicit-builtin-decl.c
@@ -60,12 +60,15 @@
 
 extern float fmaxf(float, float);
 
-struct __jmp_buf_tag {};
-void sigsetjmp(struct __jmp_buf_tag[1], int); // expected-warning{{declaration of built-in function 'sigsetjmp' requires the declaration of the 'jmp_buf' type, commonly provided in the header .}}
+typedef struct __jmp_buf_tag {
+} sigjmp_buf[1];
 
-// CHECK: FunctionDecl {{.*}}  col:6 sigsetjmp '
+int sigsetjmp(struct __jmp_buf_tag[1], int);
+
+// CHECK: FunctionDecl {{.*}}  col:5 implicit sigsetjmp '
+// CHECK: FunctionDecl {{.*}}  col:5 sigsetjmp '
 // CHECK-NOT: FunctionDecl
-// CHECK: ReturnsTwiceAttr {{.*}} <{{.*}}> Implicit
+// CHECK: ReturnsTwiceAttr {{.*}} <{{.*}}> Inherited Implicit
 
 // PR40692
 void pthread_create(); // no warning expected
Index: clang/test/CodeGen/builtin-redeclaration.c
===
--- /dev/null
+++ clang/test/CodeGen/builtin-redeclaration.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -emit-llvm-only %s
+
+// PR45410
+// Ensure we mark local extern redeclarations with a different type as non-builtin.
+void non_builtin() {
+  extern float exp();
+  exp(); // Will crash due to wrong number of arguments if this calls the builtin.
+}
+
+// PR45410
+// We mark exp() builtin as const with -fno-math-errno (default).
+// We mustn't do that for extern redeclarations of builtins where the type differs.
+float attribute() {
+  extern float exp();
+  return exp(1);
+}
Index: clang/test/AST/ast-dump-attr.cpp
===
--- clang/test/AST/ast-dump-attr.cpp
+++ clang/test/AST/ast-dump-attr.cpp
@@ -109,6 +109,7 @@
 extern "C" int printf(const char *format, ...);
 // CHECK: FunctionDecl{{.*}}printf
 // CHECK-NEXT: ParmVarDecl{{.*}}format{{.*}}'const char *'
+// CHECK-NEXT: BuiltinAttr{{.*}}Implicit
 // CHECK-NEXT: FormatAttr{{.*}}Implicit printf 1 2
 
 alignas(8) extern int x;
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -2108,6 +2108,7 @@
false,
R->isFunctionProtoType());
   New->setImplicit();
+  New->addAttr(BuiltinAttr::CreateImplicit(Context, ID));
 
   // Create Decl objects for each parameter, adding them to the
   // FunctionDecl.
@@ -3330,7 +3331,11 @@
   // there but not here.
   NewTypeInfo = NewTypeInfo.withCallingConv(OldTypeInfo.getCC());
   RequiresAdjustment = true;
-} else if (New->getBuiltinID()) {
+} else if (Old->getBuiltinID()) {
+  // Builtin attribute isn't propagated to the new one yet at this point.
+  // Check if the old is a builtin.
+  // TODO: Maybe we should only warn if the redeclaration is compatible?
+
   // Calling Conventions on a Builtin aren't really useful and setting a
   // default calling convention and cdecl'ing some builtin redeclarations is
   // common, so warn and ignore the calling convention on the redeclaration.
@@ -3756,6 +3761,7 @@
   // If the previous declaration was an implicitly-generated builtin
   // declaration, then at the very least we should use a specialized note.
   unsigned BuiltinID;
+  // TODO: Remove isImplicit check?
   if (Old->isImplicit() && (BuiltinID = Old->getBuiltinID())) {
 // If it's actually a library-defined builtin function like 'malloc'
 // or 'printf', just warn about the incompatible redeclaration.
@@ -8859,6 +8865,20 @@
 if (D.isInvalidType())
   NewFD->setInvalidDecl();
 
+// In C builtins get merged with implicitly lazily created declarations.
+// In C++ we need to check if it's a builtin and add the BuiltinAttr here.
+if (IdentifierInfo *II = Previous.getLookupName().getAsIdentifierInfo()) {
+  if (II->getBuiltinID()) {
+// A builtin needs to have C linkage.
+LinkageSpecDecl *linkage =
+dyn_cast(NewFD->getFirstDecl()->getDeclContext());
+if (linkage && linkage->getLanguage() == LinkageSpecDecl::lang_c) {
+  NewFD->addAttr(
+  BuiltinAttr::CreateImplicit(Context, II->getBuiltinID()));
+}
+  

[PATCH] D79744: clang: Add address space to indirect abi info and use it for kernels

2020-05-16 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

Drive by, I haven't read the entire history.

In D79744#2040208 , @rjmccall wrote:

> I don't understand why `noalias` is even a concern if the whole buffer passed 
> to the kernel is read-only.  `noalias` is primarily about proving 
> non-interference, but if you can tell IR that the buffer is read-only, that's 
> a much more powerful statement.


The problem is that it is a "per-pointer" attribute and not "per-object". Given 
two argument pointers, where one is marked `readonly`, may still alias. 
Similarly, an access to a global, indirect accesses, ... can write the 
"readonly" memory. Hence, the `readonly` is pretty useless *in the callee* if 
other accesses can write the memory. The `readonly` is useful in the caller 
though, usually if we have basically `noalias` information there (e.g., it is 
an alloca). `Noalias` is useful in the callee regardless of `readonly` but even 
better with.

> Regardless, if you do need `noalias`, you should be able to emit the same IR 
> that we'd emit if pointers to all the fields were assigned into `restrict` 
> local variables and then only those variables were subsequently used.

We are still debating the local restrict pointer support. Once we merge that in 
it should be usable here.


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

https://reviews.llvm.org/D79744



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


[clang] 0ee46e8 - [nfc] test commit

2020-05-16 Thread faisal vali via cfe-commits

Author: faisal vali
Date: 2020-05-16T15:08:30-05:00
New Revision: 0ee46e857d81ea815e5b11d266c0c118a2c2e714

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

LOG: [nfc] test commit

Added: 


Modified: 
clang/README.txt

Removed: 




diff  --git a/clang/README.txt b/clang/README.txt
index 91527b094856..5f50e152f9f1 100644
--- a/clang/README.txt
+++ b/clang/README.txt
@@ -24,3 +24,5 @@ on the Clang development mailing list:
 
 If you find a bug in Clang, please file it in the LLVM bug tracker:
   http://llvm.org/bugs/
+
+



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


[PATCH] D79655: [WebAssembly] Handle exception specifications

2020-05-16 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

The revert broke check-clang on several bots, e.g. here 
http://lab.llvm.org:8011/builders/clang-ppc64be-linux-lnt/builds/38159

Can you take a look please? The tree's been red all of today due to this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79655



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


[PATCH] D76077: [ARM] Add __bf16 as new Bfloat16 C Type

2020-05-16 Thread Ties Stuij via Phabricator via cfe-commits
stuij marked 4 inline comments as done.
stuij added a comment.

@LukeGeeson: you're already mentioned :) See the commits tab on this review. 
But Simon Tatham needs a mention as well. I shall add him.




Comment at: clang/docs/LanguageExtensions.rst:518
+Clang supports three half-precision (16-bit) floating point types: ``__fp16``,
+``_Float16`` and ``__bf16``.  These types are supported in all language modes.
 

SjoerdMeijer wrote:
> Not my field of expertise, and sorry if I've missed this somewhere, but was 
> wondering if this (i.e. all language modes) means we need C++ name mangling 
> support for bfloat? In the AArch64 backend I saw this:
> 
>   getBFloat16Mangling() const override { return "u6__bf16"; }
> 
> But that's something else I guess, and I was guessing a 2 letter mangling 
> needs to be added here?
> 
> https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-builtin
Yes, we need name-mangling support, and yes that method you mentioned does 
that. There's one for AArch32 as well. And yes we have documented it in the 
'C++ ABI for the latest Arm Architecture' docs:

aarch32: https://developer.arm.com/docs/ihi0041/latest
aarch64: https://developer.arm.com/docs/ihi0059/latest



Comment at: clang/include/clang-c/Index.h:3254
   CXType_FirstBuiltin = CXType_Void,
   CXType_LastBuiltin = CXType_ULongAccum,
 

majnemer wrote:
> Should this be:
>   CXType_LastBuiltin = CXType_BFloat16,
> 
thanks



Comment at: clang/lib/AST/ItaniumMangle.cpp:3186
+case BuiltinType::Half:  EltName = "float16_t"; break;
+case BuiltinType::BFloat16:  EltName = "bfloat16x1_t"; break;
 default:

majnemer wrote:
> Why is this x1?
Yes, that does look odd. The original author of this code has left the company, 
but I'll ask around.



Comment at: clang/lib/Sema/SemaOverload.cpp:1873-1874
 // We of course allow this conversion if long double is really double.
+if (FromType == S.Context.BFloat16Ty || ToType == S.Context.BFloat16Ty)
+  return false;
 if ((FromType) !=

majnemer wrote:
> This probably needs an explanation.
done


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76077



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


[PATCH] D79919: [Driver] Pass -plugin-opt=O2 for -Os -Oz and -plugin-opt=O1 for -Og

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

Great! Maybe worth to add a release note that -Os works with LTO?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79919



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


[clang] 49c9a68 - The release notes for ObjCBreakBeforeNestedBlockParam was placed between the release note for IndentCaseBlocks and its example code

2020-05-16 Thread via cfe-commits

Author: mydeveloperday
Date: 2020-05-16T18:52:13+01:00
New Revision: 49c9a68d7fc62aabdf4d625fcb2954555496772b

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

LOG: The release notes for ObjCBreakBeforeNestedBlockParam was placed between 
the release note for IndentCaseBlocks and its example code

Remove other whitespace and line limit issues and double blank line issues

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 317b6c191628..8dd22887a195 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -67,8 +67,9 @@ Non-comprehensive list of changes in this release
 - clang adds support for a set of  extended integer types (``_ExtInt(N)``) that
   permit non-power of 2 integers, exposing the LLVM integer types. Since a 
major
   motivating use case for these types is to limit 'bit' usage, these types 
don't
-  automatically promote to 'int' when operations are done between two 
``ExtInt(N)``
-  types, instead math occurs at the size of the largest ``ExtInt(N)`` type.
+  automatically promote to 'int' when operations are done between two
+  ``ExtInt(N)`` types, instead math occurs at the size of the largest
+  ``ExtInt(N)`` type.
 
 - Users of UBSan, PGO, and coverage on Windows will now need to add clang's
   library resource directory to their library search path. These features all
@@ -81,17 +82,15 @@ Non-comprehensive list of changes in this release
   linker. If the user links the program with the ``clang`` or ``clang-cl``
   drivers, the driver will pass this flag for them.
 
-
 New Compiler Flags
 --
 
-
 - -fstack-clash-protection will provide a protection against the stack clash
   attack for x86 architecture through automatic probing of each page of
   allocated stack.
 
 - -ffp-exception-behavior={ignore,maytrap,strict} allows the user to specify
-  the floating-point exception behavior.  The default setting is ``ignore``.
+  the floating-point exception behavior. The default setting is ``ignore``.
 
 - -ffp-model={precise,strict,fast} provides the user an umbrella option to
   simplify access to the many single purpose floating point options. The 
default
@@ -110,11 +109,11 @@ Modified Compiler Flags
 
 - -fno-common has been enabled as the default for all targets.  Therefore, C
   code that uses tentative definitions as definitions of a variable in multiple
-  translation units will trigger multiple-definition linker errors.  Generally,
-  this occurs when the use of the ``extern`` keyword is neglected in the 
declaration
-  of a variable in a header file. In some cases, no specific translation unit
-  provides a definition of the variable. The previous behavior can be restored 
by
-  specifying ``-fcommon``.
+  translation units will trigger multiple-definition linker errors. Generally,
+  this occurs when the use of the ``extern`` keyword is neglected in the
+  declaration of a variable in a header file. In some cases, no specific
+  translation unit provides a definition of the variable. The previous
+  behavior can be restored by specifying ``-fcommon``.
 - -Wasm-ignored-qualifier (ex. `asm const ("")`) has been removed and replaced
   with an error (this matches a recent change in GCC-9).
 - -Wasm-file-asm-volatile (ex. `asm volatile ("")` at global scope) has been
@@ -176,7 +175,7 @@ C++ Language Changes in Clang
   Previous versions of Clang rejected some constructs of this form
   (specifically, where the linkage of the type happened to be computed
   before the parser reached the typedef name); those cases are still rejected
-  in Clang 11.  In addition, cases that previous versions of Clang did not
+  in Clang 11. In addition, cases that previous versions of Clang did not
   reject now produce an extension warning. This warning can be disabled with
   the warning flag ``-Wno-non-c-typedef-for-linkage``.
 
@@ -207,7 +206,6 @@ C++1z Feature Support
 Objective-C Language Changes in Clang
 -
 
-
 OpenCL C Language Changes in Clang
 --
 
@@ -216,7 +214,6 @@ OpenCL C Language Changes in Clang
 ABI Changes in Clang
 
 
-
 OpenMP Support in Clang
 ---
 
@@ -234,7 +231,6 @@ These are major API changes that have happened since the 
10.0.0 release of
 Clang. If upgrading an external codebase that uses Clang as a library,
 this section should help get you past the largest hurdles of upgrading.
 
-
 Build System Changes
 
 
@@ -255,15 +251,11 @@ AST Matchers
 clang-format
 
 
-
 - Option ``IndentCaseBlocks`` has been added to support treating the block
   following a switch case label as a scope block 

[PATCH] D80046: [StackSafety] Make full LTO to attach metadata if MTE is enabled

2020-05-16 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

If I'm understanding this correctly, the stack-safe metadata on allocas is both 
produced and consumed at LTO-time.  So at the point where the stack-safe 
metadata would be produced, we can compute whether any later passes will query 
it.

Given that, why do you need a module flag?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80046



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


[PATCH] D79322: [FEnv] Small fixes to implementation of flt.rounds

2020-05-16 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/test/CodeGen/RISCV/flt-rounds.ll:23
+; RV64I-NEXT:sd ra, 8(sp)
+; RV64I-NEXT:call __flt_rounds
+; RV64I-NEXT:ld ra, 8(sp)

sepavloff wrote:
> lenary wrote:
> > I'm interested to understand how this function is provided. Is it part of 
> > `compiler-rt` or `libgcc`, or is it provided another way?
> At least musl library provides its implementation: 
> https://git.musl-libc.org/cgit/musl/tree/src/fenv/__flt_rounds.c . Similar 
> implementation exists in glibc.
A quick google search for "glibc __flt_rounds" only shows it in a powerpc nofpu 
file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79322



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


[clang] 32870a8 - Expose IRGen API to add the default IR attributes to a function definition.

2020-05-16 Thread John McCall via cfe-commits

Author: John McCall
Date: 2020-05-16T14:44:54-04:00
New Revision: 32870a84d9a40ea682e22a24b5f0d1a218c3b062

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

LOG: Expose IRGen API to add the default IR attributes to a function definition.

I've also made a stab at imposing some more order on where and how we add
attributes; this part should be NFC.  I wasn't sure whether the CUDA use
case for libdevice should propagate CPU/features attributes, so there's a
bit of unnecessary duplication.

Added: 


Modified: 
clang/include/clang/CodeGen/CodeGenABITypes.h
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CodeGenABITypes.cpp
clang/lib/CodeGen/CodeGenAction.cpp
clang/lib/CodeGen/CodeGenModule.h

Removed: 




diff  --git a/clang/include/clang/CodeGen/CodeGenABITypes.h 
b/clang/include/clang/CodeGen/CodeGenABITypes.h
index 5f4af7fd2a36..255e1603509e 100644
--- a/clang/include/clang/CodeGen/CodeGenABITypes.h
+++ b/clang/include/clang/CodeGen/CodeGenABITypes.h
@@ -28,6 +28,7 @@
 #include "clang/CodeGen/CGFunctionInfo.h"
 
 namespace llvm {
+class AttrBuilder;
 class Constant;
 class DataLayout;
 class Module;
@@ -86,6 +87,25 @@ llvm::Type *convertTypeForMemory(CodeGenModule , 
QualType T);
 unsigned getLLVMFieldNumber(CodeGenModule ,
 const RecordDecl *RD, const FieldDecl *FD);
 
+/// Given the language and code-generation options that Clang was configured
+/// with, set the default LLVM IR attributes for a function definition.
+/// The attributes set here are mostly global target-configuration and
+/// pipeline-configuration options like the target CPU, variant stack
+/// rules, whether to optimize for size, and so on.  This is useful for
+/// frontends (such as Swift) that generally intend to interoperate with
+/// C code and rely on Clang's target configuration logic.
+///
+/// As a general rule, this function assumes that meaningful attributes
+/// haven't already been added to the builder.  It won't intentionally
+/// displace any existing attributes, but it also won't check to avoid
+/// overwriting them.  Callers should generally apply customizations after
+/// making this call.
+///
+/// This function assumes that the caller is not defining a function that
+/// requires special no-builtin treatment.
+void addDefaultFunctionDefinitionAttributes(CodeGenModule ,
+llvm::AttrBuilder );
+
 /// Returns the default constructor for a C struct with non-trivially copyable
 /// fields, generating it if necessary. The returned function uses the `cdecl`
 /// calling convention, returns void, and takes a single argument that is a

diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 068d053d17cc..b8bd8a780e50 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1700,8 +1700,9 @@ static void AddAttributesFromFunctionProtoType(ASTContext 
,
 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
 }
 
-void CodeGenModule::ConstructDefaultFnAttrList(StringRef Name, bool HasOptnone,
-   bool AttrOnCallSite,
+void CodeGenModule::getDefaultFunctionAttributes(StringRef Name,
+ bool HasOptnone,
+ bool AttrOnCallSite,
llvm::AttrBuilder ) {
   // OptimizeNoneAttr takes precedence over -Os or -Oz. No warning needed.
   if (!HasOptnone) {
@@ -1796,6 +1797,8 @@ void CodeGenModule::ConstructDefaultFnAttrList(StringRef 
Name, bool HasOptnone,
   FuncAttrs.addAttribute("stackrealign");
 if (CodeGenOpts.Backchain)
   FuncAttrs.addAttribute("backchain");
+if (CodeGenOpts.EnableSegmentedStacks)
+  FuncAttrs.addAttribute("split-stack");
 
 if (CodeGenOpts.SpeculativeLoadHardening)
   FuncAttrs.addAttribute(llvm::Attribute::SpeculativeLoadHardening);
@@ -1822,13 +1825,21 @@ void 
CodeGenModule::ConstructDefaultFnAttrList(StringRef Name, bool HasOptnone,
   }
 }
 
-void CodeGenModule::AddDefaultFnAttrs(llvm::Function ) {
+void CodeGenModule::addDefaultFunctionDefinitionAttributes(llvm::Function ) {
   llvm::AttrBuilder FuncAttrs;
-  ConstructDefaultFnAttrList(F.getName(), F.hasOptNone(),
- /* AttrOnCallSite = */ false, FuncAttrs);
+  getDefaultFunctionAttributes(F.getName(), F.hasOptNone(),
+   /* AttrOnCallSite = */ false, FuncAttrs);
+  // TODO: call GetCPUAndFeaturesAttributes?
   F.addAttributes(llvm::AttributeList::FunctionIndex, FuncAttrs);
 }
 
+void CodeGenModule::addDefaultFunctionDefinitionAttributes(
+   llvm::AttrBuilder ) {
+  

[clang] accd9af - Revert "[nfc] test commit"

2020-05-16 Thread faisal vali via cfe-commits

Author: faisal vali
Date: 2020-05-16T15:12:04-05:00
New Revision: accd9af838b071ff6e8ba4ff3c99a2542cd0ce25

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

LOG: Revert "[nfc] test commit"

This reverts commit 0ee46e857d81ea815e5b11d266c0c118a2c2e714.

Added: 


Modified: 
clang/README.txt

Removed: 




diff  --git a/clang/README.txt b/clang/README.txt
index 5f50e152f9f1..91527b094856 100644
--- a/clang/README.txt
+++ b/clang/README.txt
@@ -24,5 +24,3 @@ on the Clang development mailing list:
 
 If you find a bug in Clang, please file it in the LLVM bug tracker:
   http://llvm.org/bugs/
-
-



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


[PATCH] D75791: [clang-format] Added new option IndentExternBlock

2020-05-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.
This revision is now accepted and ready to land.

LGTM just drop the `Noindent` it will encourage inconsistency people can read 
the manual  (plus you don't check it in the tests)




Comment at: clang/lib/Format/Format.cpp:215
+IO.enumCase(Value, "NoIndent", FormatStyle::IEBS_NoIndent);
+IO.enumCase(Value, "Noindent", FormatStyle::IEBS_NoIndent);
+IO.enumCase(Value, "true", FormatStyle::IEBS_Indent);

I don't think that's necessary


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

https://reviews.llvm.org/D75791



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


[PATCH] D77491: [Sema] Introduce BuiltinAttr, per-declaration builtin-ness

2020-05-16 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

@rsmith This is a big enough architectural change that I'd appreciate your 
sign-off on the basic approach.




Comment at: clang/lib/Sema/SemaDecl.cpp:3759
   unsigned BuiltinID;
-  if (Old->isImplicit() && (BuiltinID = Old->getBuiltinID())) {
+  bool RevertedBuiltin{Old->getIdentifier()->hasRevertedBuiltin()};
+  if (Old->isImplicit() &&

rjmccall wrote:
> The old code didn't check this eagerly.  The `Old->isImplicit()` check is 
> unlikely to fire; please make sure that we don't do any extra work unless it 
> does.
Since BuiltinAttr is inherited, we should keep the isImplicit check, because we 
only want to use a special diagnostic when "redeclaring" the implicit builtin 
declaration.



Comment at: clang/lib/Sema/SemaDecl.cpp:8880
+  }
+}
+

Hmm.  I'm concerned about not doing any sort of semantic compatibility check 
here before we assign the function special semantics.  Have we really never 
done those in C++?

If not, I wonder if we can reasonably make an implicit declaration but just 
make it hidden from lookup.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77491



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


[clang] bc98dc1 - Try to heal bots after https://reviews.llvm.org/D79655

2020-05-16 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2020-05-16T20:32:58-04:00
New Revision: bc98dc12d8382b45ff9beed82236c9274f4435ff

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

LOG: Try to heal bots after https://reviews.llvm.org/D79655

Added: 


Modified: 
clang/test/CodeGenCXX/wasm-eh.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/wasm-eh.cpp 
b/clang/test/CodeGenCXX/wasm-eh.cpp
index 2d56c6bd0cb7..17f325bd9eba 100644
--- a/clang/test/CodeGenCXX/wasm-eh.cpp
+++ b/clang/test/CodeGenCXX/wasm-eh.cpp
@@ -1,4 +1,10 @@
 // REQUIRES: webassembly-registered-target
+// https://reviews.llvm.org/D79655 temporarily added a RUN line that was 
missing
+// a -o flag and wrote to the source dir. The file it wrote was then 
interpreted
+// as a test without RUN line, breaking bots. FIXME: Remove this rm line once
+// it's been in the tree long enough to clean up everyone's build dirs.
+// Removing this June 2020 should be fine.
+// RUN: rm -f %S/wasm-eh.ll
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
 // RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -S -o - -std=c++11 | FileCheck %s --check-prefix=ASSEMBLY



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


[PATCH] D77221: [AVR] Rework MCU family detection to support more AVR MCUs

2020-05-16 Thread Dylan McKay via Phabricator via cfe-commits
dylanmckay added a comment.

@aykevl

> A thought: should the AVR family be included in the target triple? Like 
> avr5-unknown-unknown (similar to armv6m-none-eabi, armv7m-none-eabi, etc).
>  The different variations do sometimes change the architecture in 
> incompatible ways, such as with the call instruction which pushes a return 
> address of two or three bytes depending on the architecture variant (and thus 
> makes it impossible to pass parameters on the stack reliably).

I've thought about this a few years ago, I suspect it is not possible. It seems 
like we really do need to compile a sysroot/stdlib/runtime libraries for each 
and every distinct MCU.

https://github.com/rust-lang/rust/issues/44036#issuecomment-324330757

>> Does each device have a subtly different ISA?
> 
> **tl;dr** Sometimes, yes
> 
> In general, all devices can be _more or less_ grouped into families.
> 
> For example, `avr1`, `avr2`, `avr25`, ... `avr5`, `avr51`, are all family 
> names. These families each define an subset of the full AVR ISA.
> 
> You can find the AVR backend's definition of these families in AVRDevices.td 
> .
>  You can see that in general, the families build up on top of each other in 
> terms of supported instructions/features.
> 
> The problem is that not every realised ISA can be cleanly separated into a 
> family.
> 
> For example, the ATtiny26 
> 
>  is a part of the `avr2` family, but it also happens to support the "LPMX" 
> set of instructions
> 
> Another example is the ATMega8515 
> ,
>  which _almost_ implements all of `avr4`, but not quite all, and so the 
> linked definition bases the device off `avr2` and adds the extra features 
> explicitly.
> 
>> Does the backend need to know about peripherals?
> 
> No
> 
>> Or why do you want the LLVM backend to know when it's targeting, for 
>> example, "atmega328"?
> 
> Solely for deciding what subset of the ISA is supported.All device-specific 
> information required (or used) by the backend can be found inside 
> AVRDevices.td 
> .

There is a bunch of other related discussion on 
https://github.com/rust-lang/rust/issues/44036 too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77221



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


[clang] 3735505 - Fix a few doc typos to cycle bots.

2020-05-16 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2020-05-16T20:38:28-04:00
New Revision: 3735505e4ffd0117de93d344fc0549151a205d11

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

LOG: Fix a few doc typos to cycle bots.

Added: 


Modified: 
clang/docs/ConstantInterpreter.rst

Removed: 




diff  --git a/clang/docs/ConstantInterpreter.rst 
b/clang/docs/ConstantInterpreter.rst
index 67a17c75607e..c976f35a67c5 100644
--- a/clang/docs/ConstantInterpreter.rst
+++ b/clang/docs/ConstantInterpreter.rst
@@ -245,7 +245,7 @@ have their own type:
 
 Void pointers, which can be built by casting any of the aforementioned
 pointers, are implemented as a union of all pointer types. The ``BitCast``
-opcode is reponsible for performing all legal conversions between these
+opcode is responsible for performing all legal conversions between these
 types and primitive integers.
 
 BlockPointer
@@ -339,7 +339,7 @@ base offset, along with a descriptor specifying the type 
the pointer is
 supposed to refer to. Array indexing adjusts the array offset, while the
 field offset is adjusted when a pointer to a member is created. Casting
 an integer to a pointer sets the value of the base offset. As a special
-case, null pointers are target pointers with all offets set to 0.
+case, null pointers are target pointers with all offsets set to 0.
 
 TypeInfoPointer
 ~~~



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


[PATCH] D79754: [OpenMP][AMDGCN] Support OpenMP offloading for AMDGCN architecture - Part 1

2020-05-16 Thread Sameer Sahasrabuddhe via Phabricator via cfe-commits
sameerds added inline comments.



Comment at: clang/lib/AST/Decl.cpp:3221
+!hasAttr()) ||
+   Context.getTargetInfo().getTriple().isAMDGCN()) &&
   !(BuiltinID == Builtin::BIprintf || BuiltinID == Builtin::BImalloc))

sameerds wrote:
> This seems awkward to me. Why mix it up with only CUDA and HIP? The earlier 
> factoring is better, where CUDA/HIP took care of their own business, and the 
> catch-all case of AMDGCN was a separate clause by itself. It doesn't matter 
> that the builtins being checked for AMDGCN on OpenMP are //currently// 
> identical to CUDA/HIP. When this situation later changes (I am sure OpenMP 
> will support more builtins), we will have to split it out again anyway.
This clause seems to assume that AMDGCN automatically means OpenMP whenever it 
is not HIP. That does not sound right. Is there a Context.getLangOpts().OpenMP 
flag? If not, why not? There also seems to be an Opts.OpenMPIsDevice ... 
perhaps that could be used here to write a separate OpenMP clause?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79754



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


[PATCH] D80061: [WebAssembly] Handle exception specifications

2020-05-16 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin updated this revision to Diff 264466.
aheejin added a comment.

- Add missing `-` after `-o`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80061

Files:
  clang/docs/DiagnosticsReference.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGException.cpp
  clang/test/CodeGenCXX/wasm-eh.cpp

Index: clang/test/CodeGenCXX/wasm-eh.cpp
===
--- clang/test/CodeGenCXX/wasm-eh.cpp
+++ clang/test/CodeGenCXX/wasm-eh.cpp
@@ -7,7 +7,6 @@
 // RUN: rm -f %S/wasm-eh.ll
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
 // RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
-// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -S -o - -std=c++11 | FileCheck %s --check-prefix=ASSEMBLY
 
 void may_throw();
 void dont_throw() noexcept;
@@ -391,9 +390,34 @@
 
 // CHECK:   unreachable
 
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-DEFAULT
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -Wwasm-exception-spec -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-ON
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -Wno-wasm-exception-spec -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-OFF
+
+// Wasm ignores dynamic exception specifications with types at the moment. This
+// is controlled by -Wwasm-exception-spec, which is on by default. This warning
+// can be suppressed with -Wno-wasm-exception-spec.
+// Checks if a warning message is correctly printed or not printed depending on
+// the options.
+void test9() throw(int) {
+}
+// WARNING-DEFAULT: warning: dynamic exception specifications with types are currently ignored in wasm
+// WARNING-ON: warning: dynamic exception specifications with types are currently ignored in wasm
+// WARNING-OFF-NOT: warning: dynamic exception specifications with types are currently ignored in wasm
+
+// Wasm curremtly treats 'throw()' in the same way as 'noexept'. Check if the
+// same warning message is printed as if when a 'noexcept' function throws.
+void test10() throw() {
+  throw 3;
+}
+// WARNING-DEFAULT: warning: 'test10' has a non-throwing exception specification but can still throw
+// WARNING-DEFAULT: function declared non-throwing here
+
 // Here we only check if the command enables wasm exception handling in the
 // backend so that exception handling instructions can be generated in .s file.
 
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -S -o - -std=c++11 | FileCheck %s --check-prefix=ASSEMBLY
+
 // ASSEMBLY: try
 // ASSEMBLY: catch
 // ASSEMBLY: rethrow
Index: clang/lib/CodeGen/CGException.cpp
===
--- clang/lib/CodeGen/CGException.cpp
+++ clang/lib/CodeGen/CGException.cpp
@@ -20,6 +20,7 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/TargetBuiltins.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
@@ -468,6 +469,18 @@
 // encode these in an object file but MSVC doesn't do anything with it.
 if (getTarget().getCXXABI().isMicrosoft())
   return;
+// In wasm we currently treat 'throw()' in the same way as 'noexcept'. In
+// case of throw with types, we ignore it and print a warning for now.
+// TODO Correctly handle exception specification in wasm
+if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly) {
+  if (EST == EST_DynamicNone)
+EHStack.pushTerminate();
+  else
+CGM.getDiags().Report(D->getLocation(),
+  diag::warn_wasm_dynamic_exception_spec_ignored)
+<< FD->getExceptionSpecSourceRange();
+  return;
+}
 unsigned NumExceptions = Proto->getNumExceptions();
 EHFilterScope *Filter = EHStack.pushFilter(NumExceptions);
 
@@ -544,6 +557,14 @@
 // encode these in an object file but MSVC doesn't do anything with it.
 if 

[PATCH] D79655: [WebAssembly] Handle exception specifications

2020-05-16 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: clang/test/CodeGenCXX/wasm-eh.cpp:387
 
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -emit-llvm -std=c++11 2>&1 | FileCheck %s 
--check-prefix=WARNING
+

Ah, the problem is that this line is missing a -o flag and so it wrote a 
wasm-eh.ll file to the clang/test/CodeGenCXX directory, which on the next build 
was interpreted as a test without a run line. I'll land a temporary rm here to 
remove that file. Please fix this for the reland.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79655



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


[PATCH] D75791: [clang-format] Added new option IndentExternBlock

2020-05-16 Thread Marcus Johnson via Phabricator via cfe-commits
MarcusJohnson91 marked an inline comment as done.
MarcusJohnson91 added a comment.

Removed the lowercase Noindent case, that was a last minute addition I thought 
might make it a tad easier to work with, but you're right I didn't even test 
it, and honestly adding that complexity is just pointless at best.

Removed.


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

https://reviews.llvm.org/D75791



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


[PATCH] D79744: clang: Add address space to indirect abi info and use it for kernels

2020-05-16 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D79744#2040348 , @jdoerfert wrote:

> Drive by, I haven't read the entire history.
>
> In D79744#2040208 , @rjmccall wrote:
>
> > I don't understand why `noalias` is even a concern if the whole buffer 
> > passed to the kernel is read-only.  `noalias` is primarily about proving 
> > non-interference, but if you can tell IR that the buffer is read-only, 
> > that's a much more powerful statement.
>
>
> The problem is that it is a "per-pointer" attribute and not "per-object". 
> Given two argument pointers, where one is marked `readonly`, may still alias. 
> Similarly, an access to a global, indirect accesses, ... can write the 
> "readonly" memory.


Oh, do we really not have a way to mark that memory is known to be truly 
immutable for a time?  That seems like a really bad limitation.  It should be 
doable with a custom alias analysis at least.

>> Regardless, if you do need `noalias`, you should be able to emit the same IR 
>> that we'd emit if pointers to all the fields were assigned into `restrict` 
>> local variables and then only those variables were subsequently used.
> 
> We are still debating the local restrict pointer support. Once we merge that 
> in it should be usable here.

I thought that was finished a few years ago; is it really not considered usable 
yet?  Or does "we" not just mean LLVM here?


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

https://reviews.llvm.org/D79744



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


[PATCH] D79655: [WebAssembly] Handle exception specifications

2020-05-16 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin marked an inline comment as done.
aheejin added inline comments.



Comment at: clang/test/CodeGenCXX/wasm-eh.cpp:387
 
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -emit-llvm -std=c++11 2>&1 | FileCheck %s 
--check-prefix=WARNING
+

thakis wrote:
> Ah, the problem is that this line is missing a -o flag and so it wrote a 
> wasm-eh.ll file to the clang/test/CodeGenCXX directory, which on the next 
> build was interpreted as a test without a run line. I'll land a temporary rm 
> here to remove that file. Please fix this for the reland.
Oh I see... Thanks a lot for doing this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79655



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


[PATCH] D80061: [WebAssembly] Handle exception specifications

2020-05-16 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin updated this revision to Diff 264461.
aheejin added a comment.

- Add missing -o


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80061

Files:
  clang/docs/DiagnosticsReference.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGException.cpp
  clang/test/CodeGenCXX/wasm-eh.cpp

Index: clang/test/CodeGenCXX/wasm-eh.cpp
===
--- clang/test/CodeGenCXX/wasm-eh.cpp
+++ clang/test/CodeGenCXX/wasm-eh.cpp
@@ -1,7 +1,6 @@
 // REQUIRES: webassembly-registered-target
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
 // RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
-// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -S -o - -std=c++11 | FileCheck %s --check-prefix=ASSEMBLY
 
 void may_throw();
 void dont_throw() noexcept;
@@ -385,9 +384,34 @@
 
 // CHECK:   unreachable
 
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -emit-llvm -o -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-DEFAULT
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -Wwasm-exception-spec -emit-llvm -o -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-ON
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -Wno-wasm-exception-spec -emit-llvm -o -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-OFF
+
+// Wasm ignores dynamic exception specifications with types at the moment. This
+// is controlled by -Wwasm-exception-spec, which is on by default. This warning
+// can be suppressed with -Wno-wasm-exception-spec.
+// Checks if a warning message is correctly printed or not printed depending on
+// the options.
+void test9() throw(int) {
+}
+// WARNING-DEFAULT: warning: dynamic exception specifications with types are currently ignored in wasm
+// WARNING-ON: warning: dynamic exception specifications with types are currently ignored in wasm
+// WARNING-OFF-NOT: warning: dynamic exception specifications with types are currently ignored in wasm
+
+// Wasm curremtly treats 'throw()' in the same way as 'noexept'. Check if the
+// same warning message is printed as if when a 'noexcept' function throws.
+void test10() throw() {
+  throw 3;
+}
+// WARNING-DEFAULT: warning: 'test10' has a non-throwing exception specification but can still throw
+// WARNING-DEFAULT: function declared non-throwing here
+
 // Here we only check if the command enables wasm exception handling in the
 // backend so that exception handling instructions can be generated in .s file.
 
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -S -o - -std=c++11 | FileCheck %s --check-prefix=ASSEMBLY
+
 // ASSEMBLY: try
 // ASSEMBLY: catch
 // ASSEMBLY: rethrow
Index: clang/lib/CodeGen/CGException.cpp
===
--- clang/lib/CodeGen/CGException.cpp
+++ clang/lib/CodeGen/CGException.cpp
@@ -20,6 +20,7 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/TargetBuiltins.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
@@ -468,6 +469,18 @@
 // encode these in an object file but MSVC doesn't do anything with it.
 if (getTarget().getCXXABI().isMicrosoft())
   return;
+// In wasm we currently treat 'throw()' in the same way as 'noexcept'. In
+// case of throw with types, we ignore it and print a warning for now.
+// TODO Correctly handle exception specification in wasm
+if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly) {
+  if (EST == EST_DynamicNone)
+EHStack.pushTerminate();
+  else
+CGM.getDiags().Report(D->getLocation(),
+  diag::warn_wasm_dynamic_exception_spec_ignored)
+<< FD->getExceptionSpecSourceRange();
+  return;
+}
 unsigned NumExceptions = Proto->getNumExceptions();
 EHFilterScope *Filter = EHStack.pushFilter(NumExceptions);
 
@@ -544,6 +557,14 @@
 // encode these in an object file but MSVC doesn't do anything with it.
 if 

[PATCH] D75791: [clang-format] Added new option IndentExternBlock

2020-05-16 Thread Marcus Johnson via Phabricator via cfe-commits
MarcusJohnson91 updated this revision to Diff 264462.

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

https://reviews.llvm.org/D75791

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2538,6 +2538,39 @@
"}",
Style);
 }
+  
+TEST_F(FormatTest, IndentExternBlockStyle) {
+  FormatStyle Style = getLLVMStyle();
+  Style.IndentWidth = 2;
+  
+  Style.IndentExternBlock = FormatStyle::IEBS_Indent;
+  verifyFormat("extern \"C\" { /*9*/\n}", Style);
+  verifyFormat("extern \"C\" {\n"
+   "  int foo10();\n"
+   "}", Style);
+  
+  Style.IndentExternBlock = FormatStyle::IEBS_NoIndent;
+  verifyFormat("extern \"C\" { /*11*/\n}", Style);
+  verifyFormat("extern \"C\" {\n"
+   "int foo12();\n"
+   "}", Style);
+  
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  
+  Style.BraceWrapping.AfterExternBlock = true;
+  Style.IndentExternBlock = FormatStyle::IEBS_AfterExternBlock;
+  verifyFormat("extern \"C\"\n{ /*13*/\n}", Style);
+  verifyFormat("extern \"C\"\n{\n"
+   "  int foo14();\n"
+   "}", Style);
+  
+  Style.BraceWrapping.AfterExternBlock = false;
+  Style.IndentExternBlock = FormatStyle::IEBS_AfterExternBlock;
+  verifyFormat("extern \"C\" { /*15*/\n}", Style);
+  verifyFormat("extern \"C\" {\n"
+   "int foo16();\n"
+   "}", Style);
+}
 
 TEST_F(FormatTest, FormatsInlineASM) {
   verifyFormat("asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));");
@@ -13715,6 +13748,13 @@
   CHECK_PARSE("AllowShortIfStatementsOnASingleLine: true",
   AllowShortIfStatementsOnASingleLine,
   FormatStyle::SIS_WithoutElse);
+  
+  Style.IndentExternBlock = FormatStyle::IEBS_Indent;
+  CHECK_PARSE("IndentExternBlock: AfterExternBlock", IndentExternBlock, FormatStyle::IEBS_AfterExternBlock);
+  CHECK_PARSE("IndentExternBlock: Indent", IndentExternBlock, FormatStyle::IEBS_Indent);
+  CHECK_PARSE("IndentExternBlock: NoIndent", IndentExternBlock, FormatStyle::IEBS_NoIndent);
+  CHECK_PARSE("IndentExternBlock: true", IndentExternBlock, FormatStyle::IEBS_Indent);
+  CHECK_PARSE("IndentExternBlock: false", IndentExternBlock, FormatStyle::IEBS_NoIndent);
 
   // FIXME: This is required because parsing a configuration simply overwrites
   // the first N elements of the list instead of resetting it.
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1115,9 +1115,9 @@
   if (FormatTok->Tok.is(tok::l_brace)) {
 if (Style.BraceWrapping.AfterExternBlock) {
   addUnwrappedLine();
-  parseBlock(/*MustBeDeclaration=*/true);
+  parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/Style.BraceWrapping.AfterExternBlock);
 } else {
-  parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
+  parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/Style.IndentExternBlock == FormatStyle::IEBS_Indent);
 }
 addUnwrappedLine();
 return;
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -204,6 +204,18 @@
 IO.enumCase(Value, "true", FormatStyle::BWACS_Always);
   }
 };
+  
+template <>
+struct ScalarEnumerationTraits {
+  static void
+  enumeration(IO , FormatStyle::IndentExternBlockStyle ) {
+IO.enumCase(Value, "AfterExternBlock", FormatStyle::IEBS_AfterExternBlock);
+IO.enumCase(Value, "Indent", FormatStyle::IEBS_Indent);
+IO.enumCase(Value, "NoIndent", FormatStyle::IEBS_NoIndent);
+IO.enumCase(Value, "true", FormatStyle::IEBS_Indent);
+IO.enumCase(Value, "false", FormatStyle::IEBS_NoIndent);
+  }
+};
 
 template <>
 struct ScalarEnumerationTraits {
@@ -513,6 +525,7 @@
 IO.mapOptional("IndentWidth", Style.IndentWidth);
 IO.mapOptional("IndentWrappedFunctionNames",
Style.IndentWrappedFunctionNames);
+IO.mapOptional("IndentExternBlock", Style.IndentExternBlock);
 IO.mapOptional("InsertTrailingCommas", Style.InsertTrailingCommas);
 IO.mapOptional("JavaImportGroups", Style.JavaImportGroups);
 IO.mapOptional("JavaScriptQuotes", Style.JavaScriptQuotes);
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -1004,7 +1004,7 @@
 ///   }
 /// \endcode
 

[PATCH] D78491: Avoid relying on address space zero default parameter in llvm/IR

2020-05-16 Thread Dylan McKay via Phabricator via cfe-commits
dylanmckay added a comment.
Herald added a project: LLVM.

I really like the idea behind this patch, but I suspect there is a better way 
to go about it.

The only drawbacks to upstreaming this patch as-is is the idea that because it 
is implemented as a compiler define directive, it effectively splinters the the 
core LLVM C++ API into two different versions. Of course, this is kind of the 
point, but my only worry is that the `LLVM_DEFAULT_AS_PARAM` macro adds an 
additional layer of complexity to all users of the API that will be encountered 
and must be considered.

I think, if we have already identified all the call sites that break under the 
`LLVM_DEFAULT_AS_PARAM` patch, then we should instead make two final patches 
that fix the root rather than add the `LLVM_DEFAULT_AS_PARAM` for retroactive 
discovery. 1) replace all calls to `getUnqual` with the appropriate logic, 
which it looks like you've already done, and 2) remove the default value of `0` 
from all address space parameters so the callers *must* explicitly pass the 
address space in. I think that 2) would be hard to swing in the past whilst AVR 
was an experimental target, but now that AVR is an officially supported LLVM 
target, it is invariably true that all calls to `getOrCreateInternalVariable` 
and friends without explicit address spaces will break an officially supported 
in-tree target. It no longer makes sense to default to zero, so let's fix the 
root cause.

This would the problem at the root, stopping all new LLVM code from implicitly 
defaulting to address space `0`. This still leaves open the problem of 
developers explicitly calling `getUnqual` when constructing pointers, but this 
problem is left open under this patch currently as regardless of the default 
parameter or not, calls to `getUnqual` are still allowed.

**tl;dr** I suggest removing the `LLVM_DEFAULT_AS_PARAM` directive from this 
patch, instead permanently removing the default value of `= 0`. This will 
achieve the same end result, but it will fix the broken API rather than just 
making it easier for downstream users like CHERI to discover.

What are your thoughts?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78491



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


[PATCH] D79744: clang: Add address space to indirect abi info and use it for kernels

2020-05-16 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

In D79744#2040380 , @rjmccall wrote:

> In D79744#2040348 , @jdoerfert wrote:
>
> > Drive by, I haven't read the entire history.
> >
> > In D79744#2040208 , @rjmccall 
> > wrote:
> >
> > > I don't understand why `noalias` is even a concern if the whole buffer 
> > > passed to the kernel is read-only.  `noalias` is primarily about proving 
> > > non-interference, but if you can tell IR that the buffer is read-only, 
> > > that's a much more powerful statement.
> >
> >
> > The problem is that it is a "per-pointer" attribute and not "per-object". 
> > Given two argument pointers, where one is marked `readonly`, may still 
> > alias. Similarly, an access to a global, indirect accesses, ... can write 
> > the "readonly" memory.
>
>
> Oh, do we really not have a way to mark that memory is known to be truly 
> immutable for a time?  That seems like a really bad limitation.  It should be 
> doable with a custom alias analysis at least.


`noalias` + `readone` on an argument basically implies immutable for the 
function scope. I think we have invariant intrinsics that could do the trick as 
well, though I'm not too familiar with those. I was eventually hoping for 
paired/scoped `llvm.assumes` which would allow `noalias` + `readnone` again. 
Then there is `invariant` which can be placed on a load instruction. Finally, 
TBAA has a "constant memory" tag (or something like that), but again it is a 
per-access thing. That are all the in-tree ways I can think of right now.

Custom alias analysis can probably be used to some degree but except address 
spaces I'm unsure we have much that you can attach to a pointer and that 
"really sticks".

>>> Regardless, if you do need `noalias`, you should be able to emit the same 
>>> IR that we'd emit if pointers to all the fields were assigned into 
>>> `restrict` local variables and then only those variables were subsequently 
>>> used.
>> 
>> We are still debating the local restrict pointer support. Once we merge that 
>> in it should be usable here.
> 
> I thought that was finished a few years ago; is it really not considered 
> usable yet?  Or does "we" not just mean LLVM here?

Yes, I meant "we" = LLVM here. Maybe we talk about different things. I was 
referring to local restrict qualified variables, e.g., `double * __restrict Ptr 
= ...`. The proposal to not just ignore the restrict (see 
https://godbolt.org/z/jLzjR3) came last year, it was a big one and progress 
unfortunately stalled (partly my fault). Now we are just about to see a second 
push to get it done.
Is that what you meant too?


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

https://reviews.llvm.org/D79744



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


[PATCH] D79655: [WebAssembly] Handle exception specifications

2020-05-16 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin added a comment.

This is very strange. I haven't committed a file called wasm-eh.ll. (There is a 
file called wasm-eh.cpp, which existed for more than a year now.) Also there's 
no wasm-eh.ll in LLVM repo now either. I wonder how this happened..? Also I 
can't reproduce the bug in my local machine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79655



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


[PATCH] D80061: [WebAssembly] Handle exception specifications

2020-05-16 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin created this revision.
aheejin added a reviewer: dschuff.
Herald added subscribers: cfe-commits, sunfish, jgravelle-google, sbc100.
Herald added a project: clang.
aheejin edited the summary of this revision.
aheejin updated this revision to Diff 264423.
aheejin added a comment.

- rst file fix


aheejin added a comment.

This is an improved version of D79655 . The 
warning now can be suppressed by `-Wno-wasm-exception-spec`. To do this, we 
needed a diagnostic group.


Wasm currently does not fully handle exception specifications. Rather
than crashing,

- This treats `throw()` in the same way as `noexcept`.
- This ignores and prints a warning for `throw(type, ..)`, for a temporary 
measure. This warning is controlled by `-Wwasm-exception-spec`, which is on by 
default. You can suppress the warning by using `-Wno-wasm-exception-spec`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80061

Files:
  clang/docs/DiagnosticsReference.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGException.cpp
  clang/test/CodeGenCXX/wasm-eh.cpp

Index: clang/test/CodeGenCXX/wasm-eh.cpp
===
--- clang/test/CodeGenCXX/wasm-eh.cpp
+++ clang/test/CodeGenCXX/wasm-eh.cpp
@@ -1,7 +1,6 @@
 // REQUIRES: webassembly-registered-target
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
 // RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
-// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -S -o - -std=c++11 | FileCheck %s --check-prefix=ASSEMBLY
 
 void may_throw();
 void dont_throw() noexcept;
@@ -385,9 +384,34 @@
 
 // CHECK:   unreachable
 
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -emit-llvm -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-DEFAULT
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -Wwasm-exception-spec -emit-llvm -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-ON
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -Wno-wasm-exception-spec -emit-llvm -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-OFF
+
+// Wasm ignores dynamic exception specifications with types at the moment. This
+// is controlled by -Wwasm-exception-spec, which is on by default. This warning
+// can be suppressed with -Wno-wasm-exception-spec.
+// Checks if a warning message is correctly printed or not printed depending on
+// the options.
+void test9() throw(int) {
+}
+// WARNING-DEFAULT: warning: dynamic exception specifications with types are currently ignored in wasm
+// WARNING-ON: warning: dynamic exception specifications with types are currently ignored in wasm
+// WARNING-OFF-NOT: warning: dynamic exception specifications with types are currently ignored in wasm
+
+// Wasm curremtly treats 'throw()' in the same way as 'noexept'. Check if the
+// same warning message is printed as if when a 'noexcept' function throws.
+void test10() throw() {
+  throw 3;
+}
+// WARNING-DEFAULT: warning: 'test10' has a non-throwing exception specification but can still throw
+// WARNING-DEFAULT: function declared non-throwing here
+
 // Here we only check if the command enables wasm exception handling in the
 // backend so that exception handling instructions can be generated in .s file.
 
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -S -o - -std=c++11 | FileCheck %s --check-prefix=ASSEMBLY
+
 // ASSEMBLY: try
 // ASSEMBLY: catch
 // ASSEMBLY: rethrow
Index: clang/lib/CodeGen/CGException.cpp
===
--- clang/lib/CodeGen/CGException.cpp
+++ clang/lib/CodeGen/CGException.cpp
@@ -20,6 +20,7 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/TargetBuiltins.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
@@ -468,6 +469,18 @@
 // encode these in an object file but MSVC doesn't do anything with it.
 if (getTarget().getCXXABI().isMicrosoft())
   return;
+// In wasm we currently treat 'throw()' in the same way as 'noexcept'. In
+// case 

[PATCH] D80061: [WebAssembly] Handle exception specifications

2020-05-16 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin added a comment.

This is an improved version of D79655 . The 
warning now can be suppressed by `-Wno-wasm-exception-spec`. To do this, we 
needed a diagnostic group.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80061



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


[PATCH] D80061: [WebAssembly] Handle exception specifications

2020-05-16 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin updated this revision to Diff 264423.
aheejin added a comment.

- rst file fix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80061

Files:
  clang/docs/DiagnosticsReference.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGException.cpp
  clang/test/CodeGenCXX/wasm-eh.cpp

Index: clang/test/CodeGenCXX/wasm-eh.cpp
===
--- clang/test/CodeGenCXX/wasm-eh.cpp
+++ clang/test/CodeGenCXX/wasm-eh.cpp
@@ -1,7 +1,6 @@
 // REQUIRES: webassembly-registered-target
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
 // RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
-// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -S -o - -std=c++11 | FileCheck %s --check-prefix=ASSEMBLY
 
 void may_throw();
 void dont_throw() noexcept;
@@ -385,9 +384,34 @@
 
 // CHECK:   unreachable
 
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -emit-llvm -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-DEFAULT
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -Wwasm-exception-spec -emit-llvm -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-ON
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -Wno-wasm-exception-spec -emit-llvm -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-OFF
+
+// Wasm ignores dynamic exception specifications with types at the moment. This
+// is controlled by -Wwasm-exception-spec, which is on by default. This warning
+// can be suppressed with -Wno-wasm-exception-spec.
+// Checks if a warning message is correctly printed or not printed depending on
+// the options.
+void test9() throw(int) {
+}
+// WARNING-DEFAULT: warning: dynamic exception specifications with types are currently ignored in wasm
+// WARNING-ON: warning: dynamic exception specifications with types are currently ignored in wasm
+// WARNING-OFF-NOT: warning: dynamic exception specifications with types are currently ignored in wasm
+
+// Wasm curremtly treats 'throw()' in the same way as 'noexept'. Check if the
+// same warning message is printed as if when a 'noexcept' function throws.
+void test10() throw() {
+  throw 3;
+}
+// WARNING-DEFAULT: warning: 'test10' has a non-throwing exception specification but can still throw
+// WARNING-DEFAULT: function declared non-throwing here
+
 // Here we only check if the command enables wasm exception handling in the
 // backend so that exception handling instructions can be generated in .s file.
 
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -S -o - -std=c++11 | FileCheck %s --check-prefix=ASSEMBLY
+
 // ASSEMBLY: try
 // ASSEMBLY: catch
 // ASSEMBLY: rethrow
Index: clang/lib/CodeGen/CGException.cpp
===
--- clang/lib/CodeGen/CGException.cpp
+++ clang/lib/CodeGen/CGException.cpp
@@ -20,6 +20,7 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/TargetBuiltins.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
@@ -468,6 +469,18 @@
 // encode these in an object file but MSVC doesn't do anything with it.
 if (getTarget().getCXXABI().isMicrosoft())
   return;
+// In wasm we currently treat 'throw()' in the same way as 'noexcept'. In
+// case of throw with types, we ignore it and print a warning for now.
+// TODO Correctly handle exception specification in wasm
+if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly) {
+  if (EST == EST_DynamicNone)
+EHStack.pushTerminate();
+  else
+CGM.getDiags().Report(D->getLocation(),
+  diag::warn_wasm_dynamic_exception_spec_ignored)
+<< FD->getExceptionSpecSourceRange();
+  return;
+}
 unsigned NumExceptions = Proto->getNumExceptions();
 EHFilterScope *Filter = EHStack.pushFilter(NumExceptions);
 
@@ -544,6 +557,14 @@
 // encode these in an object file but MSVC doesn't do anything with it.
 if 

[PATCH] D79655: [WebAssembly] Handle exception specifications

2020-05-16 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin added a comment.

Committed and reverted this. Resubmitted this in D80061 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79655



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


[PATCH] D75791: [clang-format] Added new option IndentExternBlock

2020-05-16 Thread Marcus Johnson via Phabricator via cfe-commits
MarcusJohnson91 marked 3 inline comments as done.
MarcusJohnson91 added a comment.

I've fixed all of your comments as well as fixed the tests.


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

https://reviews.llvm.org/D75791



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


[PATCH] D75791: [clang-format] Added new option IndentExternBlock

2020-05-16 Thread Marcus Johnson via Phabricator via cfe-commits
MarcusJohnson91 updated this revision to Diff 264439.
MarcusJohnson91 added a comment.

Removed forgotten comment from control logic of UnwrappedLineParser


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

https://reviews.llvm.org/D75791

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2538,6 +2538,39 @@
"}",
Style);
 }
+  
+TEST_F(FormatTest, IndentExternBlockStyle) {
+  FormatStyle Style = getLLVMStyle();
+  Style.IndentWidth = 2;
+  
+  Style.IndentExternBlock = FormatStyle::IEBS_Indent;
+  verifyFormat("extern \"C\" { /*9*/\n}", Style);
+  verifyFormat("extern \"C\" {\n"
+   "  int foo10();\n"
+   "}", Style);
+  
+  Style.IndentExternBlock = FormatStyle::IEBS_NoIndent;
+  verifyFormat("extern \"C\" { /*11*/\n}", Style);
+  verifyFormat("extern \"C\" {\n"
+   "int foo12();\n"
+   "}", Style);
+  
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  
+  Style.BraceWrapping.AfterExternBlock = true;
+  Style.IndentExternBlock = FormatStyle::IEBS_AfterExternBlock;
+  verifyFormat("extern \"C\"\n{ /*13*/\n}", Style);
+  verifyFormat("extern \"C\"\n{\n"
+   "  int foo14();\n"
+   "}", Style);
+  
+  Style.BraceWrapping.AfterExternBlock = false;
+  Style.IndentExternBlock = FormatStyle::IEBS_AfterExternBlock;
+  verifyFormat("extern \"C\" { /*15*/\n}", Style);
+  verifyFormat("extern \"C\" {\n"
+   "int foo16();\n"
+   "}", Style);
+}
 
 TEST_F(FormatTest, FormatsInlineASM) {
   verifyFormat("asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));");
@@ -13715,6 +13748,13 @@
   CHECK_PARSE("AllowShortIfStatementsOnASingleLine: true",
   AllowShortIfStatementsOnASingleLine,
   FormatStyle::SIS_WithoutElse);
+  
+  Style.IndentExternBlock = FormatStyle::IEBS_Indent;
+  CHECK_PARSE("IndentExternBlock: AfterExternBlock", IndentExternBlock, FormatStyle::IEBS_AfterExternBlock);
+  CHECK_PARSE("IndentExternBlock: Indent", IndentExternBlock, FormatStyle::IEBS_Indent);
+  CHECK_PARSE("IndentExternBlock: NoIndent", IndentExternBlock, FormatStyle::IEBS_NoIndent);
+  CHECK_PARSE("IndentExternBlock: true", IndentExternBlock, FormatStyle::IEBS_Indent);
+  CHECK_PARSE("IndentExternBlock: false", IndentExternBlock, FormatStyle::IEBS_NoIndent);
 
   // FIXME: This is required because parsing a configuration simply overwrites
   // the first N elements of the list instead of resetting it.
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1115,9 +1115,9 @@
   if (FormatTok->Tok.is(tok::l_brace)) {
 if (Style.BraceWrapping.AfterExternBlock) {
   addUnwrappedLine();
-  parseBlock(/*MustBeDeclaration=*/true);
+  parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/Style.BraceWrapping.AfterExternBlock);
 } else {
-  parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
+  parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/Style.IndentExternBlock == FormatStyle::IEBS_Indent);
 }
 addUnwrappedLine();
 return;
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -204,6 +204,19 @@
 IO.enumCase(Value, "true", FormatStyle::BWACS_Always);
   }
 };
+  
+template <>
+struct ScalarEnumerationTraits {
+  static void
+  enumeration(IO , FormatStyle::IndentExternBlockStyle ) {
+IO.enumCase(Value, "AfterExternBlock", FormatStyle::IEBS_AfterExternBlock);
+IO.enumCase(Value, "Indent", FormatStyle::IEBS_Indent);
+IO.enumCase(Value, "NoIndent", FormatStyle::IEBS_NoIndent);
+IO.enumCase(Value, "Noindent", FormatStyle::IEBS_NoIndent);
+IO.enumCase(Value, "true", FormatStyle::IEBS_Indent);
+IO.enumCase(Value, "false", FormatStyle::IEBS_NoIndent);
+  }
+};
 
 template <>
 struct ScalarEnumerationTraits {
@@ -513,6 +526,7 @@
 IO.mapOptional("IndentWidth", Style.IndentWidth);
 IO.mapOptional("IndentWrappedFunctionNames",
Style.IndentWrappedFunctionNames);
+IO.mapOptional("IndentExternBlock", Style.IndentExternBlock);
 IO.mapOptional("InsertTrailingCommas", Style.InsertTrailingCommas);
 IO.mapOptional("JavaImportGroups", Style.JavaImportGroups);
 IO.mapOptional("JavaScriptQuotes", Style.JavaScriptQuotes);
Index: clang/include/clang/Format/Format.h

[PATCH] D75791: [clang-format] Added new option IndentExternBlock

2020-05-16 Thread Marcus Johnson via Phabricator via cfe-commits
MarcusJohnson91 updated this revision to Diff 264438.
MarcusJohnson91 edited the summary of this revision.
MarcusJohnson91 added a comment.

Did everything you asked and did a littl bit of my own cleanup as well.


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

https://reviews.llvm.org/D75791

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2538,6 +2538,39 @@
"}",
Style);
 }
+  
+TEST_F(FormatTest, IndentExternBlockStyle) {
+  FormatStyle Style = getLLVMStyle();
+  Style.IndentWidth = 2;
+  
+  Style.IndentExternBlock = FormatStyle::IEBS_Indent;
+  verifyFormat("extern \"C\" { /*9*/\n}", Style);
+  verifyFormat("extern \"C\" {\n"
+   "  int foo10();\n"
+   "}", Style);
+  
+  Style.IndentExternBlock = FormatStyle::IEBS_NoIndent;
+  verifyFormat("extern \"C\" { /*11*/\n}", Style);
+  verifyFormat("extern \"C\" {\n"
+   "int foo12();\n"
+   "}", Style);
+  
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  
+  Style.BraceWrapping.AfterExternBlock = true;
+  Style.IndentExternBlock = FormatStyle::IEBS_AfterExternBlock;
+  verifyFormat("extern \"C\"\n{ /*13*/\n}", Style);
+  verifyFormat("extern \"C\"\n{\n"
+   "  int foo14();\n"
+   "}", Style);
+  
+  Style.BraceWrapping.AfterExternBlock = false;
+  Style.IndentExternBlock = FormatStyle::IEBS_AfterExternBlock;
+  verifyFormat("extern \"C\" { /*15*/\n}", Style);
+  verifyFormat("extern \"C\" {\n"
+   "int foo16();\n"
+   "}", Style);
+}
 
 TEST_F(FormatTest, FormatsInlineASM) {
   verifyFormat("asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));");
@@ -13715,6 +13748,13 @@
   CHECK_PARSE("AllowShortIfStatementsOnASingleLine: true",
   AllowShortIfStatementsOnASingleLine,
   FormatStyle::SIS_WithoutElse);
+  
+  Style.IndentExternBlock = FormatStyle::IEBS_Indent;
+  CHECK_PARSE("IndentExternBlock: AfterExternBlock", IndentExternBlock, FormatStyle::IEBS_AfterExternBlock);
+  CHECK_PARSE("IndentExternBlock: Indent", IndentExternBlock, FormatStyle::IEBS_Indent);
+  CHECK_PARSE("IndentExternBlock: NoIndent", IndentExternBlock, FormatStyle::IEBS_NoIndent);
+  CHECK_PARSE("IndentExternBlock: true", IndentExternBlock, FormatStyle::IEBS_Indent);
+  CHECK_PARSE("IndentExternBlock: false", IndentExternBlock, FormatStyle::IEBS_NoIndent);
 
   // FIXME: This is required because parsing a configuration simply overwrites
   // the first N elements of the list instead of resetting it.
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1113,11 +1113,11 @@
 if (FormatTok->Tok.is(tok::string_literal)) {
   nextToken();
   if (FormatTok->Tok.is(tok::l_brace)) {
-if (Style.BraceWrapping.AfterExternBlock) {
+if (Style.BraceWrapping.AfterExternBlock) { // Style.IndentExternBlock == FormatStyle::IEBS_AfterExternBlock && 
   addUnwrappedLine();
-  parseBlock(/*MustBeDeclaration=*/true);
+  parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/Style.BraceWrapping.AfterExternBlock);
 } else {
-  parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
+  parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/Style.IndentExternBlock == FormatStyle::IEBS_Indent);
 }
 addUnwrappedLine();
 return;
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -204,6 +204,19 @@
 IO.enumCase(Value, "true", FormatStyle::BWACS_Always);
   }
 };
+  
+template <>
+struct ScalarEnumerationTraits {
+  static void
+  enumeration(IO , FormatStyle::IndentExternBlockStyle ) {
+IO.enumCase(Value, "AfterExternBlock", FormatStyle::IEBS_AfterExternBlock);
+IO.enumCase(Value, "Indent", FormatStyle::IEBS_Indent);
+IO.enumCase(Value, "NoIndent", FormatStyle::IEBS_NoIndent);
+IO.enumCase(Value, "Noindent", FormatStyle::IEBS_NoIndent);
+IO.enumCase(Value, "true", FormatStyle::IEBS_Indent);
+IO.enumCase(Value, "false", FormatStyle::IEBS_NoIndent);
+  }
+};
 
 template <>
 struct ScalarEnumerationTraits {
@@ -513,6 +526,7 @@
 IO.mapOptional("IndentWidth", Style.IndentWidth);
 IO.mapOptional("IndentWrappedFunctionNames",
Style.IndentWrappedFunctionNames);
+IO.mapOptional("IndentExternBlock", Style.IndentExternBlock);
 

[PATCH] D79744: clang: Add address space to indirect abi info and use it for kernels

2020-05-16 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D79744#2035283 , @rjmccall wrote:

>




> A completely different approach: OpenMP has to solve some very similar 
> problems and just lowers them completely in the frontend; have you considered 
> just doing that?  Kernels need a ton of special-case handling anyway, and 
> IIUC you can never optimize over the boundary anyway.

Yes, this is what I was describing. The problem is this ends up hurting 
optimizations because now we end up losing things like noalias on the pointer 
arguments. I also would still need to track the argument size/offset/align 
information in the IR, but for that we could keep on doing what we're doing and 
just never use the kernel arguments. One of the advantages of byval was an 
explicit align field to track this


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

https://reviews.llvm.org/D79744



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


[PATCH] D77491: [Sema] Introduce BuiltinAttr, per-declaration builtin-ness

2020-05-16 Thread Raul Tambre via Phabricator via cfe-commits
tambre updated this revision to Diff 264441.
tambre added a comment.
Herald added a reviewer: aaron.ballman.

Rework builtin declaration handling. Introduce BuiltinAttr.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77491

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/IdentifierTable.h
  clang/lib/AST/Decl.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGen/builtin-redeclaration.c
  clang/test/Sema/implicit-builtin-decl.c

Index: clang/test/Sema/implicit-builtin-decl.c
===
--- clang/test/Sema/implicit-builtin-decl.c
+++ clang/test/Sema/implicit-builtin-decl.c
@@ -60,12 +60,16 @@
 
 extern float fmaxf(float, float);
 
-struct __jmp_buf_tag {};
-void sigsetjmp(struct __jmp_buf_tag[1], int); // expected-warning{{declaration of built-in function 'sigsetjmp' requires the declaration of the 'jmp_buf' type, commonly provided in the header .}}
+typedef struct __jmp_buf_tag
+{
+} sigjmp_buf[1];
+
+int sigsetjmp(struct __jmp_buf_tag[1], int);
 
-// CHECK: FunctionDecl {{.*}}  col:6 sigsetjmp '
+// CHECK: FunctionDecl {{.*}}  col:5 implicit sigsetjmp '
+// CHECK: FunctionDecl {{.*}}  col:5 sigsetjmp '
 // CHECK-NOT: FunctionDecl
-// CHECK: ReturnsTwiceAttr {{.*}} <{{.*}}> Implicit
+// CHECK: ReturnsTwiceAttr {{.*}} <{{.*}}> Inherited Implicit
 
 // PR40692
 void pthread_create(); // no warning expected
Index: clang/test/CodeGen/builtin-redeclaration.c
===
--- /dev/null
+++ clang/test/CodeGen/builtin-redeclaration.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -emit-llvm-only %s
+
+// PR45410
+// Ensure we mark local extern redeclarations with a different type as non-builtin.
+void non_builtin() {
+  extern float exp();
+  exp(); // Will crash due to wrong number of arguments if this calls the builtin.
+}
+
+// PR45410
+// We mark exp() builtin as const with -fno-math-errno (default).
+// We mustn't do that for extern redeclarations of builtins where the type differs.
+float attribute() {
+  extern float exp();
+  return exp(1);
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -2108,6 +2108,7 @@
false,
R->isFunctionProtoType());
   New->setImplicit();
+  New->addAttr(BuiltinAttr::CreateImplicit(Context, ID));
 
   // Create Decl objects for each parameter, adding them to the
   // FunctionDecl.
@@ -3330,7 +3331,11 @@
   // there but not here.
   NewTypeInfo = NewTypeInfo.withCallingConv(OldTypeInfo.getCC());
   RequiresAdjustment = true;
-} else if (New->getBuiltinID()) {
+} else if (Old->getBuiltinID()) {
+  // Builtin attribute isn't propagated to the new one yet at this point.
+  // Check if the old is a builtin.
+  // TODO: Maybe we should only warn if the redeclaration is compatible?
+
   // Calling Conventions on a Builtin aren't really useful and setting a
   // default calling convention and cdecl'ing some builtin redeclarations is
   // common, so warn and ignore the calling convention on the redeclaration.
@@ -3756,6 +3761,7 @@
   // If the previous declaration was an implicitly-generated builtin
   // declaration, then at the very least we should use a specialized note.
   unsigned BuiltinID;
+  // TODO: Remove isImplicit check?
   if (Old->isImplicit() && (BuiltinID = Old->getBuiltinID())) {
 // If it's actually a library-defined builtin function like 'malloc'
 // or 'printf', just warn about the incompatible redeclaration.
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -3164,10 +3164,12 @@
   if (const auto *ABAA = getAttr()) {
 BuiltinID = ABAA->getBuiltinName()->getBuiltinID();
   } else {
-if (!getIdentifier())
+const auto *Attr = getAttr();
+
+if (!Attr)
   return 0;
 
-BuiltinID = getIdentifier()->getBuiltinID();
+BuiltinID = Attr->getID();
   }
 
   if (!BuiltinID)
Index: clang/include/clang/Basic/IdentifierTable.h
===
--- clang/include/clang/Basic/IdentifierTable.h
+++ clang/include/clang/Basic/IdentifierTable.h
@@ -225,7 +225,7 @@
   }
   void setObjCKeywordID(tok::ObjCKeywordKind ID) { ObjCOrBuiltinID = ID; }
 
-  /// True if setNotBuiltin() was called.
+  /// True if revertBuiltin() was called.
   bool hasRevertedBuiltin() const {
 return ObjCOrBuiltinID == tok::NUM_OBJC_KEYWORDS;
   }
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -3440,3