[PATCH] D97915: [Coroutines] Handle overaligned frame allocation

2021-06-23 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

In D97915#2832667 , @ChuanqiXu wrote:

> In D97915#2832446 , @ychen wrote:
>
>> In D97915#2829581 , @ChuanqiXu 
>> wrote:
>>
>>> A remained question.
>>>
>>> - what's the semantics if user specified their allocation/deallocation 
>>> functions?
>>>
>>> Previously, we discussed for the ::operator new and ::operator delete. But 
>>> what would we do for user specified allocation/deallocation functions?
>>> It looks like we would treat them just like `::operator new`. And it makes 
>>> sense at the first glance. But the problem comes from that we judge whether
>>> or not to over allocate a frame by this condition:
>>>
>>>   coro.align > align of new
>>>
>>> But if the user uses their new, it makes no sense to use the `align of new` 
>>> as the condition. On the other hand, if user specified their new function 
>>> and the 
>>> alignment requirement for their promise type, would it be better really 
>>> that the compiler do the extra transformation?
>>>
>>> May be we need to discuss with other guys who are more familiar with the 
>>> C++ standard to answer this.
>>
>> I think @rjmccall could answer these. My understanding is that 
>> user-specified allocation/deallocation has the same semantics as their 
>> standard library's counterparts. `align of new` (aka 
>> __STDCPP_DEFAULT_NEW_ALIGNMENT__) should apply to both.
>
> Yeah, I just curious about the question and not sure about the answer yet. I 
> agree with that it should be safe if we treat user-specified 
> allocation/deallocation as ::operator new. Maybe I am a little bit of 
> pedantry. I just not sure if the developer would be satisfied when they find 
> we allocate padding space they didn't want when they offered a new/delete 
> method. (Maybe I am too anxious).
>
> ---
>
> Another problem I find in this patch is that the introduction for `raw frame` 
> makes the frame confusing. For example, the following codes is aim to 
> calculate the size for the over allocated  frame:
>
>   %[[SIZE:.+]] = call i64 @llvm.coro.size.i64()
>   %[[NEWSIZE:.+]] = add i64 %[[SIZE]], %[[PAD]]
>   %[[MEM2:.+]] = call noalias nonnull i8* @_Znwm(i64 %[[NEWSIZE]])
>
> It makes sense only if `llvm.coro.size` stands for the size of 'true frame' 
> (I am not sure what's the meaning for raw frame now. Let me use 'true frame' 
> temporarily). But the document now says that '@llvm.coro.size' returns the 
> size of the frame. It's confusing
> I am not require to fix it by rename 'llvm.coro.size' or rephrase the 
> document simply. I am thinking about the the semantics of coroutine 
> intrinsics after we introduce the concept of 'raw frame'.

These are great points. The semantics of some coroutine intrinsics needs a 
little bit of tweaking otherwise they are confusing with the introduction of 
`raw frame` (suggestions for alternative names are much appreciated) which I 
defined in the updated patch (Coroutines.rst). Docs for `llvm.coro.size` 
mentions `coroutine frame` which I've used verbatim in the docs for 
`llvm.coro.raw.frame.ptr.*`.
Using your diagram below: `raw frame` is  `| --- for align --- | --- true frame 
--- |`. `Coroutine frame` is `| --- true frame --- |`. (BTW, `llvm.coro.begin` 
docs are stale which I updated in the patch, please take a look @ChuanqiXu 
@rjmccall @lxfind).




Comment at: clang/lib/CodeGen/CGCoroutine.cpp:452-461
+  llvm::Function *RawFramePtrOffsetIntrin = CGF.CGM.getIntrinsic(
+  llvm::Intrinsic::coro_raw_frame_ptr_offset, CGF.Int32Ty);
+  auto *RawFramePtrOffset = CGF.Builder.CreateCall(RawFramePtrOffsetIntrin);
+  auto *FramePtrAddrStart =
+  CGF.Builder.CreateInBoundsGEP(CoroFree, {RawFramePtrOffset});
+  auto *FramePtrAddr = CGF.Builder.CreatePointerCast(
+  FramePtrAddrStart, CGF.Int8PtrTy->getPointerTo());

ChuanqiXu wrote:
> ychen wrote:
> > ChuanqiXu wrote:
> > > We allocate overaligned-frame like:
> > > ```
> > > | --- for align --- | --- true frame --- |
> > > ```
> > > And here we set the argument to the address of true frame. Then I wonder 
> > > how about the memory for the `for align` part. Would we still free them 
> > > correctly? Maybe I missed something.
> > > Would we still free them correctly? 
> > Yes, that's the tricky part. Using `f0` of `coro-alloc.cpp` as an example, 
> > `llvm.coro.raw.frame.ptr.addr` is called at alloc time to save the raw 
> > memory pointer to the coroutine frame.  Later at dealloc time, 
> > `llvm.coro.raw.frame.ptr.addr` is called again to load the raw memory 
> > pointer back and free it.
> To make it clear, what's the definition for 'raw ptr'? From the context, I 
> think it means the true frame in above diagram from the context.
> 
> So this confuses me:
> > llvm.coro.raw.frame.ptr.addr is called again to load the raw memory pointer 
> > back and free it.
> 
> If the raw memory means the true frame, it may 

[PATCH] D97915: [Coroutines] Handle overaligned frame allocation

2021-06-23 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 353855.
ychen added a comment.

- Update intrinsics documentation.
- Inline `EmitBuiltinAlignTo` as `emitAlignUpTo`.
- Address other comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97915

Files:
  clang/lib/CodeGen/CGCoroutine.cpp
  clang/test/CodeGenCoroutines/coro-alloc.cpp
  clang/test/CodeGenCoroutines/coro-cleanup.cpp
  clang/test/CodeGenCoroutines/coro-gro.cpp
  llvm/docs/Coroutines.rst
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/Transforms/Coroutines/CoroFrame.cpp
  llvm/lib/Transforms/Coroutines/CoroInstr.h
  llvm/lib/Transforms/Coroutines/CoroInternal.h
  llvm/lib/Transforms/Coroutines/CoroSplit.cpp
  llvm/lib/Transforms/Coroutines/Coroutines.cpp
  llvm/test/Transforms/Coroutines/coro-frame-overalign.ll

Index: llvm/test/Transforms/Coroutines/coro-frame-overalign.ll
===
--- /dev/null
+++ llvm/test/Transforms/Coroutines/coro-frame-overalign.ll
@@ -0,0 +1,78 @@
+; Check that `llvm.coro.align`, `llvm.coro.raw.frame.ptr.offset` and
+; `@llvm.coro.raw.frame.ptr.alloca` are lowered correctly.
+; RUN: opt < %s -passes=coro-split -S | FileCheck %s
+
+%PackedStruct = type <{ i64 }>
+
+declare void @consume(%PackedStruct*, i32, i32, i8**)
+declare void @consume2(i32, i32)
+
+define i8* @f() "coroutine.presplit"="1" {
+entry:
+  %data = alloca %PackedStruct, align 32
+  %id = call token @llvm.coro.id(i32 16, i8* null, i8* null, i8* null)
+  %size = call i32 @llvm.coro.size.i32()
+  %alloc = call i8* @malloc(i32 %size)
+  %hdl = call i8* @llvm.coro.begin(token %id, i8* %alloc)
+  %align = call i32 @llvm.coro.align.i32()
+  %offset = call i32 @llvm.coro.raw.frame.ptr.offset.i32()
+  %addr = call i8** @llvm.coro.raw.frame.ptr.addr()
+  call void @consume(%PackedStruct* %data, i32 %align, i32 %offset, i8** %addr)
+  %0 = call i8 @llvm.coro.suspend(token none, i1 false)
+  switch i8 %0, label %suspend [i8 0, label %resume
+i8 1, label %cleanup]
+resume:
+  br label %cleanup
+
+cleanup:
+  %align2 = call i32 @llvm.coro.align.i32()
+  %offset2 = call i32 @llvm.coro.raw.frame.ptr.offset.i32()
+  call void @consume2(i32 %align2, i32 %offset2)
+  %mem = call i8* @llvm.coro.free(token %id, i8* %hdl)
+  call void @free(i8* %mem)
+  br label %suspend
+suspend:
+  call i1 @llvm.coro.end(i8* %hdl, i1 0)
+  ret i8* %hdl
+}
+
+; See if the raw frame address was inserted into the frame.
+; CHECK-LABEL: %f.Frame = type { void (%f.Frame*)*, void (%f.Frame*)*, i8*, i1, [7 x i8], %PackedStruct }
+
+; See if we used correct index to access frame addr field (field 2).
+; CHECK-LABEL: @f(
+; CHECK: %alloc.frame.ptr = alloca i8*, align 8
+; CHECK: %[[FIELD:.+]] = getelementptr inbounds %f.Frame, %f.Frame* %FramePtr, i32 0, i32 2
+; CHECK: %[[ADDR:.+]] = load i8*, i8** %alloc.frame.ptr, align 8
+; CHECK: store i8* %[[ADDR]], i8** %[[FIELD]], align 8
+; CHECK: %[[DATA:.+]] = getelementptr inbounds %f.Frame, %f.Frame* %FramePtr, i32 0, i32 5
+; CHECK: call void @consume(%PackedStruct* %[[DATA]], i32 32, i32 16, i8** %[[FIELD]])
+; CHECK: ret i8*
+
+; See if `llvm.coro.align` and `llvm.coro.raw.frame.ptr.offset` are lowered
+; correctly during deallocation.
+; CHECK-LABEL: @f.destroy(
+; CHECK: call void @consume2(i32 32, i32 16)
+; CHECK: call void @free(i8* %{{.*}})
+
+; CHECK-LABEL: @f.cleanup(
+; CHECK: call void @consume2(i32 32, i32 16)
+; CHECK: call void @free(i8*
+
+declare i8* @llvm.coro.free(token, i8*)
+declare i32 @llvm.coro.size.i32()
+declare i32 @llvm.coro.align.i32()
+declare i32 @llvm.coro.raw.frame.ptr.offset.i32()
+declare i8** @llvm.coro.raw.frame.ptr.addr()
+declare i8  @llvm.coro.suspend(token, i1)
+declare void @llvm.coro.resume(i8*)
+declare void @llvm.coro.destroy(i8*)
+
+declare token @llvm.coro.id(i32, i8*, i8*, i8*)
+declare i1 @llvm.coro.alloc(token)
+declare i8* @llvm.coro.begin(token, i8*)
+declare i1 @llvm.coro.end(i8*, i1)
+
+declare noalias i8* @malloc(i32)
+declare double @print(double)
+declare void @free(i8*)
Index: llvm/lib/Transforms/Coroutines/Coroutines.cpp
===
--- llvm/lib/Transforms/Coroutines/Coroutines.cpp
+++ llvm/lib/Transforms/Coroutines/Coroutines.cpp
@@ -234,6 +234,9 @@
   Shape.CoroBegin = nullptr;
   Shape.CoroEnds.clear();
   Shape.CoroSizes.clear();
+  Shape.CoroAligns.clear();
+  Shape.CoroRawFramePtrOffsets.clear();
+  Shape.CoroRawFramePtrAddrs.clear();
   Shape.CoroSuspends.clear();
 
   Shape.FrameTy = nullptr;
@@ -268,6 +271,15 @@
   case Intrinsic::coro_size:
 CoroSizes.push_back(cast(II));
 break;
+  case Intrinsic::coro_align:
+CoroAligns.push_back(cast(II));
+break;
+  case Intrinsic::coro_raw_frame_ptr_offset:
+CoroRawFramePtrOffsets.push_back(cast(II));
+break;
+  case Intrinsic::coro_raw_frame_ptr_addr:
+CoroRa

[PATCH] D103943: [X86] Add -mgeneral-regs-only support.

2021-06-23 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei accepted this revision.
pengfei added a comment.
This revision is now accepted and ready to land.

LGTM.


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

https://reviews.llvm.org/D103943

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


[PATCH] D102134: [docs]Updated the AMD GPU Attributes documentation

2021-06-23 Thread PoojaYadav via Phabricator via cfe-commits
pooja2299 abandoned this revision.
pooja2299 added a comment.

Closing this issue because the default workgroup size is 1024 now, so no 
changes are required.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102134

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


[PATCH] D103440: [WIP][analyzer] Introduce range-based reasoning for addition operator

2021-06-23 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

Hey, it looks like we are finally converging on this one!  Great job!

NOTE: I don't know if you noticed, but I want to point out that there are three 
failing tests:
F17553262: Screen Shot 2021-06-23 at 11.35.49.png 





Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1075-1076
+  ///   LHSOpd binop RHSOpd == Result, where binop is any binary operation
+  bool hasOverflowed(llvm::APSInt LHSOpd, llvm::APSInt RHSOpd,
+ llvm::APSInt &Result, QualType T) {
+llvm::APSInt Zero = ValueFactory.getAPSIntType(T).getZeroValue();

manas wrote:
> We should have these specific functions for other BO as well. Because they 
> will lead us to reason about when `Operand1 binop Operand2` can overflow or 
> not. I was thinking in the direction of having a simpler class which works 
> for this.
I searched through a codebase a bit and here are the couple of functions (from 
`APInt.h`) that can come in handy:
```
  // Operations that return overflow indicators.
  APInt sadd_ov(const APInt &RHS, bool &Overflow) const;
  APInt uadd_ov(const APInt &RHS, bool &Overflow) const;
  APInt ssub_ov(const APInt &RHS, bool &Overflow) const;
  APInt usub_ov(const APInt &RHS, bool &Overflow) const;
  APInt sdiv_ov(const APInt &RHS, bool &Overflow) const;
  APInt smul_ov(const APInt &RHS, bool &Overflow) const;
  APInt umul_ov(const APInt &RHS, bool &Overflow) const;
  APInt sshl_ov(const APInt &Amt, bool &Overflow) const;
  APInt ushl_ov(const APInt &Amt, bool &Overflow) const;
```
`APSInt` is derived from `APInt`, so we can totally use these.



Comment at: clang/test/Analysis/constant-folding.c:269
+  // Checks for inclusive ranges for unsigned integers
+  if (a >= 0 && a <= 10 && b >= 0 && b <= 20) {
+clang_analyzer_eval((a + b) >= 0); // expected-warning{{TRUE}}

They are already unsigned, we don't need `a >= 0` and `b >= 0`



Comment at: clang/test/Analysis/constant-folding.c:330
+clang_analyzer_eval((c + d) == INT_MAX - 22); // expected-warning{{FALSE}}
+  }
+}

I don't see the cases where we overflow on both ends and the case where we 
overflow on one end, but `Min > Max`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103440

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


[PATCH] D103440: [WIP][analyzer] Introduce range-based reasoning for addition operator

2021-06-23 Thread Manas Gupta via Phabricator via cfe-commits
manas added a comment.

Thanks @vsavchenko and everyone for helping! :)




Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1075-1076
+  ///   LHSOpd binop RHSOpd == Result, where binop is any binary operation
+  bool hasOverflowed(llvm::APSInt LHSOpd, llvm::APSInt RHSOpd,
+ llvm::APSInt &Result, QualType T) {
+llvm::APSInt Zero = ValueFactory.getAPSIntType(T).getZeroValue();

vsavchenko wrote:
> manas wrote:
> > We should have these specific functions for other BO as well. Because they 
> > will lead us to reason about when `Operand1 binop Operand2` can overflow or 
> > not. I was thinking in the direction of having a simpler class which works 
> > for this.
> I searched through a codebase a bit and here are the couple of functions 
> (from `APInt.h`) that can come in handy:
> ```
>   // Operations that return overflow indicators.
>   APInt sadd_ov(const APInt &RHS, bool &Overflow) const;
>   APInt uadd_ov(const APInt &RHS, bool &Overflow) const;
>   APInt ssub_ov(const APInt &RHS, bool &Overflow) const;
>   APInt usub_ov(const APInt &RHS, bool &Overflow) const;
>   APInt sdiv_ov(const APInt &RHS, bool &Overflow) const;
>   APInt smul_ov(const APInt &RHS, bool &Overflow) const;
>   APInt umul_ov(const APInt &RHS, bool &Overflow) const;
>   APInt sshl_ov(const APInt &Amt, bool &Overflow) const;
>   APInt ushl_ov(const APInt &Amt, bool &Overflow) const;
> ```
> `APSInt` is derived from `APInt`, so we can totally use these.
That's great! I will incorporate those in the code instead of custom functions.



Comment at: clang/test/Analysis/constant-folding.c:269
+  // Checks for inclusive ranges for unsigned integers
+  if (a >= 0 && a <= 10 && b >= 0 && b <= 20) {
+clang_analyzer_eval((a + b) >= 0); // expected-warning{{TRUE}}

vsavchenko wrote:
> They are already unsigned, we don't need `a >= 0` and `b >= 0`
Right! I will remove those constraints.



Comment at: clang/test/Analysis/constant-folding.c:330
+clang_analyzer_eval((c + d) == INT_MAX - 22); // expected-warning{{FALSE}}
+  }
+}

vsavchenko wrote:
> I don't see the cases where we overflow on both ends and the case where we 
> overflow on one end, but `Min > Max`.
My bad. I thought I added both overflows one. I will add them now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103440

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


[PATCH] D104550: [analyzer] Implement getType for SVal

2021-06-23 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Another thing to mention about `SVal::getType()` in its doxygen comment is that 
//most of the time you don't need it//. Similarly to how checking whether an 
`SVal` is a `Loc` or a `NonLoc` results in incorrect code 95% of the time 
(because such code is unable to discriminate between arbitrary lvalues and 
pointer rvalues which is typically crucial in order to get everything right but 
often forgotten / misunderstood), relying on the type of the `SVal` rather than 
its storage raises similar problems.

The use case in `RegionStore` that I mentioned in the beginning is the rare 
exception to this rule of thumb because there's no AST expressions to tell us 
the type of the storage and on top of that type punning makes the storage 
basically entirely untyped. There's really no other way to obtain such 
information. Bytes in memory really don't have a type; it's very much a matter 
of convenient abstraction for us to associate type with them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104550

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


[PATCH] D104770: Add support for #pragma system_header with -fms-extensions

2021-06-23 Thread Hans Wennborg via Phabricator via cfe-commits
hans created this revision.
hans added a reviewer: thakis.
hans requested review of this revision.
Herald added a project: clang.

Clang already supports the pragma prefixed by "GCC" or "clang".

MSVC has more recently added support for the pragma, but without any prefix; 
see 
https://devblogs.microsoft.com/cppblog/broken-warnings-theory/#external-headers


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104770

Files:
  clang/lib/Lex/Pragma.cpp
  clang/test/Lexer/pragma-operators.cpp
  clang/test/Preprocessor/Inputs/pragma_sysheader.h
  clang/test/Preprocessor/pragma_sysheader.c
  clang/test/Preprocessor/pragma_sysheader.h


Index: clang/test/Preprocessor/pragma_sysheader.h
===
--- clang/test/Preprocessor/pragma_sysheader.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#pragma GCC system_header
-typedef int x;
-typedef int x;
-
Index: clang/test/Preprocessor/pragma_sysheader.c
===
--- clang/test/Preprocessor/pragma_sysheader.c
+++ clang/test/Preprocessor/pragma_sysheader.c
@@ -1,13 +1,14 @@
-// RUN: %clang_cc1 -verify -pedantic %s -fsyntax-only
-// RUN: %clang_cc1 -E %s | FileCheck %s
+// RUN: %clang_cc1 -verify -std=c99 -pedantic %s -fsyntax-only
+// RUN: %clang_cc1 -verify -std=c99 -pedantic %s -fsyntax-only -DCLANG
+// RUN: %clang_cc1 -verify -std=c99 -pedantic %s -fsyntax-only -fms-extensions 
-DMS
 // expected-no-diagnostics
 // rdar://6899937
-#include "pragma_sysheader.h"
-
+#include "Inputs/pragma_sysheader.h"
 
+// RUN: %clang_cc1 -E %s | FileCheck %s
 // PR9861: Verify that line markers are not messed up in -E mode.
 // CHECK: # 1 "{{.*}}pragma_sysheader.h" 1
-// CHECK-NEXT: # 2 "{{.*}}pragma_sysheader.h" 3
-// CHECK-NEXT: typedef int x;
-// CHECK-NEXT: typedef int x;
-// CHECK-NEXT: # 6 "{{.*}}pragma_sysheader.c" 2
+// CHECK-NEXT: # 7 "{{.*}}pragma_sysheader.h" 3
+// CHECK: typedef int x;
+// CHECK: typedef int x;
+// CHECK-NEXT: # 7 "{{.*}}pragma_sysheader.c" 2
Index: clang/test/Preprocessor/Inputs/pragma_sysheader.h
===
--- /dev/null
+++ clang/test/Preprocessor/Inputs/pragma_sysheader.h
@@ -0,0 +1,10 @@
+#if defined(CLANG)
+#pragma clang system_header
+#elif defined(MS)
+#pragma system_header
+#else
+#pragma GCC system_header
+#endif
+
+typedef int x;
+typedef int x;
Index: clang/test/Lexer/pragma-operators.cpp
===
--- clang/test/Lexer/pragma-operators.cpp
+++ clang/test/Lexer/pragma-operators.cpp
@@ -19,7 +19,7 @@
 #pragma warning(pop)
 
 #define pragma_L _Pragma(L"GCC diagnostic push")
-#define pragma_u8 _Pragma(u8"system_header")
+#define pragma_u8 _Pragma(u8"pack(1)")
 #define pragma_u _Pragma(u"GCC diagnostic pop")
 #define pragma_U _Pragma(U"comment(lib, \"libfoo\")")
 #define pragma_R _Pragma(R"(clang diagnostic ignored "-Wunused")")
@@ -27,7 +27,7 @@
 #define pragma_hello _Pragma(u8R"x(message R"y("Hello", world!)y")x")
 // CHECK: int n =
 // CHECK: #pragma GCC diagnostic push
-// CHECK: #pragma system_header
+// CHECK: #pragma pack(1)
 // CHECK: #pragma GCC diagnostic pop
 // CHECK: #pragma comment(lib, "libfoo")
 // CHECK: #pragma clang diagnostic ignored "-Wunused"
Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -1955,6 +1955,7 @@
 AddPragmaHandler(new PragmaExecCharsetHandler());
 AddPragmaHandler(new PragmaIncludeAliasHandler());
 AddPragmaHandler(new PragmaHdrstopHandler());
+AddPragmaHandler(new PragmaSystemHeaderHandler());
   }
 
   // Pragmas added by plugins


Index: clang/test/Preprocessor/pragma_sysheader.h
===
--- clang/test/Preprocessor/pragma_sysheader.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#pragma GCC system_header
-typedef int x;
-typedef int x;
-
Index: clang/test/Preprocessor/pragma_sysheader.c
===
--- clang/test/Preprocessor/pragma_sysheader.c
+++ clang/test/Preprocessor/pragma_sysheader.c
@@ -1,13 +1,14 @@
-// RUN: %clang_cc1 -verify -pedantic %s -fsyntax-only
-// RUN: %clang_cc1 -E %s | FileCheck %s
+// RUN: %clang_cc1 -verify -std=c99 -pedantic %s -fsyntax-only
+// RUN: %clang_cc1 -verify -std=c99 -pedantic %s -fsyntax-only -DCLANG
+// RUN: %clang_cc1 -verify -std=c99 -pedantic %s -fsyntax-only -fms-extensions -DMS
 // expected-no-diagnostics
 // rdar://6899937
-#include "pragma_sysheader.h"
-
+#include "Inputs/pragma_sysheader.h"
 
+// RUN: %clang_cc1 -E %s | FileCheck %s
 // PR9861: Verify that line markers are not messed up in -E mode.
 // CHECK: # 1 "{{.*}}pragma_sysheader.h" 1
-// CHECK-NEXT: # 2 "{{.*}}pragma_sysheader.h" 3
-// CHECK-NEXT: typedef int x;
-// CHECK-NEXT: typedef int x;
-// CHECK-NEXT: # 6 "{{.*}}pragma_sysheader.c" 2
+// CHECK-NEXT: # 7 "{

[PATCH] D104770: Add support for #pragma system_header with -fms-extensions

2021-06-23 Thread Hans Wennborg via Phabricator via cfe-commits
hans added inline comments.



Comment at: clang/test/Lexer/pragma-operators.cpp:22
 #define pragma_L _Pragma(L"GCC diagnostic push")
-#define pragma_u8 _Pragma(u8"system_header")
+#define pragma_u8 _Pragma(u8"pack(1)")
 #define pragma_u _Pragma(u"GCC diagnostic pop")

I had to change the pragma here, because now we will warn about system_header 
being ignored in a non-header file which would break this test.



Comment at: clang/test/Preprocessor/pragma_sysheader.c:1
-// RUN: %clang_cc1 -verify -pedantic %s -fsyntax-only
-// RUN: %clang_cc1 -E %s | FileCheck %s
+// RUN: %clang_cc1 -verify -std=c99 -pedantic %s -fsyntax-only
+// RUN: %clang_cc1 -verify -std=c99 -pedantic %s -fsyntax-only -DCLANG

Adding -std=c99 is necessary, because in newer language modes (which are now 
the default), Clang doesn't warn about repeated typedef declarations, so the 
test wasn't actually testing the system_header pragma anymore.



Comment at: clang/test/Preprocessor/pragma_sysheader.c:6
 // rdar://6899937
-#include "pragma_sysheader.h"
-
+#include "Inputs/pragma_sysheader.h"
 

Moving the .h file to Inputs/ is just a cleanup.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104770

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


[PATCH] D104744: [PowerPC] Add PowerPC rotate related builtins and emit target independent code for XL compatibility

2021-06-23 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf added a comment.

Please provide context of the patch (`git diff -U999`) :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104744

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


[PATCH] D102730: [clang-format] Support custom If macros

2021-06-23 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102730

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


[clang] 157473a - [IR] Simplify createReplacementInstr

2021-06-23 Thread Jay Foad via cfe-commits

Author: Jay Foad
Date: 2021-06-23T10:47:43+01:00
New Revision: 157473a58f02b8f2ad12ecbaaa1af32d0342257b

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

LOG: [IR] Simplify createReplacementInstr

NFCI, although the test change shows that ConstantExpr::getAsInstruction
is better than the old implementation of createReplacementInstr because
it propagates things like the sdiv "exact" flag.

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

Added: 


Modified: 
clang/test/CodeGenCUDA/managed-var.cu
llvm/lib/IR/ReplaceConstant.cpp

Removed: 




diff  --git a/clang/test/CodeGenCUDA/managed-var.cu 
b/clang/test/CodeGenCUDA/managed-var.cu
index 99bbad924ea54..05a7a69387690 100644
--- a/clang/test/CodeGenCUDA/managed-var.cu
+++ b/clang/test/CodeGenCUDA/managed-var.cu
@@ -146,7 +146,7 @@ float load3() {
 // HOST:  %3 = getelementptr inbounds [100 x %struct.vec], [100 x 
%struct.vec]* %2, i64 0, i64 1, i32 1
 // HOST:  %4 = ptrtoint float* %3 to i64
 // HOST:  %5 = sub i64 %4, %1
-// HOST:  %6 = sdiv i64 %5, 4
+// HOST:  %6 = sdiv exact i64 %5, 4
 // HOST:  %7 = sitofp i64 %6 to float
 // HOST:  ret float %7
 float addr_taken2() {

diff  --git a/llvm/lib/IR/ReplaceConstant.cpp b/llvm/lib/IR/ReplaceConstant.cpp
index 9382f820a7f29..fd73a1a8e5afe 100644
--- a/llvm/lib/IR/ReplaceConstant.cpp
+++ b/llvm/lib/IR/ReplaceConstant.cpp
@@ -20,53 +20,9 @@ namespace llvm {
 // Replace a constant expression by instructions with equivalent operations at
 // a specified location.
 Instruction *createReplacementInstr(ConstantExpr *CE, Instruction *Instr) {
-  IRBuilder Builder(Instr);
-  unsigned OpCode = CE->getOpcode();
-  switch (OpCode) {
-  case Instruction::GetElementPtr: {
-SmallVector CEOpVec(CE->operands());
-ArrayRef CEOps(CEOpVec);
-return dyn_cast(
-
Builder.CreateInBoundsGEP(cast(CE)->getSourceElementType(),
-  CEOps[0], CEOps.slice(1)));
-  }
-  case Instruction::Add:
-  case Instruction::Sub:
-  case Instruction::Mul:
-  case Instruction::UDiv:
-  case Instruction::SDiv:
-  case Instruction::FDiv:
-  case Instruction::URem:
-  case Instruction::SRem:
-  case Instruction::FRem:
-  case Instruction::Shl:
-  case Instruction::LShr:
-  case Instruction::AShr:
-  case Instruction::And:
-  case Instruction::Or:
-  case Instruction::Xor:
-return dyn_cast(
-Builder.CreateBinOp((Instruction::BinaryOps)OpCode, CE->getOperand(0),
-CE->getOperand(1), CE->getName()));
-  case Instruction::Trunc:
-  case Instruction::ZExt:
-  case Instruction::SExt:
-  case Instruction::FPToUI:
-  case Instruction::FPToSI:
-  case Instruction::UIToFP:
-  case Instruction::SIToFP:
-  case Instruction::FPTrunc:
-  case Instruction::FPExt:
-  case Instruction::PtrToInt:
-  case Instruction::IntToPtr:
-  case Instruction::BitCast:
-  case Instruction::AddrSpaceCast:
-return dyn_cast(
-Builder.CreateCast((Instruction::CastOps)OpCode, CE->getOperand(0),
-   CE->getType(), CE->getName()));
-  default:
-llvm_unreachable("Unhandled constant expression!\n");
-  }
+  auto *CEInstr = CE->getAsInstruction();
+  CEInstr->insertBefore(Instr);
+  return CEInstr;
 }
 
 void convertConstantExprsToInstructions(Instruction *I, ConstantExpr *CE,



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


[PATCH] D104124: [IR] Simplify createReplacementInstr

2021-06-23 Thread Jay Foad via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG157473a58f02: [IR] Simplify createReplacementInstr (authored 
by foad).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104124

Files:
  clang/test/CodeGenCUDA/managed-var.cu
  llvm/lib/IR/ReplaceConstant.cpp


Index: llvm/lib/IR/ReplaceConstant.cpp
===
--- llvm/lib/IR/ReplaceConstant.cpp
+++ llvm/lib/IR/ReplaceConstant.cpp
@@ -20,53 +20,9 @@
 // Replace a constant expression by instructions with equivalent operations at
 // a specified location.
 Instruction *createReplacementInstr(ConstantExpr *CE, Instruction *Instr) {
-  IRBuilder Builder(Instr);
-  unsigned OpCode = CE->getOpcode();
-  switch (OpCode) {
-  case Instruction::GetElementPtr: {
-SmallVector CEOpVec(CE->operands());
-ArrayRef CEOps(CEOpVec);
-return dyn_cast(
-
Builder.CreateInBoundsGEP(cast(CE)->getSourceElementType(),
-  CEOps[0], CEOps.slice(1)));
-  }
-  case Instruction::Add:
-  case Instruction::Sub:
-  case Instruction::Mul:
-  case Instruction::UDiv:
-  case Instruction::SDiv:
-  case Instruction::FDiv:
-  case Instruction::URem:
-  case Instruction::SRem:
-  case Instruction::FRem:
-  case Instruction::Shl:
-  case Instruction::LShr:
-  case Instruction::AShr:
-  case Instruction::And:
-  case Instruction::Or:
-  case Instruction::Xor:
-return dyn_cast(
-Builder.CreateBinOp((Instruction::BinaryOps)OpCode, CE->getOperand(0),
-CE->getOperand(1), CE->getName()));
-  case Instruction::Trunc:
-  case Instruction::ZExt:
-  case Instruction::SExt:
-  case Instruction::FPToUI:
-  case Instruction::FPToSI:
-  case Instruction::UIToFP:
-  case Instruction::SIToFP:
-  case Instruction::FPTrunc:
-  case Instruction::FPExt:
-  case Instruction::PtrToInt:
-  case Instruction::IntToPtr:
-  case Instruction::BitCast:
-  case Instruction::AddrSpaceCast:
-return dyn_cast(
-Builder.CreateCast((Instruction::CastOps)OpCode, CE->getOperand(0),
-   CE->getType(), CE->getName()));
-  default:
-llvm_unreachable("Unhandled constant expression!\n");
-  }
+  auto *CEInstr = CE->getAsInstruction();
+  CEInstr->insertBefore(Instr);
+  return CEInstr;
 }
 
 void convertConstantExprsToInstructions(Instruction *I, ConstantExpr *CE,
Index: clang/test/CodeGenCUDA/managed-var.cu
===
--- clang/test/CodeGenCUDA/managed-var.cu
+++ clang/test/CodeGenCUDA/managed-var.cu
@@ -146,7 +146,7 @@
 // HOST:  %3 = getelementptr inbounds [100 x %struct.vec], [100 x 
%struct.vec]* %2, i64 0, i64 1, i32 1
 // HOST:  %4 = ptrtoint float* %3 to i64
 // HOST:  %5 = sub i64 %4, %1
-// HOST:  %6 = sdiv i64 %5, 4
+// HOST:  %6 = sdiv exact i64 %5, 4
 // HOST:  %7 = sitofp i64 %6 to float
 // HOST:  ret float %7
 float addr_taken2() {


Index: llvm/lib/IR/ReplaceConstant.cpp
===
--- llvm/lib/IR/ReplaceConstant.cpp
+++ llvm/lib/IR/ReplaceConstant.cpp
@@ -20,53 +20,9 @@
 // Replace a constant expression by instructions with equivalent operations at
 // a specified location.
 Instruction *createReplacementInstr(ConstantExpr *CE, Instruction *Instr) {
-  IRBuilder Builder(Instr);
-  unsigned OpCode = CE->getOpcode();
-  switch (OpCode) {
-  case Instruction::GetElementPtr: {
-SmallVector CEOpVec(CE->operands());
-ArrayRef CEOps(CEOpVec);
-return dyn_cast(
-Builder.CreateInBoundsGEP(cast(CE)->getSourceElementType(),
-  CEOps[0], CEOps.slice(1)));
-  }
-  case Instruction::Add:
-  case Instruction::Sub:
-  case Instruction::Mul:
-  case Instruction::UDiv:
-  case Instruction::SDiv:
-  case Instruction::FDiv:
-  case Instruction::URem:
-  case Instruction::SRem:
-  case Instruction::FRem:
-  case Instruction::Shl:
-  case Instruction::LShr:
-  case Instruction::AShr:
-  case Instruction::And:
-  case Instruction::Or:
-  case Instruction::Xor:
-return dyn_cast(
-Builder.CreateBinOp((Instruction::BinaryOps)OpCode, CE->getOperand(0),
-CE->getOperand(1), CE->getName()));
-  case Instruction::Trunc:
-  case Instruction::ZExt:
-  case Instruction::SExt:
-  case Instruction::FPToUI:
-  case Instruction::FPToSI:
-  case Instruction::UIToFP:
-  case Instruction::SIToFP:
-  case Instruction::FPTrunc:
-  case Instruction::FPExt:
-  case Instruction::PtrToInt:
-  case Instruction::IntToPtr:
-  case Instruction::BitCast:
-  case Instruction::AddrSpaceCast:
-return dyn_cast(
-Builder.CreateCast((Instruction::CastOps)OpCode, CE->getOperand(0),
-   CE->getType(), CE->getName()));
-  default:
-llvm_unreachable("Unhandled constant expression!\n");
-  }
+  auto *CEInstr = CE->getAsInstruction(

[PATCH] D103943: [X86] Add -mgeneral-regs-only support.

2021-06-23 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

Thanks - that makes sense - LGTM


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

https://reviews.llvm.org/D103943

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


[PATCH] D104082: [CodeGen] Don't create a fake FunctionDecl when generating block/block_byref copy/dispose helper functions

2021-06-23 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In D104082#2835080 , @zequanwu wrote:

> Hi, this caused compiler crash with error "Assertion 
> `cast(Scope)->describes(&MF->getFunction())' failed." on iOS 
> platforms.  So, I reverted it.
> I'm working on a reduced repro.

FYI this also caused a failure on GreenDragon, with `-verify-machineinstrs`: 
https://green.lab.llvm.org/green/job/test-suite-verify-machineinstrs-aarch64-O0-g/9663/consoleFull#-134330334249ba4694-19c4-4d7e-bec5-911270d8a58c

The failure should be re-producible by building the following C++ file from 
llvm-test-suite:

  bin/clang++  -DNDEBUG  -B 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
-Wno-unused-command-line-argument -mllvm -verify-machineinstrs -O0 -g -arch 
arm64 -isysroot 
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk
   -w -Werror=date-time -MD -MT 
SingleSource/UnitTests/CMakeFiles/block-byref-cxxobj-test.dir/block-byref-cxxobj-test.cpp.o
 -MF 
SingleSource/UnitTests/CMakeFiles/block-byref-cxxobj-test.dir/block-byref-cxxobj-test.cpp.o.d
 -o 
SingleSource/UnitTests/CMakeFiles/block-byref-cxxobj-test.dir/block-byref-cxxobj-test.cpp.o
 -c 
/Users/buildslave/jenkins/workspace/test-suite-verify-machineinstrs-aarch64-O0-g/test-suite/SingleSource/UnitTests/block-byref-cxxobj-test.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104082

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


[PATCH] D104774: [clang-format] Fix a bug that indents else-comment-if incorrectly

2021-06-23 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
owenpan added reviewers: djasper, klimek, MyDeveloperDay.
owenpan added a project: clang-format.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

If there is a comment between "else" and "if", the "if" statement including its 
body is indented incorrectly.

See https://bugs.llvm.org/show_bug.cgi?id=50809 for an example.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104774

Files:
  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
@@ -1181,6 +1181,13 @@
"  g();\n"
"else\n"
"  h();");
+  verifyFormat("if (a)\n"
+   "  f();\n"
+   "else // comment\n"
+   "  if (b) {\n"
+   "g();\n"
+   "h()\n"
+   "  }");
   verifyFormat("if constexpr (a)\n"
"  f();\n"
"else if constexpr (b)\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2021,7 +2021,15 @@
   parseBlock(/*MustBeDeclaration=*/false);
   addUnwrappedLine();
 } else if (FormatTok->Tok.is(tok::kw_if)) {
+  FormatToken *Previous = AllTokens[Tokens->getPosition() - 1];
+  bool PrecededByComment = Previous->is(tok::comment);
+  if (PrecededByComment) {
+addUnwrappedLine();
+++Line->Level;
+  }
   parseIfThenElse();
+  if (PrecededByComment)
+--Line->Level;
 } else {
   addUnwrappedLine();
   ++Line->Level;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -1181,6 +1181,13 @@
"  g();\n"
"else\n"
"  h();");
+  verifyFormat("if (a)\n"
+   "  f();\n"
+   "else // comment\n"
+   "  if (b) {\n"
+   "g();\n"
+   "h()\n"
+   "  }");
   verifyFormat("if constexpr (a)\n"
"  f();\n"
"else if constexpr (b)\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2021,7 +2021,15 @@
   parseBlock(/*MustBeDeclaration=*/false);
   addUnwrappedLine();
 } else if (FormatTok->Tok.is(tok::kw_if)) {
+  FormatToken *Previous = AllTokens[Tokens->getPosition() - 1];
+  bool PrecededByComment = Previous->is(tok::comment);
+  if (PrecededByComment) {
+addUnwrappedLine();
+++Line->Level;
+  }
   parseIfThenElse();
+  if (PrecededByComment)
+--Line->Level;
 } else {
   addUnwrappedLine();
   ++Line->Level;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104770: Add support for #pragma system_header with -fms-extensions

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

LGTM, though you could add a test that `#pragma system_header` gives a 
diagnostic outside of `-fms-extensions` mode if you think that's valuable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104770

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


[PATCH] D104117: [clangd] Fix highlighting for implicit ObjC property refs

2021-06-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Drive by from vacation, sorry - can this be tackled "upstream" in 
findExplicitReferences rather than special cased in syntax highlighting?

That would help with xrefs, rename etc. Features should really be only handled 
here if they're somehow not a simple token->decl reference, but this seems to 
be.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104117

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


[PATCH] D93525: [clang-offload-bundler] Add unbundling of archives containing bundled object files into device specific archives

2021-06-23 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam updated this revision to Diff 353922.
saiislam added a comment.

Updated clang and hip tests to ensure that all 4 components of triple are 
mandataroly available in the bundle entry ID.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93525

Files:
  clang/docs/ClangOffloadBundler.rst
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/clang-offload-bundler.c
  clang/test/Driver/hip-rdc-device-only.hip
  clang/test/Driver/hip-toolchain-rdc-separate.hip
  clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Index: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
@@ -22,14 +22,18 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Triple.h"
+#include "llvm/Object/Archive.h"
+#include "llvm/Object/ArchiveWriter.h"
 #include "llvm/Object/Binary.h"
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Debug.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
@@ -82,6 +86,7 @@
"  bc  - llvm-bc\n"
"  s   - assembler\n"
"  o   - object\n"
+   "  a   - archive of objects\n"
"  gch - precompiled-header\n"
"  ast - clang AST file"),
   cl::cat(ClangOffloadBundlerCategory));
@@ -123,20 +128,49 @@
 /// Path to the current binary.
 static std::string BundlerExecutable;
 
-/// Obtain the offload kind and real machine triple out of the target
-/// information specified by the user.
-static void getOffloadKindAndTriple(StringRef Target, StringRef &OffloadKind,
-StringRef &Triple) {
-  auto KindTriplePair = Target.split('-');
-  OffloadKind = KindTriplePair.first;
-  Triple = KindTriplePair.second;
-}
-static bool hasHostKind(StringRef Target) {
+/// Obtain the offload kind, real machine triple, and an optional GPUArch
+/// out of the target information specified by the user.
+/// Bundle Entry ID (or, Offload Target String) has following components:
+///  * Offload Kind - Host, OpenMP, or HIP
+///  * Triple - Standard LLVM Triple
+///  * GPUArch (Optional) - Processor name, like gfx906 or sm_30
+/// In presence of Proc, the Triple should contain separator "-" for all
+/// standard four components, even if they are empty.
+struct OffloadTargetInfo {
   StringRef OffloadKind;
-  StringRef Triple;
-  getOffloadKindAndTriple(Target, OffloadKind, Triple);
-  return OffloadKind == "host";
-}
+  llvm::Triple Triple;
+  StringRef GPUArch;
+
+  OffloadTargetInfo(const StringRef Target) {
+SmallVector Components;
+Target.split(Components, '-', 5);
+Components.resize(6);
+this->OffloadKind = Components[0];
+this->Triple = llvm::Triple(Components[1], Components[2], Components[3],
+Components[4]);
+this->GPUArch = Components[5];
+  }
+
+  bool hasHostKind() const { return this->OffloadKind == "host"; }
+
+  bool isOffloadKindValid() const {
+return OffloadKind == "host" || OffloadKind == "openmp" ||
+   OffloadKind == "hip" || OffloadKind == "hipv4";
+  }
+
+  bool isTripleValid() const {
+return !Triple.str().empty() && Triple.getArch() != Triple::UnknownArch;
+  }
+
+  bool operator==(const OffloadTargetInfo &Target) const {
+return OffloadKind == Target.OffloadKind &&
+   Triple.isCompatibleWith(Target.Triple) && GPUArch == Target.GPUArch;
+  }
+
+  std::string str() {
+return Twine(OffloadKind + "-" + Triple.str() + "-" + GPUArch).str();
+  }
+};
 
 /// Generic file handler interface.
 class FileHandler {
@@ -163,7 +197,7 @@
   virtual Error ReadBundleEnd(MemoryBuffer &Input) = 0;
 
   /// Read the current bundle and write the result into the stream \a OS.
-  virtual Error ReadBundle(raw_fd_ostream &OS, MemoryBuffer &Input) = 0;
+  virtual Error ReadBundle(raw_ostream &OS, MemoryBuffer &Input) = 0;
 
   /// Write the header of the bundled file to \a OS based on the information
   /// gathered from \a Inputs.
@@ -378,7 +412,7 @@
 return Error::success();
   }
 
-  Error ReadBundle(raw_fd_ostream &OS, MemoryBuffer &Input) final {
+  Error ReadBundle(raw_ostream &OS, MemoryBuffer &Input) final {
 assert(CurBundleInfo != BundlesInfo.end() && "Invalid reader info!");
 StringRef FC = Input.getBuffer();
 OS.write(FC.data() + CurBundleInfo->second.Offset,
@@ -541,7 +575,7 @@
 
   Error ReadBundleEnd(MemoryBuff

[PATCH] D104774: [clang-format] Fix a bug that indents else-comment-if incorrectly

2021-06-23 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


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104774

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


[PATCH] D104777: PR50767: clear non-distinct debuginfo for function with nodebug definition after undecorated declaration

2021-06-23 Thread Bruno De Fraine via Phabricator via cfe-commits
brunodefraine created this revision.
brunodefraine added reviewers: ychen, dblaikie.
brunodefraine added a project: clang.
brunodefraine requested review of this revision.
Herald added a subscriber: cfe-commits.

Fix suggested by Yuanfang Chen:

Non-distinct debuginfo is attached to the function due to the undecorated 
declaration. Later, when seeing the function definition and `nodebug` 
attribute, the non-distinct debuginfo should be cleared.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104777

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/attr-nodebug2.cpp


Index: clang/test/CodeGen/attr-nodebug2.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-nodebug2.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -debug-info-kind=limited -debugger-tuning=gdb 
-dwarf-version=4 -O -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
+
+void t1();
+
+void use() { t1(); }
+
+__attribute__((nodebug))
+void t1()
+{
+  int a = 10;
+  a++;
+}
+
+// CHECK-LABEL: define{{.*}} void @_Z3usev()
+// CHECK-SAME:  !dbg
+// CHECK-SAME:  {
+// CHECK:   !dbg
+// CHECK:   }
+
+// PR50767 Function __attribute__((nodebug)) inconsistency causes crash
+// illegal (non-distinct) !dbg metadata was being added to _Z2t1v definition
+
+// CHECK-LABEL: define{{.*}} void @_Z2t1v()
+// CHECK-NOT:   !dbg
+// CHECK-SAME:  {
+// CHECK-NOT:   !dbg
+// CHECK:   }
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1300,8 +1300,14 @@
   QualType ResTy = BuildFunctionArgList(GD, Args);
 
   // Check if we should generate debug info for this function.
-  if (FD->hasAttr())
-DebugInfo = nullptr; // disable debug info indefinitely for this function
+  if (FD->hasAttr()) {
+// Clear non-distinct debug info that was possibly attached to
+// the function due to a declaration with the nodebug attribute
+if (Fn)
+  Fn->setSubprogram(nullptr);
+// Disable debug info indefinitely for this function
+DebugInfo = nullptr;
+  }
 
   // The function might not have a body if we're generating thunks for a
   // function declaration.


Index: clang/test/CodeGen/attr-nodebug2.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-nodebug2.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -debug-info-kind=limited -debugger-tuning=gdb -dwarf-version=4 -O -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
+
+void t1();
+
+void use() { t1(); }
+
+__attribute__((nodebug))
+void t1()
+{
+  int a = 10;
+  a++;
+}
+
+// CHECK-LABEL: define{{.*}} void @_Z3usev()
+// CHECK-SAME:  !dbg
+// CHECK-SAME:  {
+// CHECK:   !dbg
+// CHECK:   }
+
+// PR50767 Function __attribute__((nodebug)) inconsistency causes crash
+// illegal (non-distinct) !dbg metadata was being added to _Z2t1v definition
+
+// CHECK-LABEL: define{{.*}} void @_Z2t1v()
+// CHECK-NOT:   !dbg
+// CHECK-SAME:  {
+// CHECK-NOT:   !dbg
+// CHECK:   }
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1300,8 +1300,14 @@
   QualType ResTy = BuildFunctionArgList(GD, Args);
 
   // Check if we should generate debug info for this function.
-  if (FD->hasAttr())
-DebugInfo = nullptr; // disable debug info indefinitely for this function
+  if (FD->hasAttr()) {
+// Clear non-distinct debug info that was possibly attached to
+// the function due to a declaration with the nodebug attribute
+if (Fn)
+  Fn->setSubprogram(nullptr);
+// Disable debug info indefinitely for this function
+DebugInfo = nullptr;
+  }
 
   // The function might not have a body if we're generating thunks for a
   // function declaration.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104770: Add support for #pragma system_header with -fms-extensions

2021-06-23 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In D104770#2835596 , @aaron.ballman 
wrote:

> LGTM, though you could add a test that `#pragma system_header` gives a 
> diagnostic outside of `-fms-extensions` mode if you think that's valuable.

Thanks! Yes, I'll do that, and I'll also add a test to see that it actually 
warns when no system_header is used.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104770

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


[PATCH] D104770: Add support for #pragma system_header with -fms-extensions

2021-06-23 Thread Hans Wennborg 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 rG24037c37b6c4: Add support for #pragma system_header with 
-fms-extensions (authored by hans).

Changed prior to commit:
  https://reviews.llvm.org/D104770?vs=353895&id=353926#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104770

Files:
  clang/lib/Lex/Pragma.cpp
  clang/test/Lexer/pragma-operators.cpp
  clang/test/Preprocessor/Inputs/pragma_sysheader.h
  clang/test/Preprocessor/pragma_sysheader.c
  clang/test/Preprocessor/pragma_sysheader.h


Index: clang/test/Preprocessor/pragma_sysheader.h
===
--- clang/test/Preprocessor/pragma_sysheader.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#pragma GCC system_header
-typedef int x;
-typedef int x;
-
Index: clang/test/Preprocessor/pragma_sysheader.c
===
--- clang/test/Preprocessor/pragma_sysheader.c
+++ clang/test/Preprocessor/pragma_sysheader.c
@@ -1,13 +1,15 @@
-// RUN: %clang_cc1 -verify -pedantic %s -fsyntax-only
-// RUN: %clang_cc1 -E %s | FileCheck %s
-// expected-no-diagnostics
-// rdar://6899937
-#include "pragma_sysheader.h"
+// RUN: %clang_cc1 -verify -std=c99 -Wunknown-pragmas -pedantic %s 
-fsyntax-only
+// RUN: %clang_cc1 -verify -std=c99 -Wunknown-pragmas -pedantic %s 
-fsyntax-only -DGCC
+// RUN: %clang_cc1 -verify -std=c99 -Wunknown-pragmas -pedantic %s 
-fsyntax-only -DCLANG
+// RUN: %clang_cc1 -verify -std=c99 -Wunknown-pragmas -pedantic %s 
-fsyntax-only -fms-extensions -DMS
 
+// rdar://6899937
+#include "Inputs/pragma_sysheader.h"
 
+// RUN: %clang_cc1 -E %s | FileCheck %s
 // PR9861: Verify that line markers are not messed up in -E mode.
 // CHECK: # 1 "{{.*}}pragma_sysheader.h" 1
-// CHECK-NEXT: # 2 "{{.*}}pragma_sysheader.h" 3
-// CHECK-NEXT: typedef int x;
-// CHECK-NEXT: typedef int x;
-// CHECK-NEXT: # 6 "{{.*}}pragma_sysheader.c" 2
+// CHECK-NEXT: # 12 "{{.*}}pragma_sysheader.h"
+// CHECK: typedef int x;
+// CHECK: typedef int x;
+// CHECK-NEXT: # 8 "{{.*}}pragma_sysheader.c" 2
Index: clang/test/Preprocessor/Inputs/pragma_sysheader.h
===
--- /dev/null
+++ clang/test/Preprocessor/Inputs/pragma_sysheader.h
@@ -0,0 +1,19 @@
+#if defined(CLANG)
+#pragma clang system_header
+// expected-no-diagnostics
+#elif defined(GCC)
+#pragma GCC system_header
+// expected-no-diagnostics
+#elif defined(MS)
+#pragma system_header
+// expected-no-diagnostics
+#else
+// expected-warning@+1{{unknown pragma ignored}}
+#pragma system_header
+
+// expected-note@+4{{previous definition is here}}
+// expected-warning@+4{{redefinition of typedef 'x' is a C11 feature}}
+#endif
+
+typedef int x;
+typedef int x;
Index: clang/test/Lexer/pragma-operators.cpp
===
--- clang/test/Lexer/pragma-operators.cpp
+++ clang/test/Lexer/pragma-operators.cpp
@@ -19,7 +19,7 @@
 #pragma warning(pop)
 
 #define pragma_L _Pragma(L"GCC diagnostic push")
-#define pragma_u8 _Pragma(u8"system_header")
+#define pragma_u8 _Pragma(u8"pack(1)")
 #define pragma_u _Pragma(u"GCC diagnostic pop")
 #define pragma_U _Pragma(U"comment(lib, \"libfoo\")")
 #define pragma_R _Pragma(R"(clang diagnostic ignored "-Wunused")")
@@ -27,7 +27,7 @@
 #define pragma_hello _Pragma(u8R"x(message R"y("Hello", world!)y")x")
 // CHECK: int n =
 // CHECK: #pragma GCC diagnostic push
-// CHECK: #pragma system_header
+// CHECK: #pragma pack(1)
 // CHECK: #pragma GCC diagnostic pop
 // CHECK: #pragma comment(lib, "libfoo")
 // CHECK: #pragma clang diagnostic ignored "-Wunused"
Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -1955,6 +1955,7 @@
 AddPragmaHandler(new PragmaExecCharsetHandler());
 AddPragmaHandler(new PragmaIncludeAliasHandler());
 AddPragmaHandler(new PragmaHdrstopHandler());
+AddPragmaHandler(new PragmaSystemHeaderHandler());
   }
 
   // Pragmas added by plugins


Index: clang/test/Preprocessor/pragma_sysheader.h
===
--- clang/test/Preprocessor/pragma_sysheader.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#pragma GCC system_header
-typedef int x;
-typedef int x;
-
Index: clang/test/Preprocessor/pragma_sysheader.c
===
--- clang/test/Preprocessor/pragma_sysheader.c
+++ clang/test/Preprocessor/pragma_sysheader.c
@@ -1,13 +1,15 @@
-// RUN: %clang_cc1 -verify -pedantic %s -fsyntax-only
-// RUN: %clang_cc1 -E %s | FileCheck %s
-// expected-no-diagnostics
-// rdar://6899937
-#include "pragma_sysheader.h"
+// RUN: %clang_cc1 -verify -std=c99 -Wunknown-pragmas -pedantic %s -fsyntax-only
+// RUN: %clan

[clang] 24037c3 - Add support for #pragma system_header with -fms-extensions

2021-06-23 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2021-06-23T13:26:03+02:00
New Revision: 24037c37b6c4043faae7bf396b735e1ba36e46e0

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

LOG: Add support for #pragma system_header with -fms-extensions

Clang already supports the pragma prefixed by "GCC" or "clang".

MSVC has more recently added support for the pragma, but without any prefix; see
https://devblogs.microsoft.com/cppblog/broken-warnings-theory/#external-headers

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

Added: 
clang/test/Preprocessor/Inputs/pragma_sysheader.h

Modified: 
clang/lib/Lex/Pragma.cpp
clang/test/Lexer/pragma-operators.cpp
clang/test/Preprocessor/pragma_sysheader.c

Removed: 
clang/test/Preprocessor/pragma_sysheader.h



diff  --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp
index 5b42241a32c2e..081b92ac21d9a 100644
--- a/clang/lib/Lex/Pragma.cpp
+++ b/clang/lib/Lex/Pragma.cpp
@@ -1955,6 +1955,7 @@ void Preprocessor::RegisterBuiltinPragmas() {
 AddPragmaHandler(new PragmaExecCharsetHandler());
 AddPragmaHandler(new PragmaIncludeAliasHandler());
 AddPragmaHandler(new PragmaHdrstopHandler());
+AddPragmaHandler(new PragmaSystemHeaderHandler());
   }
 
   // Pragmas added by plugins

diff  --git a/clang/test/Lexer/pragma-operators.cpp 
b/clang/test/Lexer/pragma-operators.cpp
index 4d288c9372d64..d9c3d36d78704 100644
--- a/clang/test/Lexer/pragma-operators.cpp
+++ b/clang/test/Lexer/pragma-operators.cpp
@@ -19,7 +19,7 @@ B(foo)
 #pragma warning(pop)
 
 #define pragma_L _Pragma(L"GCC diagnostic push")
-#define pragma_u8 _Pragma(u8"system_header")
+#define pragma_u8 _Pragma(u8"pack(1)")
 #define pragma_u _Pragma(u"GCC diagnostic pop")
 #define pragma_U _Pragma(U"comment(lib, \"libfoo\")")
 #define pragma_R _Pragma(R"(clang diagnostic ignored "-Wunused")")
@@ -27,7 +27,7 @@ B(foo)
 #define pragma_hello _Pragma(u8R"x(message R"y("Hello", world!)y")x")
 // CHECK: int n =
 // CHECK: #pragma GCC diagnostic push
-// CHECK: #pragma system_header
+// CHECK: #pragma pack(1)
 // CHECK: #pragma GCC diagnostic pop
 // CHECK: #pragma comment(lib, "libfoo")
 // CHECK: #pragma clang diagnostic ignored "-Wunused"

diff  --git a/clang/test/Preprocessor/Inputs/pragma_sysheader.h 
b/clang/test/Preprocessor/Inputs/pragma_sysheader.h
new file mode 100644
index 0..7352370e724b4
--- /dev/null
+++ b/clang/test/Preprocessor/Inputs/pragma_sysheader.h
@@ -0,0 +1,19 @@
+#if defined(CLANG)
+#pragma clang system_header
+// expected-no-diagnostics
+#elif defined(GCC)
+#pragma GCC system_header
+// expected-no-diagnostics
+#elif defined(MS)
+#pragma system_header
+// expected-no-diagnostics
+#else
+// expected-warning@+1{{unknown pragma ignored}}
+#pragma system_header
+
+// expected-note@+4{{previous definition is here}}
+// expected-warning@+4{{redefinition of typedef 'x' is a C11 feature}}
+#endif
+
+typedef int x;
+typedef int x;

diff  --git a/clang/test/Preprocessor/pragma_sysheader.c 
b/clang/test/Preprocessor/pragma_sysheader.c
index 3c94363152af7..421bfb839ee30 100644
--- a/clang/test/Preprocessor/pragma_sysheader.c
+++ b/clang/test/Preprocessor/pragma_sysheader.c
@@ -1,13 +1,15 @@
-// RUN: %clang_cc1 -verify -pedantic %s -fsyntax-only
-// RUN: %clang_cc1 -E %s | FileCheck %s
-// expected-no-diagnostics
-// rdar://6899937
-#include "pragma_sysheader.h"
+// RUN: %clang_cc1 -verify -std=c99 -Wunknown-pragmas -pedantic %s 
-fsyntax-only
+// RUN: %clang_cc1 -verify -std=c99 -Wunknown-pragmas -pedantic %s 
-fsyntax-only -DGCC
+// RUN: %clang_cc1 -verify -std=c99 -Wunknown-pragmas -pedantic %s 
-fsyntax-only -DCLANG
+// RUN: %clang_cc1 -verify -std=c99 -Wunknown-pragmas -pedantic %s 
-fsyntax-only -fms-extensions -DMS
 
+// rdar://6899937
+#include "Inputs/pragma_sysheader.h"
 
+// RUN: %clang_cc1 -E %s | FileCheck %s
 // PR9861: Verify that line markers are not messed up in -E mode.
 // CHECK: # 1 "{{.*}}pragma_sysheader.h" 1
-// CHECK-NEXT: # 2 "{{.*}}pragma_sysheader.h" 3
-// CHECK-NEXT: typedef int x;
-// CHECK-NEXT: typedef int x;
-// CHECK-NEXT: # 6 "{{.*}}pragma_sysheader.c" 2
+// CHECK-NEXT: # 12 "{{.*}}pragma_sysheader.h"
+// CHECK: typedef int x;
+// CHECK: typedef int x;
+// CHECK-NEXT: # 8 "{{.*}}pragma_sysheader.c" 2

diff  --git a/clang/test/Preprocessor/pragma_sysheader.h 
b/clang/test/Preprocessor/pragma_sysheader.h
deleted file mode 100644
index b79bde584a98b..0
--- a/clang/test/Preprocessor/pragma_sysheader.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#pragma GCC system_header
-typedef int x;
-typedef int x;
-



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


[clang] 76c931a - [AIX][PowerPC] Remove error when specifying mabi=vec-default on AIX

2021-06-23 Thread Zarko Todorovski via cfe-commits

Author: Zarko Todorovski
Date: 2021-06-23T07:40:38-04:00
New Revision: 76c931ae42cf1080199a238446306e8554ebb6de

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

LOG: [AIX][PowerPC] Remove error when specifying mabi=vec-default on AIX

The default Altivec ABI was implemented but the clang error for specifying
its use still remains.  Users could get around this but not specifying the
type of Altivec ABI but we need to remove the error.

Reviewed By: jsji

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

Added: 
clang/test/Driver/aix-vec_extabi.c

Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/altivec.c
clang/test/Preprocessor/aix-vec_extabi.c

Removed: 
clang/test/Driver/aix-vec-extabi.c



diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 6e4a60156fef7..c7da9713b1e4e 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -542,9 +542,6 @@ def err_drv_cannot_mix_options : Error<"cannot specify '%1' 
along with '%0'">;
 
 def err_drv_invalid_object_mode : Error<"OBJECT_MODE setting %0 is not 
recognized and is not a valid setting.">;
 
-def err_aix_default_altivec_abi : Error<
-  "The default Altivec ABI on AIX is not yet supported, use '-mabi=vec-extabi' 
for the extended Altivec ABI">;
-
 def err_aix_unsupported_tls_model : Error<"TLS model '%0' is not yet supported 
on AIX">;
 
 def err_invalid_cxx_abi : Error<"Invalid C++ ABI name '%0'">;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index eafe5de8eedb8..b358813a1a017 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4823,7 +4823,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 if (A->getOption().getID() == options::OPT_mabi_EQ_vec_extabi)
   CmdArgs.push_back("-mabi=vec-extabi");
 else
-  D.Diag(diag::err_aix_default_altivec_abi);
+  CmdArgs.push_back("-mabi=vec-default");
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_Wframe_larger_than_EQ)) {

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 5bbb954c7d4d7..c1b7b027b3b4d 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1859,13 +1859,7 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions 
&Opts, ArgList &Args,
   << A->getSpelling() << T.str();
 
 const Option &O = A->getOption();
-if (O.matches(OPT_mabi_EQ_vec_default))
-  Diags.Report(diag::err_aix_default_altivec_abi)
-  << A->getSpelling() << T.str();
-else {
-  assert(O.matches(OPT_mabi_EQ_vec_extabi));
-  Opts.EnableAIXExtendedAltivecABI = 1;
-}
+Opts.EnableAIXExtendedAltivecABI = O.matches(OPT_mabi_EQ_vec_extabi);
   }
 
   bool NeedLocTracking = false;

diff  --git a/clang/test/CodeGen/altivec.c b/clang/test/CodeGen/altivec.c
index 86b570f15d080..af239b54711c1 100644
--- a/clang/test/CodeGen/altivec.c
+++ b/clang/test/CodeGen/altivec.c
@@ -4,12 +4,12 @@
 // RUN: %clang_cc1 -target-feature +altivec -triple 
powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-LE
 // RUN: %clang_cc1 -target-feature +altivec -mabi=vec-extabi -target-cpu pwr8 
-triple powerpc-unknown-aix -emit-llvm %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-BE
 // RUN: %clang_cc1 -target-feature +altivec -mabi=vec-extabi -target-cpu pwr8 
-triple powerpc64-unknown-aix -emit-llvm %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-BE
-// RUN: not %clang_cc1 -target-feature +altivec -mabi=vec-default -target-cpu 
pwr8 -triple powerpc-unknown-aix -emit-llvm %s 2>&1 | FileCheck %s 
--check-prefix=AIX-ERROR
-// RUN: not %clang_cc1 -target-feature +altivec -mabi=vec-default -target-cpu 
pwr8 -triple powerpc64-unknown-aix -emit-llvm %s 2>&1 | FileCheck %s 
--check-prefix=AIX-ERROR
-// RUN: %clang -S -emit-llvm -maltivec -mabi=vec-extabi -mcpu=pwr8 -target 
powerpc-unknown-aix %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE
-// RUN: %clang -S -emit-llvm -maltivec -mabi=vec-extabi -mcpu=pwr8 -target 
powerpc64-unknown-aix %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE
-// RUN: not %clang -S -emit-llvm -maltivec -mabi=vec-default -mcpu=pwr8 
-triple powerpc-unknown-aix -emit-llvm %s 2>&1 | FileCheck %s 
--check-prefix=AIX-ERROR
-// RUN: not %clang -S -emit-llvm -maltivec -mabi=vec-default -mcpu=pwr8 
-triple powerpc64-unknown-aix -emit-llvm %s 2>&1 | FileCheck %s 
--check-prefix=AIX-ERROR
+// RUN: %clang_cc1 -target-f

[PATCH] D102094: [AIX][PowerPC] Remove error when specifying mabi=vec-default on AIX

2021-06-23 Thread Zarko Todorovski 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 rG76c931ae42cf: [AIX][PowerPC] Remove error when specifying 
mabi=vec-default on AIX (authored by ZarkoCA).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102094

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/altivec.c
  clang/test/Driver/aix-vec-extabi.c
  clang/test/Driver/aix-vec_extabi.c
  clang/test/Preprocessor/aix-vec_extabi.c

Index: clang/test/Preprocessor/aix-vec_extabi.c
===
--- clang/test/Preprocessor/aix-vec_extabi.c
+++ clang/test/Preprocessor/aix-vec_extabi.c
@@ -2,11 +2,11 @@
 // RUN:   | FileCheck %s -check-prefix=EXTABI
 // RUN: %clang  -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -E -dM -maltivec -mabi=vec-extabi %s -o - 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=EXTABI
-// RUN: not %clang  -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -E -dM -maltivec -mabi=vec-default %s 2>&1 \
+// RUN: %clang  -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -E -dM -maltivec -mabi=vec-default %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=DFLTABI
-// RUN: not %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -E -dM -maltivec -mabi=vec-default %s 2>&1 \
+// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -E -dM -maltivec -mabi=vec-default %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=DFLTABI
 
 
-// EXTABI:  #define __EXTABI__
-// DFLTABI: The default Altivec ABI on AIX is not yet supported, use '-mabi=vec-extabi' for the extended Altivec ABI
+// EXTABI:  #define __EXTABI__
+// DFLTABI-NOT: #define __EXTABI__
Index: clang/test/Driver/aix-vec_extabi.c
===
--- /dev/null
+++ clang/test/Driver/aix-vec_extabi.c
@@ -0,0 +1,16 @@
+// RUN:  %clang -### -target powerpc-unknown-aix -S %s 2>&1 | \
+// RUN:  FileCheck %s --implicit-check-not=vec-extabi
+// RUN:  %clang -### -target powerpc-unknown-aix -S -maltivec %s 2>&1 | \
+// RUN:  FileCheck %s --implicit-check-not=vec-extabi
+// RUN:  %clang -### -target powerpc-unknown-aix -S -maltivec -mabi=vec-default %s 2>&1 | \
+// RUN:  FileCheck %s --check-prefix=DFLTABI --implicit-check-not=vec-extabi
+// RUN:  %clang -### -target powerpc-unknown-aix -S -mabi=vec-extabi %s 2>&1 | \
+// RUN:  FileCheck %s --check-prefix=EXTABI
+// RUN:  %clang -### -target powerpc-unknown-aix -S -maltivec -mabi=vec-extabi %s 2>&1 | \
+// RUN:  FileCheck %s --check-prefix=EXTABI
+/
+// EXTABI:   "-cc1"
+// EXTABI-SAME:  "-mabi=vec-extabi"
+
+// DFLTABI:  "-cc1"
+// DFLTABI-SAME: "-mabi=vec-default"
Index: clang/test/Driver/aix-vec-extabi.c
===
--- clang/test/Driver/aix-vec-extabi.c
+++ /dev/null
@@ -1,10 +0,0 @@
-// RUN:  %clang -### -target powerpc-unknown-aix -S -maltivec -mabi=vec-extabi %s 2>&1 | \
-// RUN:  FileCheck %s
-
-// CHECK: "-cc1"
-// CHECK-SAME: "-mabi=vec-extabi"
-
-// RUN:  %clang -### -target powerpc-unknown-aix -S -maltivec -mabi=vec-default %s 2>&1 | \
-// RUN:  FileCheck %s --check-prefix=ERROR
-
-// ERROR: The default Altivec ABI on AIX is not yet supported, use '-mabi=vec-extabi' for the extended Altivec ABI
Index: clang/test/CodeGen/altivec.c
===
--- clang/test/CodeGen/altivec.c
+++ clang/test/CodeGen/altivec.c
@@ -4,12 +4,12 @@
 // RUN: %clang_cc1 -target-feature +altivec -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-LE
 // RUN: %clang_cc1 -target-feature +altivec -mabi=vec-extabi -target-cpu pwr8 -triple powerpc-unknown-aix -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE
 // RUN: %clang_cc1 -target-feature +altivec -mabi=vec-extabi -target-cpu pwr8 -triple powerpc64-unknown-aix -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE
-// RUN: not %clang_cc1 -target-feature +altivec -mabi=vec-default -target-cpu pwr8 -triple powerpc-unknown-aix -emit-llvm %s 2>&1 | FileCheck %s --check-prefix=AIX-ERROR
-// RUN: not %clang_cc1 -target-feature +altivec -mabi=vec-default -target-cpu pwr8 -triple powerpc64-unknown-aix -emit-llvm %s 2>&1 | FileCheck %s --check-prefix=AIX-ERROR
-// RUN: %clang -S -emit-llvm -maltivec -mabi=vec-extabi -mcpu=pwr8 -target powerpc-unknown-aix %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE
-// RUN: %clang -S -emit-llvm -maltivec -mabi=vec-extabi -mcpu=pwr8 -target powerpc64-unknown-aix %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE
-// RUN: not %clang -S -emit-llvm -maltivec -mabi=vec-default -mcpu=pwr8 -triple powerpc-unknown-aix -emit-llvm %s 2>&1 | FileCheck %s --check-prefix=AIX-ERROR
-// RUN: not %clang -S -emit-llvm -maltivec -m

[PATCH] D103131: support debug info for alias variable

2021-06-23 Thread kamlesh kumar via Phabricator via cfe-commits
kamleshbhalui added a comment.

Here is what we get when we replace int with float.

  $lldb-11 ./a.out 
  (lldb) target create "./a.out"
  Current executable set to '/folk/kkumar/tcllvm/llvm-build-lldb-rel/bin/a.out' 
(x86_64).
  (lldb) b main
  Breakpoint 1: where = a.out`main + 4 at test.c:3:12, address = 
0x00400484
  (lldb) p oldname
  (float) $0 = 1
  (lldb) p newname
  (void *) $1 = 0x3f80


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


[clang] ca7f471 - [clang-format] Fix a bug that indents else-comment-if incorrectly

2021-06-23 Thread via cfe-commits

Author: owenca
Date: 2021-06-23T04:57:45-07:00
New Revision: ca7f4715858137dc97ac782cead65ba706bffa3c

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

LOG: [clang-format] Fix a bug that indents else-comment-if incorrectly

PR50809

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 0fb5428f89673..45ff319b5841d 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2021,7 +2021,15 @@ void UnwrappedLineParser::parseIfThenElse() {
   parseBlock(/*MustBeDeclaration=*/false);
   addUnwrappedLine();
 } else if (FormatTok->Tok.is(tok::kw_if)) {
+  FormatToken *Previous = AllTokens[Tokens->getPosition() - 1];
+  bool PrecededByComment = Previous->is(tok::comment);
+  if (PrecededByComment) {
+addUnwrappedLine();
+++Line->Level;
+  }
   parseIfThenElse();
+  if (PrecededByComment)
+--Line->Level;
 } else {
   addUnwrappedLine();
   ++Line->Level;

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 108d918ce3453..59690c722a9ed 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -1181,6 +1181,13 @@ TEST_F(FormatTest, ElseIf) {
"  g();\n"
"else\n"
"  h();");
+  verifyFormat("if (a)\n"
+   "  f();\n"
+   "else // comment\n"
+   "  if (b) {\n"
+   "g();\n"
+   "h();\n"
+   "  }");
   verifyFormat("if constexpr (a)\n"
"  f();\n"
"else if constexpr (b)\n"



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


[PATCH] D104774: [clang-format] Fix a bug that indents else-comment-if incorrectly

2021-06-23 Thread 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 rGca7f47158581: [clang-format] Fix a bug that indents 
else-comment-if incorrectly (authored by owenca 
).

Changed prior to commit:
  https://reviews.llvm.org/D104774?vs=353909&id=353933#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104774

Files:
  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
@@ -1181,6 +1181,13 @@
"  g();\n"
"else\n"
"  h();");
+  verifyFormat("if (a)\n"
+   "  f();\n"
+   "else // comment\n"
+   "  if (b) {\n"
+   "g();\n"
+   "h();\n"
+   "  }");
   verifyFormat("if constexpr (a)\n"
"  f();\n"
"else if constexpr (b)\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2021,7 +2021,15 @@
   parseBlock(/*MustBeDeclaration=*/false);
   addUnwrappedLine();
 } else if (FormatTok->Tok.is(tok::kw_if)) {
+  FormatToken *Previous = AllTokens[Tokens->getPosition() - 1];
+  bool PrecededByComment = Previous->is(tok::comment);
+  if (PrecededByComment) {
+addUnwrappedLine();
+++Line->Level;
+  }
   parseIfThenElse();
+  if (PrecededByComment)
+--Line->Level;
 } else {
   addUnwrappedLine();
   ++Line->Level;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -1181,6 +1181,13 @@
"  g();\n"
"else\n"
"  h();");
+  verifyFormat("if (a)\n"
+   "  f();\n"
+   "else // comment\n"
+   "  if (b) {\n"
+   "g();\n"
+   "h();\n"
+   "  }");
   verifyFormat("if constexpr (a)\n"
"  f();\n"
"else if constexpr (b)\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2021,7 +2021,15 @@
   parseBlock(/*MustBeDeclaration=*/false);
   addUnwrappedLine();
 } else if (FormatTok->Tok.is(tok::kw_if)) {
+  FormatToken *Previous = AllTokens[Tokens->getPosition() - 1];
+  bool PrecededByComment = Previous->is(tok::comment);
+  if (PrecededByComment) {
+addUnwrappedLine();
+++Line->Level;
+  }
   parseIfThenElse();
+  if (PrecededByComment)
+--Line->Level;
 } else {
   addUnwrappedLine();
   ++Line->Level;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104774: [clang-format] Fix a bug that indents else-comment-if incorrectly

2021-06-23 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104774

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


[PATCH] D75041: [clang-tidy] Extend 'bugprone-easily-swappable-parameters' with mixability because of implicit conversions

2021-06-23 Thread Whisperity via Phabricator via cfe-commits
whisperity marked 2 inline comments as done.
whisperity added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp:657-667
+  // Certain kinds unfortunately need to be side-stepped for canonical type
+  // matching.
+  if (LType->getAs() || RType->getAs()) {
+// Unfortunately, the canonical type of a function pointer becomes the
+// same even if exactly one is "noexcept" and the other isn't, making us
+// give a false positive report irrespective of implicit conversions.
+LLVM_DEBUG(llvm::dbgs()

whisperity wrote:
> whisperity wrote:
> > martong wrote:
> > > aaron.ballman wrote:
> > > > whisperity wrote:
> > > > > @aaron.ballman Getting ahead of the curve here. I understand this is 
> > > > > ugly. Unfortunately, no matter how much I read the standard, I don't 
> > > > > get anything of "canonical type" mentioned, it seems to me this 
> > > > > concept is something inherent to the model of Clang.
> > > > > 
> > > > > Basically why this is here: imagine a `void (*)() noexcept` and a 
> > > > > `void (*)()`. One's `noexcept`, the other isn't. Inside the AST, this 
> > > > > is a `ParenType` of a `PointerType` to a `FunctionProtoType`. There 
> > > > > exists a //one-way// implicit conversion from the `noexcept` to the 
> > > > > non-noexcept ("noexceptness can be discarded", similarly to how 
> > > > > "constness can be gained")
> > > > > Unfortunately, because this is a one-way implicit conversion, it 
> > > > > won't return on the code path earlier for implicit conversions.
> > > > > 
> > > > > Now because of this, the recursive descent in our code will reach the 
> > > > > point when the two innermost `FunctionProtoType`s are in our hands. 
> > > > > As a fallback case, we simply ask Clang "Hey, do //you// think these 
> > > > > two are the same?". And for some weird reason, Clang will say 
> > > > > "Yes."... While one of them is a `noexcept` function and the other 
> > > > > one isn't.
> > > > > 
> > > > > I do not know the innards of the AST well enough to even have a 
> > > > > glimpse of whether or not this is a bug. So that's the reason why I 
> > > > > went ahead and implemented this side-stepping logic. Basically, as 
> > > > > the comment says, it'lll **force** the information of "No matter what 
> > > > > you do, do NOT consider these mixable!" back up the recursion chain, 
> > > > > and handle it appropriately later.
> > > > > Unfortunately, no matter how much I read the standard, I don't get 
> > > > > anything of "canonical type" mentioned, it seems to me this concept 
> > > > > is something inherent to the model of Clang.
> > > > 
> > > > It is more of a Clang-centric concept. Basically, a canonical type is 
> > > > one that's had all of the typedefs stripped off it.
> > > > 
> > > > > Now because of this, the recursive descent in our code will reach the 
> > > > > point when the two innermost FunctionProtoTypes are in our hands. As 
> > > > > a fallback case, we simply ask Clang "Hey, do you think these two are 
> > > > > the same?". And for some weird reason, Clang will say "Yes."... While 
> > > > > one of them is a noexcept function and the other one isn't.
> > > > 
> > > > I think a confounding factor in this area is that `noexcept` did not 
> > > > used to be part of the function type until one day it started being a 
> > > > part of the function type. So my guess is that this is fallout from 
> > > > this sort of thing: https://godbolt.org/z/EYfj8z (which may be worth 
> > > > keeping in mind when working on the check).
> > > About `noexcept`: we've faced a similar problem in the `ASTImporter` 
> > > library. We could not import a noexcept function's definition if we 
> > > already had one without the noexcept specifier. 
> > > 
> > > Thus, in `ASTStructuralEquivalence.cpp` we do differentiate the function 
> > > types based on their noexcept specifier (and we even check the noexcept 
> > > expression).:
> > > ```
> > > TEST_F(StructuralEquivalenceFunctionTest, Noexcept) {
> > >   auto t = makeNamedDecls("void foo();",
> > >   "void foo() noexcept;", Lang_CXX11);
> > >   EXPECT_FALSE(testStructuralMatch(t));
> > > }
> > > TEST_F(StructuralEquivalenceFunctionTest, NoexceptNonMatch) {
> > >   auto t = makeNamedDecls("void foo() noexcept(false);",
> > >   "void foo() noexcept(true);", Lang_CXX11);
> > >   EXPECT_FALSE(testStructuralMatch(t));
> > > }
> > > ```
> > > 
> > > May be in these special cases it would worth to reuse the 
> > > ASTStructuralEquivalenceContext class?
> > Definitely, good catch, @martong, thank you very much! @aaron.ballman, what 
> > do you think? If I see this right, `StructuralEquivalenceContext` is part 
> > of `libClangAST` so should be readily available.
> > 
> > The only issue I'm seeing is that this class takes non-**`const`** 
> > `ASTContext` and `Decl` nodes...
> Well, I started looking into putting up `con

[PATCH] D104777: PR50767: clear non-distinct debuginfo for function with nodebug definition after undecorated declaration

2021-06-23 Thread Bruno De Fraine via Phabricator via cfe-commits
brunodefraine updated this revision to Diff 353949.
brunodefraine added a comment.

Fix issues from Windows/clang-format buildbot. Fix mistake in code comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104777

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/attr-nodebug2.cpp


Index: clang/test/CodeGen/attr-nodebug2.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-nodebug2.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -debug-info-kind=limited 
-debugger-tuning=gdb -dwarf-version=4 -O -disable-llvm-passes -emit-llvm -o - 
%s | FileCheck %s
+
+void t1();
+
+void use() { t1(); }
+
+__attribute__((nodebug)) void t1() {
+  int a = 10;
+  a++;
+}
+
+// CHECK-LABEL: define{{.*}} void @_Z3usev()
+// CHECK-SAME:  !dbg
+// CHECK-SAME:  {
+// CHECK:   !dbg
+// CHECK:   }
+
+// PR50767 Function __attribute__((nodebug)) inconsistency causes crash
+// illegal (non-distinct) !dbg metadata was being added to _Z2t1v definition
+
+// CHECK-LABEL: define{{.*}} void @_Z2t1v()
+// CHECK-NOT:   !dbg
+// CHECK-SAME:  {
+// CHECK-NOT:   !dbg
+// CHECK:   }
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1300,8 +1300,14 @@
   QualType ResTy = BuildFunctionArgList(GD, Args);
 
   // Check if we should generate debug info for this function.
-  if (FD->hasAttr())
-DebugInfo = nullptr; // disable debug info indefinitely for this function
+  if (FD->hasAttr()) {
+// Clear non-distinct debug info that was possibly attached to the function
+// due to an earlier declaration without the nodebug attribute
+if (Fn)
+  Fn->setSubprogram(nullptr);
+// Disable debug info indefinitely for this function
+DebugInfo = nullptr;
+  }
 
   // The function might not have a body if we're generating thunks for a
   // function declaration.


Index: clang/test/CodeGen/attr-nodebug2.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-nodebug2.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -debug-info-kind=limited -debugger-tuning=gdb -dwarf-version=4 -O -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
+
+void t1();
+
+void use() { t1(); }
+
+__attribute__((nodebug)) void t1() {
+  int a = 10;
+  a++;
+}
+
+// CHECK-LABEL: define{{.*}} void @_Z3usev()
+// CHECK-SAME:  !dbg
+// CHECK-SAME:  {
+// CHECK:   !dbg
+// CHECK:   }
+
+// PR50767 Function __attribute__((nodebug)) inconsistency causes crash
+// illegal (non-distinct) !dbg metadata was being added to _Z2t1v definition
+
+// CHECK-LABEL: define{{.*}} void @_Z2t1v()
+// CHECK-NOT:   !dbg
+// CHECK-SAME:  {
+// CHECK-NOT:   !dbg
+// CHECK:   }
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1300,8 +1300,14 @@
   QualType ResTy = BuildFunctionArgList(GD, Args);
 
   // Check if we should generate debug info for this function.
-  if (FD->hasAttr())
-DebugInfo = nullptr; // disable debug info indefinitely for this function
+  if (FD->hasAttr()) {
+// Clear non-distinct debug info that was possibly attached to the function
+// due to an earlier declaration without the nodebug attribute
+if (Fn)
+  Fn->setSubprogram(nullptr);
+// Disable debug info indefinitely for this function
+DebugInfo = nullptr;
+  }
 
   // The function might not have a body if we're generating thunks for a
   // function declaration.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104117: [clangd] Fix highlighting for implicit ObjC property refs

2021-06-23 Thread David Goldman via Phabricator via cfe-commits
dgoldman added a comment.

In D104117#2835599 , @sammccall wrote:

> Drive by from vacation, sorry - can this be tackled "upstream" in 
> findExplicitReferences rather than special cased in syntax highlighting?
>
> That would help with xrefs, rename etc. Features should really be only 
> handled here if they're somehow not a simple token->decl reference, but this 
> seems to be.

There's a couple of problems with that at the moment:

- Currently all ObjC method handling is done here since ObjC has selectors 
which need to be special cased
- FindExplicitRefs right now resolves these down to their ObjCMethodDecls, 
losing syntactic information that they were referenced by property expressions 
and not method expressions. We'd have to store that somehow to note these as 
`Field` and not `Method`.




Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:579
+  return true;
+// A single property expr can reference both a getter and setter, but we 
can
+// only provide a single semantic token, so prefer the getter.

kadircet wrote:
> is there any difference to using one or the other ? (i.e. can setter be 
> static while getter isn't? I suppose not). maybe mention that in the comment 
> and say that we are choosing whichever exists (and change the logic below to 
> `if` followed by an `else if`?
Not like that - but it's technically possible you could have a getter in an SDK 
and a user-provided setter for it (but that would be really weird); both of 
them can exist.



Comment at: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp:699
 @property(nonatomic, assign) int $Field_decl[[someProperty]];
+@property(readonly, class) $Class[[Foo]] 
*$Field_decl_readonly_static[[sharedInstance]];
 @end

kadircet wrote:
> we have an explicit `@property` here, but comments in the implementation says 
> otherwise. did you mean not having any explicit `getter/setter` or 
> `@synthesize` statement ?
After some testing it seems like property refs to class properties always use 
the implicit form like `ObjCPropertyRefExpr 0x7f87cb8116f0  
'' lvalue objcproperty Kind=MethodRef 
Getter="sharedInstance" Setter="(null)" Messaging=Getter` 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104117

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


[clang] a0d05ed - Handle interactions between reserved identifier and user-defined suffixes

2021-06-23 Thread via cfe-commits

Author: serge-sans-paille
Date: 2021-06-23T15:38:42+02:00
New Revision: a0d05ed848990c06c6dcdfc2e37bc8f13f7fe470

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

LOG: Handle interactions between reserved identifier and user-defined suffixes

According to https://eel.is/c++draft/over.literal

> double operator""_Bq(long double);  // OK: does not use the reserved 
> identifier _­Bq ([lex.name])
> double operator"" _Bq(long double); // ill-formed, no diagnostic required: 
> uses the reserved identifier _­Bq ([lex.name])

Obey that rule by keeping track of the operator literal name status wrt. 
leading whitespace.

Fix: https://bugs.llvm.org/show_bug.cgi?id=50644

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

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/AST/Decl.cpp
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/Sema/reserved-identifier.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index db389922ae3a1..5a9ed8519e765 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4122,7 +4122,8 @@ class Sema final {
 bool RValueThis, unsigned ThisQuals);
   CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class);
 
-  bool checkLiteralOperatorId(const CXXScopeSpec &SS, const UnqualifiedId &Id);
+  bool checkLiteralOperatorId(const CXXScopeSpec &SS, const UnqualifiedId &Id,
+  bool IsUDSuffix);
   LiteralOperatorLookupResult
   LookupLiteralOperator(Scope *S, LookupResult &R, ArrayRef ArgTys,
 bool AllowRaw, bool AllowTemplate,

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 0fbe8ec161910..5047dc19b0c6f 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -1081,10 +1081,9 @@ bool NamedDecl::isLinkageValid() const {
 ReservedIdentifierStatus
 NamedDecl::isReserved(const LangOptions &LangOpts) const {
   const IdentifierInfo *II = getIdentifier();
-  if (!II)
-if (const auto *FD = dyn_cast(this))
-  II = FD->getLiteralIdentifier();
 
+  // This triggers at least for CXXLiteralIdentifiers, which we already checked
+  // at lexing time.
   if (!II)
 return ReservedIdentifierStatus::NotReserved;
 

diff  --git a/clang/lib/Parse/ParseExprCXX.cpp 
b/clang/lib/Parse/ParseExprCXX.cpp
index 93f578edc09e6..f3d10b4a08895 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -9,7 +9,6 @@
 // This file implements the Expression parsing implementation for C++.
 //
 
//===--===//
-#include "clang/Parse/Parser.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclTemplate.h"
@@ -17,6 +16,7 @@
 #include "clang/Basic/PrettyStackTrace.h"
 #include "clang/Lex/LiteralSupport.h"
 #include "clang/Parse/ParseDiagnostic.h"
+#include "clang/Parse/Parser.h"
 #include "clang/Parse/RAIIObjectsForParser.h"
 #include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/ParsedTemplate.h"
@@ -2636,9 +2636,10 @@ bool Parser::ParseUnqualifiedIdOperator(CXXScopeSpec 
&SS, bool EnteringContext,
 
 // Grab the literal operator's suffix, which will be either the next token
 // or a ud-suffix from the string literal.
+bool IsUDSuffix = !Literal.getUDSuffix().empty();
 IdentifierInfo *II = nullptr;
 SourceLocation SuffixLoc;
-if (!Literal.getUDSuffix().empty()) {
+if (IsUDSuffix) {
   II = &PP.getIdentifierTable().get(Literal.getUDSuffix());
   SuffixLoc =
 Lexer::AdvanceToTokenCharacter(TokLocs[Literal.getUDSuffixToken()],
@@ -2675,7 +2676,7 @@ bool Parser::ParseUnqualifiedIdOperator(CXXScopeSpec &SS, 
bool EnteringContext,
 
 Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc);
 
-return Actions.checkLiteralOperatorId(SS, Result);
+return Actions.checkLiteralOperatorId(SS, Result, IsUDSuffix);
   }
 
   // Parse a conversion-function-id.

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index a57c5ad198e1b..b0b6b3dca5f6a 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -484,8 +484,25 @@ ParsedType Sema::getDestructorTypeForDecltype(const 
DeclSpec &DS,
 }
 
 bool Sema::checkLiteralOperatorId(const CXXScopeSpec &SS,
-  const UnqualifiedId &Name) {
+  const UnqualifiedId &Name, bool IsUDSuffix) {
   assert(Name.getKind() == UnqualifiedIdKind::IK_LiteralOperatorId);
+  if (!IsUDSuffix) {
+// [over.literal] p8
+//
+// double operator""_Bq(long double);  // OK: not a reserved identifier
+// double operator"" _Bq

[PATCH] D104299: Handle interactions between reserved identifier and user-defined suffixes

2021-06-23 Thread serge via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
serge-sans-paille marked 2 inline comments as done.
Closed by commit rGa0d05ed84899: Handle interactions between reserved 
identifier and user-defined suffixes (authored by serge-sans-paille).

Changed prior to commit:
  https://reviews.llvm.org/D104299?vs=352938&id=353952#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104299

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/Sema/reserved-identifier.cpp

Index: clang/test/Sema/reserved-identifier.cpp
===
--- clang/test/Sema/reserved-identifier.cpp
+++ clang/test/Sema/reserved-identifier.cpp
@@ -76,11 +76,19 @@
 int _barbatruc; // no-warning
 }
 
-long double operator"" _BarbeBleue(long double) // expected-warning {{identifier 'operator""_BarbeBleue' is reserved because it starts with '_' followed by a capital letter}}
+long double operator"" _BarbeBleue(long double) // expected-warning {{identifier '_BarbeBleue' is reserved because it starts with '_' followed by a capital letter}}
 {
   return 0.;
 }
 
+long double operator""_SacreBleu(long double) // no-warning
+{
+  return 0.;
+}
+
+long double sacrebleu = operator"" _SacreBleu(1.2); // expected-warning {{identifier '_SacreBleu' is reserved because it starts with '_' followed by a capital letter}}
+long double sangbleu = operator""_SacreBleu(1.2);   // no-warning
+
 struct _BarbeRouge { // expected-warning {{identifier '_BarbeRouge' is reserved because it starts with '_' followed by a capital letter}}
 } p;
 struct _BarbeNoire { // expected-warning {{identifier '_BarbeNoire' is reserved because it starts with '_' followed by a capital letter}}
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -484,8 +484,25 @@
 }
 
 bool Sema::checkLiteralOperatorId(const CXXScopeSpec &SS,
-  const UnqualifiedId &Name) {
+  const UnqualifiedId &Name, bool IsUDSuffix) {
   assert(Name.getKind() == UnqualifiedIdKind::IK_LiteralOperatorId);
+  if (!IsUDSuffix) {
+// [over.literal] p8
+//
+// double operator""_Bq(long double);  // OK: not a reserved identifier
+// double operator"" _Bq(long double); // ill-formed, no diagnostic required
+IdentifierInfo *II = Name.Identifier;
+ReservedIdentifierStatus Status = II->isReserved(PP.getLangOpts());
+SourceLocation Loc = Name.getEndLoc();
+if (Status != ReservedIdentifierStatus::NotReserved &&
+!PP.getSourceManager().isInSystemHeader(Loc)) {
+  Diag(Loc, diag::warn_reserved_extern_symbol)
+  << II << static_cast(Status)
+  << FixItHint::CreateReplacement(
+ Name.getSourceRange(),
+ (StringRef("operator\"\"") + II->getName()).str());
+}
+  }
 
   if (!SS.isValid())
 return false;
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -9,7 +9,6 @@
 // This file implements the Expression parsing implementation for C++.
 //
 //===--===//
-#include "clang/Parse/Parser.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclTemplate.h"
@@ -17,6 +16,7 @@
 #include "clang/Basic/PrettyStackTrace.h"
 #include "clang/Lex/LiteralSupport.h"
 #include "clang/Parse/ParseDiagnostic.h"
+#include "clang/Parse/Parser.h"
 #include "clang/Parse/RAIIObjectsForParser.h"
 #include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/ParsedTemplate.h"
@@ -2636,9 +2636,10 @@
 
 // Grab the literal operator's suffix, which will be either the next token
 // or a ud-suffix from the string literal.
+bool IsUDSuffix = !Literal.getUDSuffix().empty();
 IdentifierInfo *II = nullptr;
 SourceLocation SuffixLoc;
-if (!Literal.getUDSuffix().empty()) {
+if (IsUDSuffix) {
   II = &PP.getIdentifierTable().get(Literal.getUDSuffix());
   SuffixLoc =
 Lexer::AdvanceToTokenCharacter(TokLocs[Literal.getUDSuffixToken()],
@@ -2675,7 +2676,7 @@
 
 Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc);
 
-return Actions.checkLiteralOperatorId(SS, Result);
+return Actions.checkLiteralOperatorId(SS, Result, IsUDSuffix);
   }
 
   // Parse a conversion-function-id.
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1081,10 +1081,9 @@
 ReservedIdentifierStatus
 NamedDecl::isReserved(const La

[PATCH] D104677: [OpenMP][AMDGCN] Apply fix for isnan, isinf and isfinite for amdgcn.

2021-06-23 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/test/Headers/hip-header.hip:21
+// RUN:   -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -o - \
+// RUN:   -D__HIPCC_RTC__ -DUSE_ISNAN_WITH_INT_RETURN | FileCheck %s 
-check-prefixes=AMD_INT_RETURN
+// RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h \

where is this macro used and how does it affect HIP? Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104677

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


[PATCH] D104714: [UpdateCCTestChecks] Support --check-globals

2021-06-23 Thread Giorgis Georgakoudis via Phabricator via cfe-commits
ggeorgakoudis added a comment.

LGMT too!


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

https://reviews.llvm.org/D104714

___
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-06-23 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D103131#2835702 , @kamleshbhalui 
wrote:

> Here is what we get when we replace int with float.
>
>   $lldb-11 ./a.out 
>   (lldb) target create "./a.out"
>   Current executable set to 
> '/folk/kkumar/tcllvm/llvm-build-lldb-rel/bin/a.out' (x86_64).
>   (lldb) b main
>   Breakpoint 1: where = a.out`main + 4 at test.c:3:12, address = 
> 0x00400484
>   (lldb) p oldname
>   (float) $0 = 1
>   (lldb) p newname
>   (void *) $1 = 0x3f80

Yep, looks like it's ignoring the imported declaration in favor of the raw 
symbol table entry.

How's lldb handle GCC-style debug info (the variable declaration, without any 
imported declaration) for the alias?


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] D93525: [clang-offload-bundler] Add unbundling of archives containing bundled object files into device specific archives

2021-06-23 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:7619
 if (CurKind == Action::OFK_HIP && CurDep->getOffloadingArch()) {
-  Triples += '-';
+  Triples += "--";
   Triples += CurDep->getOffloadingArch();

This is not HIP specific. Other toolchain could use a non-canonical triple too. 
Also there may be more components of triple missing. A generic fix would be use 
Triple::normalize  for all toolchain. same as below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93525

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


[PATCH] D104677: [OpenMP][AMDGCN] Apply fix for isnan, isinf and isfinite for amdgcn.

2021-06-23 Thread Ethan Stewart via Phabricator via cfe-commits
estewart08 added inline comments.



Comment at: clang/test/Headers/hip-header.hip:21
+// RUN:   -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -o - \
+// RUN:   -D__HIPCC_RTC__ -DUSE_ISNAN_WITH_INT_RETURN | FileCheck %s 
-check-prefixes=AMD_INT_RETURN
+// RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h \

yaxunl wrote:
> where is this macro used and how does it affect HIP? Thanks.
https://github.com/ROCm-Developer-Tools/llvm-project/blob/main/clang/test/Headers/Inputs/include/cmath#L85

For testing purposes we can enable certain return types for isnan.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104677

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


[PATCH] D104677: [OpenMP][AMDGCN] Apply fix for isnan, isinf and isfinite for amdgcn.

2021-06-23 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104677

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


[PATCH] D104677: [OpenMP][AMDGCN] Apply fix for isnan, isinf and isfinite for amdgcn.

2021-06-23 Thread Jon Chesterfield via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5dfdc1812d9b: [OpenMP][AMDGCN] Apply fix for isnan, isinf 
and isfinite for amdgcn. (authored by estewart08, committed by JonChesterfield).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104677

Files:
  clang/lib/Headers/__clang_hip_cmath.h
  clang/test/Headers/hip-header.hip
  clang/test/Headers/openmp_device_math_isnan.cpp

Index: clang/test/Headers/openmp_device_math_isnan.cpp
===
--- clang/test/Headers/openmp_device_math_isnan.cpp
+++ clang/test/Headers/openmp_device_math_isnan.cpp
@@ -1,11 +1,19 @@
 // RUN: %clang_cc1 -x c++ -internal-isystem %S/Inputs/include -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -x c++ -internal-isystem %S/Inputs/include -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host.bc
 // RUN: %clang_cc1 -x c++ -include __clang_openmp_device_functions.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix=BOOL_RETURN
+// RUN: %clang_cc1 -x c++ -include __clang_openmp_device_functions.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -fopenmp -triple amdgcn-amd-amdhsa -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix=AMD_BOOL_RETURN
 // RUN: %clang_cc1 -x c++ -internal-isystem %S/Inputs/include -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc -ffast-math -ffp-contract=fast
+// RUN: %clang_cc1 -x c++ -internal-isystem %S/Inputs/include -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host.bc -ffast-math -ffp-contract=fast
 // RUN: %clang_cc1 -x c++ -include __clang_openmp_device_functions.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - -ffast-math -ffp-contract=fast | FileCheck %s --check-prefix=BOOL_RETURN
+// RUN: %clang_cc1 -x c++ -include __clang_openmp_device_functions.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -fopenmp -triple amdgcn-amd-amdhsa -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - -ffast-math -ffp-contract=fast | FileCheck %s --check-prefix=AMD_BOOL_RETURN
 // RUN: %clang_cc1 -x c++ -internal-isystem %S/Inputs/include -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc -DUSE_ISNAN_WITH_INT_RETURN
+// RUN: %clang_cc1 -x c++ -internal-isystem %S/Inputs/include -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host.bc -DUSE_ISNAN_WITH_INT_RETURN
 // RUN: %clang_cc1 -x c++ -include __clang_openmp_device_functions.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - -DUSE_ISNAN_WITH_INT_RETURN | FileCheck %s --check-prefix=INT_RETURN
+// RUN: %clang_cc1 -x c++ -include __clang_openmp_device_functions.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -fopenmp -triple amdgcn-amd-amdhsa -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - -DUSE_ISNAN_WITH_INT_RETURN | FileCheck %s --check-prefix=AMD_INT_RETURN
 // RUN: %clang_cc1 -x c++ -internal-isystem %S/Inputs/include -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc -ffast-math -ffp-contract=fast -DUSE_ISNAN_WITH_INT_RETURN
+// RUN: %clang_cc1 -x c++ -internal-isystem %S/Inputs/include -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host.bc -ffast-math -ffp-contract=fast -DUSE_ISNAN_WITH_INT_RETURN
 // RUN: %clang_cc1 -x c++ -include __clang_openmp_device_functions.h -internal-

[clang] 5dfdc18 - [OpenMP][AMDGCN] Apply fix for isnan, isinf and isfinite for amdgcn.

2021-06-23 Thread Jon Chesterfield via cfe-commits

Author: Ethan Stewart
Date: 2021-06-23T15:26:09+01:00
New Revision: 5dfdc1812d9b9c043204d39318f6446424d8f2d7

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

LOG: [OpenMP][AMDGCN] Apply fix for isnan, isinf and isfinite for amdgcn.

This fixes issues with various return types(bool/int) and was already
in place for nvptx headers, adjusted to work for amdgcn. This does
not affect hip as the change is guarded with OPENMP_AMDGCN.
Similar to D85879.

Reviewed By: jdoerfert, JonChesterfield, yaxunl

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

Added: 


Modified: 
clang/lib/Headers/__clang_hip_cmath.h
clang/test/Headers/hip-header.hip
clang/test/Headers/openmp_device_math_isnan.cpp

Removed: 




diff  --git a/clang/lib/Headers/__clang_hip_cmath.h 
b/clang/lib/Headers/__clang_hip_cmath.h
index b5d7c16ac5e41..7342705434e6b 100644
--- a/clang/lib/Headers/__clang_hip_cmath.h
+++ b/clang/lib/Headers/__clang_hip_cmath.h
@@ -52,8 +52,46 @@ __DEVICE__ int fpclassify(double __x) {
 __DEVICE__ float frexp(float __arg, int *__exp) {
   return ::frexpf(__arg, __exp);
 }
+
+#if defined(__OPENMP_AMDGCN__)
+// For OpenMP we work around some old system headers that have non-conforming
+// `isinf(float)` and `isnan(float)` implementations that return an `int`. We 
do
+// this by providing two versions of these functions, 
diff ering only in the
+// return type. To avoid conflicting definitions we disable implicit base
+// function generation. That means we will end up with two specializations, one
+// per type, but only one has a base function defined by the system header.
+#pragma omp begin declare variant match(   
\
+implementation = {extension(disable_implicit_base)})
+
+// FIXME: We lack an extension to customize the mangling of the variants, e.g.,
+//add a suffix. This means we would clash with the names of the 
variants
+//(note that we do not create implicit base functions here). To avoid
+//this clash we add a new trait to some of them that is always true
+//(this is LLVM after all ;)). It will only influence the mangled name
+//of the variants inside the inner region and avoid the clash.
+#pragma omp begin declare variant match(implementation = {vendor(llvm)})
+
+__DEVICE__ int isinf(float __x) { return ::__isinff(__x); }
+__DEVICE__ int isinf(double __x) { return ::__isinf(__x); }
+__DEVICE__ int isfinite(float __x) { return ::__finitef(__x); }
+__DEVICE__ int isfinite(double __x) { return ::__finite(__x); }
+__DEVICE__ int isnan(float __x) { return ::__isnanf(__x); }
+__DEVICE__ int isnan(double __x) { return ::__isnan(__x); }
+
+#pragma omp end declare variant
+#endif // defined(__OPENMP_AMDGCN__)
+
+__DEVICE__ bool isinf(float __x) { return ::__isinff(__x); }
+__DEVICE__ bool isinf(double __x) { return ::__isinf(__x); }
 __DEVICE__ bool isfinite(float __x) { return ::__finitef(__x); }
 __DEVICE__ bool isfinite(double __x) { return ::__finite(__x); }
+__DEVICE__ bool isnan(float __x) { return ::__isnanf(__x); }
+__DEVICE__ bool isnan(double __x) { return ::__isnan(__x); }
+
+#if defined(__OPENMP_AMDGCN__)
+#pragma omp end declare variant
+#endif // defined(__OPENMP_AMDGCN__)
+
 __DEVICE__ bool isgreater(float __x, float __y) {
   return __builtin_isgreater(__x, __y);
 }
@@ -66,8 +104,6 @@ __DEVICE__ bool isgreaterequal(float __x, float __y) {
 __DEVICE__ bool isgreaterequal(double __x, double __y) {
   return __builtin_isgreaterequal(__x, __y);
 }
-__DEVICE__ bool isinf(float __x) { return ::__isinff(__x); }
-__DEVICE__ bool isinf(double __x) { return ::__isinf(__x); }
 __DEVICE__ bool isless(float __x, float __y) {
   return __builtin_isless(__x, __y);
 }
@@ -86,8 +122,6 @@ __DEVICE__ bool islessgreater(float __x, float __y) {
 __DEVICE__ bool islessgreater(double __x, double __y) {
   return __builtin_islessgreater(__x, __y);
 }
-__DEVICE__ bool isnan(float __x) { return ::__isnanf(__x); }
-__DEVICE__ bool isnan(double __x) { return ::__isnan(__x); }
 __DEVICE__ bool isnormal(float __x) { return __builtin_isnormal(__x); }
 __DEVICE__ bool isnormal(double __x) { return __builtin_isnormal(__x); }
 __DEVICE__ bool isunordered(float __x, float __y) {

diff  --git a/clang/test/Headers/hip-header.hip 
b/clang/test/Headers/hip-header.hip
index 5bba1de2ce6c4..0e95d58d55700 100644
--- a/clang/test/Headers/hip-header.hip
+++ b/clang/test/Headers/hip-header.hip
@@ -8,6 +8,20 @@
 // RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h \
 // RUN:   -internal-isystem %S/../../lib/Headers/cuda_wrappers \
 // RUN:   -internal-isystem %S/Inputs/include \
+// RUN:   -include cmath \
+// RUN:   -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
+// RUN:   -target-cpu gfx906 -emit-llvm %s -f

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

2021-06-23 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 353954.
ASDenysPetrov added a comment.

Made changes according to comments. Optimized `castTo` function for each cast 
case. Simplified unit test.


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

https://reviews.llvm.org/D103094

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h
  
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
@@ -40,12 +40,18 @@
   const Range &R) {
   return OS << toString(R);
 }
+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();
@@ -53,7 +59,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;
@@ -61,6 +67,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 {
@@ -74,25 +108,30 @@
   // End init block
 
   using Self = RangeSetTest;
-  using RawRange = std::pair;
-  using RawRangeSet = std::initializer_list;
-
-  const llvm::APSInt &from(BaseType X) {
-static llvm::APSInt Base{sizeof(BaseType) * 8,
- std::is_unsigned::value};
-Base = X;
-return BVF.getValue(Base);
+  template  using RawRangeT = std::pair;
+  template 
+  using RawRangeSetT = std::initializer_list>;
+  using RawRange = RawRangeT;
+  using RawRangeSet = RawRangeSetT;
+  template 
+  static constexpr APSIntType APSIntTy = APSIntType(sizeof(T) * 8,
+!is_signed_v);
+
+  template  const llvm::APSInt &from(T X) {
+static llvm::APSInt Int = APSIntTy.getZeroValue();
+Int = X;
+return BVF.getValue(Int);
   }
 
-  Range from(const RawRange &Init) {
+  template  Range from(const RawRangeT &Init) {
 return Range(from(Init.first), from(Init.second));
   }
 
-  RangeSet from(const RawRangeSet &Init) {
+  template 
+  RangeSet from(RawRangeSetT Init, APSIntType Ty = APSIntTy) {
 RangeSet RangeSet = F.getEmptySet();
-for (const auto &Raw : Init) {
+for (const auto &Raw : Init)
   RangeSet = F.add(RangeSet, from(Raw));
-}
 return RangeSet;
   }
 
@@ -211,9 +250,20 @@
RawRangeSet RawExpected) {
 wrap(&Self::checkDeleteImpl, Point, RawFrom, RawExpected);
   }
-};
 
-} // namespace
+  void checkCastToImpl(RangeSet What, APSIntType Ty, RangeSet Expected) {
+RangeSet Result = F.castTo(What, Ty);
+EXPECT_EQ(Result, Expected)
+<< "while casting " << toString(What) << " to " << Ty;
+  }
+
+  template 
+  void checkCastTo(RawRangeSetT What, RawRangeSetT Expected) {
+static constexpr APSIntT

[PATCH] D104777: PR50767: clear non-distinct debuginfo for function with nodebug definition after undecorated declaration

2021-06-23 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a subscriber: aaron.ballman.
dblaikie added a comment.

@aaron.ballman Do we have attributes/infrastructure for attributes that have to 
be the same from their first declaration or at least from their first call? I'm 
wondering if it might be simpler/better to require nodebug to be provided 
earlier, rather than fixing it up after the fact like this.

(for instance, requiring it to be attributed on the declaration would ensure we 
don't create call_site descriptions for calls to nodebug functions - which 
would save some debug info size)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104777

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


[PATCH] D98710: [clang-tidy] Add --skip-headers, part 1 (use setTraversalScope)

2021-06-23 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:148
+/// Check if a Decl should be skipped.
+std::shared_ptr Filter;
   };

chh wrote:
> sammccall wrote:
> > I don't think the filter belongs here.
> > The design of traversal scope is that it's a property of the AST that 
> > affects all traversals, so it shouldn't be a configuration property of 
> > particular traversals like ASTMatchFinder.
> > 
> > There's a question of what to do about `MatchFinder::newASTConsumer()`, 
> > which runs the finder immediately after an AST is created, and so covers 
> > the point at which we might set a scope. There are several good options, 
> > e.g.:
> >  - Don't provide any facility for setting traversal scope when 
> > newASTConsumer() is used - it's not commonly needed, and the ASTConsumer is 
> > trivial to reimplement where that's actually needed
> >  - Accept an optional `function` which should run just 
> > before matching starts
> > 
> > This seems a bit subtle, but the difference between having this in 
> > MatchFinder proper vs just in newASTConsumer() is important I think, 
> > precisely because it's common to run the matchers directly on an existing 
> > AST.
> > 
> I have some similar concerns too.
> 
> clangd calls MatchFinder::matchAST explicitly after setTraversalScope,
> but clang-tidy uses MultiplexConsumer and MatchFinder::newASTConsumer
> is just one of the two consumers.
> (1) I am not sure if it would be safe or even work to make big changes in
> ClangTidy.cpp's CreateASTConsumer to call MatchFinder::matchAST explicitly.
> (2) Similarly, I wonder if setTraversalScope will work for both MatchFinder
> and other consumers in the same MultiplexConsumer.
> 
> Could you check if my current change to MatchFinder::HandleTranslationUnit
> is right, especially in the saving/restoring of traversal scope?
> 
> I am assuming that each consumer in a MultiplexConsumer will have its own
> chance to HandleTranslationUnit and HandleTopLevelDecl.
> If that's correct, it seems to me that changing those two handlers in
> MatchFinder is right for clang-tidy. Then they will need the optional
> MatchFinder::MatchFinderOptions::DeclFilter.
> 
> 
> but clang-tidy uses MultiplexConsumer and MatchFinder::newASTConsumer is just 
> one of the two consumers.

Yeah, `MultiplexConsumer` is a separate interface in clang, and I don't think 
we have a strong reason to modify it. 

However, we could refine the bit in clang-tidy -- clang-tidy uses 
`MultiplexConsumer` to dispatch all events to two consumers: the MatcherFinder, 
the clang's static analyzer, we can get rid of the `MultiplexConsumer` by 
implementing a new ASTConsumer, so that we have enough flexibility to affect 
all traversals without touching all clang areas, so the API will look like

```
class ClangTidyASTConsumer : public ASTConsumer {

public:
  void HandleTopLevelDecl(...) override {
 // collect all main file decl
  }
  void HandleTranslationUnit(ASTContext &Context) override {
// set traversal scope.
MatcherFinderConsumer->HandleTranslationUnit(Context);
StaticAnalyzer->HandleTranslationUnit(Context);
  }
  
  // implement other necessary Handle* overrides, and dispatch to 
StaticAnalyzer consumers;

private:
  std::unique_ptr MatcherFinderConsumer;
  std::unique_ptr<...> StaticAnalyzer;
  ... MainFileDecl;
}; 
``` 


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

https://reviews.llvm.org/D98710

___
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-06-23 Thread kamlesh kumar via Phabricator via cfe-commits
kamleshbhalui added a comment.

In D103131#2835909 , @dblaikie wrote:

> In D103131#2835702 , @kamleshbhalui 
> wrote:
>
>> Here is what we get when we replace int with float.
>>
>>   $lldb-11 ./a.out 
>>   (lldb) target create "./a.out"
>>   Current executable set to 
>> '/folk/kkumar/tcllvm/llvm-build-lldb-rel/bin/a.out' (x86_64).
>>   (lldb) b main
>>   Breakpoint 1: where = a.out`main + 4 at test.c:3:12, address = 
>> 0x00400484
>>   (lldb) p oldname
>>   (float) $0 = 1
>>   (lldb) p newname
>>   (void *) $1 = 0x3f80
>
> Yep, looks like it's ignoring the imported declaration in favor of the raw 
> symbol table entry.
>
> How's lldb handle GCC-style debug info (the variable declaration, without any 
> imported declaration) for the alias?

lldb's behavior is same even with GCC -style debug info.


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] D104198: [Matrix] Add documentation for compound assignment and type conversion of matrix types

2021-06-23 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 353970.
SaurabhJha added a comment.
Herald added a project: clang-tools-extra.

Did a --amend to rebuild


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104198

Files:
  clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,64 @@
 return a + b * c;
   }
 
+The matrix type extension also supports operations between a matrix and a 
scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+  return (a + 23) * 12;
+  }
+
+The matrix type extension supports division between a matrix and a scalar but 
not between a matrix and a matrix.
+
+.. code-block:: c++
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+a = a / 3.0;
+return a;
+  }
+
+The matrix type extension supports compound assignments for addition, 
subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+a += b;
+a -= b;
+a *= b;
+a += 23;
+a -= 12;
+return a;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are 
C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+return (fx5x5) i;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =
Index: clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp
===
--- clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp
+++ clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp
@@ -80,7 +80,7 @@
 
   auto &FileMgr = Tool.getFiles();
   SourceManager Sources(Diagnostics, FileMgr);
-  Rewriter Rewrite(Sources, DefaultLangOptions);
+  Rewriter Rewrite(Sources, DefaultLangOptions); // TODO: Ally Donaldson
   Tool.applyAllReplacements(Rewrite);
 
   for (const auto &File : Files) {


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,64 @@
 return a + b * c;
   }
 
+The matrix type extension also supports operations between a matrix and a scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+  return (a + 23) * 12;
+  }
+
+The matrix type extension supports division between a matrix and a scalar but not between a matrix and a matrix.
+
+.. code-block:: c++
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+a = a / 3.0;
+return a;
+  }
+
+The matrix type extension supports compound assignments for addition, subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+a += b;
+a -= b;
+a *= b;
+a += 23;
+a -= 12;
+return a;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+return (fx5x5) i;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =
Index: clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp
===
--- clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp
+++ clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp
@@ -80,7 +80,7 @@
 
   auto &FileMgr = Tool.getFiles();
   SourceManager Sources(Diagnostics, FileMgr);
-  Rewriter Rewrite(Sources, DefaultLangOptions);
+  Rewriter Rewrite(So

[PATCH] D69560: [clang-tidy] Add 'bugprone-easily-swappable-parameters' check

2021-06-23 Thread Whisperity via Phabricator via cfe-commits
whisperity updated this revision to Diff 353969.
whisperity marked 8 inline comments as done.
whisperity added a comment.

All changes are **NFC** and styling only.

- Remove the `FB` macro in favour of explicitly specifying the bit flag value
- Change debug printout from bit pattern to individual significant letters


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69560

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-easily-swappable-parameters.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-ignore.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len3.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c
@@ -0,0 +1,148 @@
+// RUN: %check_clang_tidy %s bugprone-easily-swappable-parameters %t \
+// RUN:   -config='{CheckOptions: [ \
+// RUN: {key: bugprone-easily-swappable-parameters.MinimumLength, value: 2}, \
+// RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterNames, value: ""}, \
+// RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes, value: "bool;MyBool;struct U;MAKE_LOGICAL_TYPE(int)"} \
+// RUN:  ]}' -- -x c
+
+#define bool _Bool
+#define true 1
+#define false 0
+
+typedef bool MyBool;
+
+#define TheLogicalType bool
+
+void declVoid(void); // NO-WARN: Declaration only.
+void decl(); // NO-WARN: Declaration only.
+void oneParam(int I) {}  // NO-WARN: 1 parameter.
+void variadic(int I, ...) {} // NO-WARN: 1 visible parameter.
+
+void trivial(int I, int J) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: 2 adjacent parameters of 'trivial' of similar type ('int') are easily swapped by mistake [bugprone-easily-swappable-parameters]
+// CHECK-MESSAGES: :[[@LINE-2]]:18: note: the first parameter in the range is 'I'
+// CHECK-MESSAGES: :[[@LINE-3]]:25: note: the last parameter in the range is 'J'
+
+void qualifier(int I, const int CI) {} // NO-WARN: Distinct types.
+
+void restrictQualifier(char *restrict CPR1, char *restrict CPR2) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: 2 adjacent parameters of 'restrictQualifier' of similar type ('char *restrict')
+// CHECK-MESSAGES: :[[@LINE-2]]:39: note: the first parameter in the range is 'CPR1'
+// CHECK-MESSAGES: :[[@LINE-3]]:60: note: the last parameter in the range is 'CPR2'
+
+void pointer1(int *IP1, int *IP2) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: 2 adjacent parameters of 'pointer1' of similar type ('int *')
+// CHECK-MESSAGES: :[[@LINE-2]]:20: note: the first parameter in the range is 'IP1'
+// CHECK-MESSAGES: :[[@LINE-3]]:30: note: the last parameter in the range is 'IP2'
+
+void pointerConversion(int *IP, long *LP) {}
+// NO-WARN: Even though C can convert any T* to U* back and forth, compiler
+// warnings already exist for this.
+
+void testVariadicsCall() {
+  int IVal = 1;
+  decl(IVal); // NO-WARN: Particular calls to "variadics" are like template
+  // instantiations, and we do not model them.
+
+  variadic(IVal);  // NO-WARN.
+  variadic(IVal, 2, 3, 4); // NO-WARN.
+}
+
+struct S {};
+struct T {};
+
+void taggedTypes1(struct S SVar, struct T TVar) {} // NO-WARN: Distinct types.
+
+void taggedTypes2(struct S SVar1, struct S SVar2) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 2 adjacent parameters of 'taggedTypes2' of similar type ('struct S')
+// CHECK-MESSAGES: :[[@LINE-2]]:28: note: the first parameter in the range is 'SVar1'
+// CHECK-MESSAGES: :[[@LINE-3]]:44: note: the last parameter in the range is 'SVar2'
+
+void wrappers(struct { int I; } I1, struct { int I; } I2) {} // NO-WARN: Distinct anonymous types.
+
+void knr(I, J)
+  int I;
+  int J;
+{}
+// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: 2 adjacent parameters of 'knr' of similar type ('int')
+// CHECK-MESSAGES: :[[@LINE-4]]:7: note: the first parameter in the range is 'I'
+// CHECK-MESSAGES: :[[@LINE-4]]:7: note: the last parameter in the range is 'J'
+
+void boolAsWritten(bool B1, bool B2) {} // NO-WARN: The type name is ignored.
+// Note that "bool" is a macro that expands to "_Bool" internally, but it is
+// only "bool" that is ignored from the two.
+
+void underscoreBoo

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

2021-06-23 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:297-307
+bool clang::ento::RangeSet::isUnsigned() const {
+  return begin()->From().isUnsigned();
+}
+
+uint32_t clang::ento::RangeSet::getBitWidth() const {
+  return begin()->From().getBitWidth();
+}

We should add `assert(!isEmpty());` in all three



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:645-676
+// CastRangeSize is an amount of all possible values of cast type.
+// Example: `char` has 256 values; `short` has 65536 values.
+// But in fact we use `amount of values` - 1, because
+// we can't keep `amount of values of UINT64` inside uint64_t.
+// E.g. 256 is an amount of all possible values of `char` and we can't keep
+// it inside `char`.
+// And it's OK, it's enough to do correct calculations.

Maybe we can extract this into something like `truncateTo` and the next `if` to 
`convertTo` private methods?



Comment at: clang/unittests/StaticAnalyzer/RangeSetTest.cpp:117-118
+  template 
+  static constexpr APSIntType APSIntTy = APSIntType(sizeof(T) * 8,
+!is_signed_v);
+

Great, that works too!



Comment at: clang/unittests/StaticAnalyzer/RangeSetTest.cpp:120
+
+  template  const llvm::APSInt &from(T X) {
+static llvm::APSInt Int = APSIntTy.getZeroValue();

Default to `BaseType`?



Comment at: clang/unittests/StaticAnalyzer/RangeSetTest.cpp:126
 
-  Range from(const RawRange &Init) {
+  template  Range from(const RawRangeT &Init) {
 return Range(from(Init.first), from(Init.second));

Default to `BaseType`?



Comment at: clang/unittests/StaticAnalyzer/RangeSetTest.cpp:130
 
-  RangeSet from(const RawRangeSet &Init) {
+  template 
+  RangeSet from(RawRangeSetT Init, APSIntType Ty = APSIntTy) {

Default to `BaseType`?



Comment at: clang/unittests/StaticAnalyzer/RangeSetTest.cpp:131
+  template 
+  RangeSet from(RawRangeSetT Init, APSIntType Ty = APSIntTy) {
 RangeSet RangeSet = F.getEmptySet();

Unused parameter?



Comment at: clang/unittests/StaticAnalyzer/RangeSetTest.cpp:721-799
+TYPED_TEST(RangeSetCastToNoopTest, RangeSetCastToNoopTest) {
+  // Just to reduce the verbosity.
+  using F = typename TypeParam::FromType; // From
+  using T = typename TypeParam::ToType;   // To
+
+  using TV = TestValues;
+  constexpr auto MIN = TV::MIN;

If loop and promotion share the same test case, why should we split them into 
two groups?


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

https://reviews.llvm.org/D103094

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


[PATCH] D104198: [Matrix] Add documentation for compound assignment and type conversion of matrix types

2021-06-23 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 353971.
SaurabhJha added a comment.

Removing mistakenly added files


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104198

Files:
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,64 @@
 return a + b * c;
   }
 
+The matrix type extension also supports operations between a matrix and a 
scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+  return (a + 23) * 12;
+  }
+
+The matrix type extension supports division between a matrix and a scalar but 
not between a matrix and a matrix.
+
+.. code-block:: c++
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+a = a / 3.0;
+return a;
+  }
+
+The matrix type extension supports compound assignments for addition, 
subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+a += b;
+a -= b;
+a *= b;
+a += 23;
+a -= 12;
+return a;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are 
C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+return (fx5x5) i;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,64 @@
 return a + b * c;
   }
 
+The matrix type extension also supports operations between a matrix and a scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+  return (a + 23) * 12;
+  }
+
+The matrix type extension supports division between a matrix and a scalar but not between a matrix and a matrix.
+
+.. code-block:: c++
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+a = a / 3.0;
+return a;
+  }
+
+The matrix type extension supports compound assignments for addition, subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+a += b;
+a -= b;
+a *= b;
+a += 23;
+a -= 12;
+return a;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+return (fx5x5) i;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95736: [clang-tidy] Extend 'bugprone-easily-swappable-parameters' with `typedef` and `const &` diagnostics

2021-06-23 Thread Whisperity via Phabricator via cfe-commits
whisperity updated this revision to Diff 353972.
whisperity added a comment.

**NFC**: Rebase & update.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95736

Files:
  clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-easily-swappable-parameters.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
@@ -111,20 +111,38 @@
 // CHECK-MESSAGES: :[[@LINE-2]]:32: note: the first parameter in the range is 'I1'
 // CHECK-MESSAGES: :[[@LINE-3]]:43: note: the last parameter in the range is 'I2'
 
-void throughTypedef(int I, MyInt1 J) {}
-// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: 2 adjacent parameters of 'throughTypedef' of similar type ('int')
-// CHECK-MESSAGES: :[[@LINE-2]]:25: note: the first parameter in the range is 'I'
-// CHECK-MESSAGES: :[[@LINE-3]]:35: note: the last parameter in the range is 'J'
+void typedefMultiple(MyInt1 I1, MyInt2 I2x, MyInt2 I2y) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 3 adjacent parameters of 'typedefMultiple' of similar type are
+// CHECK-MESSAGES: :[[@LINE-2]]:29: note: the first parameter in the range is 'I1'
+// CHECK-MESSAGES: :[[@LINE-3]]:52: note: the last parameter in the range is 'I2y'
+// CHECK-MESSAGES: :[[@LINE-4]]:22: note: after resolving type aliases, the common type of 'MyInt1' and 'MyInt2' is 'int'
+
+void throughTypedef1(int I, MyInt1 J) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 2 adjacent parameters of 'throughTypedef1' of similar type are
+// CHECK-MESSAGES: :[[@LINE-2]]:26: note: the first parameter in the range is 'I'
+// CHECK-MESSAGES: :[[@LINE-3]]:36: note: the last parameter in the range is 'J'
+// CHECK-MESSAGES: :[[@LINE-4]]:22: note: after resolving type aliases, 'int' and 'MyInt1' are the same
+
+void betweenTypedef2(MyInt1 I, MyInt2 J) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 2 adjacent parameters of 'betweenTypedef2' of similar type are
+// CHECK-MESSAGES: :[[@LINE-2]]:29: note: the first parameter in the range is 'I'
+// CHECK-MESSAGES: :[[@LINE-3]]:39: note: the last parameter in the range is 'J'
+// CHECK-MESSAGES: :[[@LINE-4]]:22: note: after resolving type aliases, the common type of 'MyInt1' and 'MyInt2' is 'int'
+
+typedef MyInt2 MyInt2b;
 
-void betweenTypedef(MyInt1 I, MyInt2 J) {}
-// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: 2 adjacent parameters of 'betweenTypedef' of similar type ('MyInt1')
-// CHECK-MESSAGES: :[[@LINE-2]]:28: note: the first parameter in the range is 'I'
-// CHECK-MESSAGES: :[[@LINE-3]]:38: note: the last parameter in the range is 'J'
+void typedefChain(int I, MyInt1 MI1, MyInt2 MI2, MyInt2b MI2b) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 4 adjacent parameters of 'typedefChain' of similar type are
+// CHECK-MESSAGES: :[[@LINE-2]]:23: note: the first parameter in the range is 'I'
+// CHECK-MESSAGES: :[[@LINE-3]]:58: note: the last parameter in the range is 'MI2b'
+// CHECK-MESSAGES: :[[@LINE-4]]:19: note: after resolving type aliases, 'int' and 'MyInt1' are the same
+// CHECK-MESSAGES: :[[@LINE-5]]:19: note: after resolving type aliases, 'int' and 'MyInt2' are the same
+// CHECK-MESSAGES: :[[@LINE-6]]:19: note: after resolving type aliases, 'int' and 'MyInt2b' are the same
 
 typedef long MyLong1;
 using MyLong2 = long;
 
-void throughTypedefToOtherType(MyInt1 I, MyLong1 J) {} // NO-WARN: Not the same type.
+void throughTypedefToOtherType(MyInt1 I, MyLong1 J) {} // NO-WARN: int and long.
 
 void qualified1(int I, const int CI) {} // NO-WARN: Not the same type.
 
@@ -138,18 +156,73 @@
 
 void qualifiedThroughTypedef1(int I, CInt CI) {} // NO-WARN: Not the same type.
 
-void qualifiedThroughTypedef2(CInt CI1, const int CI2) {} // NO-WARN: Not the same type.
-// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 2 adjacent parameters of 'qualifiedThroughTypedef2' of similar type ('CInt')
+void qualifiedThroughTypedef2(CInt CI1, const int CI2) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 2 adjacent parameters of 'qualifiedThroughTypedef2' of similar type are
 // CHECK-MESSAGES: :[[@LINE-2]]:36: note: the first parameter in the range is 'CI1'
 // CHECK-MESSAGES: :[[@LINE-3]]:51: note: the last parameter in the range is 'CI2'
-
-void reference1(int I, int &IR) {} // NO-WARN: Not the same type.
-
-void reference2(int I, const int &CIR) {} // NO-WARN: Not the same type.
-
-void reference3(int I, int &&IRR) {} // NO-WARN: Not the same type.
-
-void reference4(int I, const int &&CIRR) {} // NO-WARN: Not the same type.
+// CHECK-MESSAGES: :[[@LINE-4]]:31: note: a

[PATCH] D96355: [clang-tidy] Extend 'bugprone-easily-swappable-parameters' with optionally considering differently qualified types mixable

2021-06-23 Thread Whisperity via Phabricator via cfe-commits
whisperity updated this revision to Diff 353974.
whisperity added a comment.

**NFC**: Rebase & update.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96355

Files:
  clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.h
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-easily-swappable-parameters.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-ignore.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len3.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-qualifiermixing.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c
@@ -2,7 +2,8 @@
 // RUN:   -config='{CheckOptions: [ \
 // RUN: {key: bugprone-easily-swappable-parameters.MinimumLength, value: 2}, \
 // RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterNames, value: ""}, \
-// RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes, value: "bool;MyBool;struct U;MAKE_LOGICAL_TYPE(int)"} \
+// RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes, value: "bool;MyBool;struct U;MAKE_LOGICAL_TYPE(int)"}, \
+// RUN: {key: bugprone-easily-swappable-parameters.QualifiersMix, value: 0} \
 // RUN:  ]}' -- -x c
 
 #define bool _Bool
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-qualifiermixing.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-qualifiermixing.cpp
@@ -0,0 +1,112 @@
+// RUN: %check_clang_tidy %s bugprone-easily-swappable-parameters %t \
+// RUN:   -config='{CheckOptions: [ \
+// RUN: {key: bugprone-easily-swappable-parameters.MinimumLength, value: 2}, \
+// RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterNames, value: ""}, \
+// RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes, value: ""}, \
+// RUN: {key: bugprone-easily-swappable-parameters.QualifiersMix, value: 1} \
+// RUN:  ]}' --
+
+typedef int MyInt1;
+typedef int MyInt2;
+using CInt = const int;
+using CMyInt1 = const MyInt1;
+using CMyInt2 = const MyInt2;
+
+void qualified1(int I, const int CI) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 2 adjacent parameters of 'qualified1' of similar type are easily swapped by mistake [bugprone-easily-swappable-parameters]
+// CHECK-MESSAGES: :[[@LINE-2]]:21: note: the first parameter in the range is 'I'
+// CHECK-MESSAGES: :[[@LINE-3]]:34: note: the last parameter in the range is 'CI'
+// CHECK-MESSAGES: :[[@LINE-4]]:24: note: 'int' and 'const int' parameters accept and bind the same kind of values
+
+void qualified2(int I, volatile int VI) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 2 adjacent parameters of 'qualified2' of similar type are
+// CHECK-MESSAGES: :[[@LINE-2]]:21: note: the first parameter in the range is 'I'
+// CHECK-MESSAGES: :[[@LINE-3]]:37: note: the last parameter in the range is 'VI'
+// CHECK-MESSAGES: :[[@LINE-4]]:24: note: 'int' and 'volatile int' parameters accept and bind the same kind of values
+
+void qualified3(int I, const volatile int CVI) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 2 adjacent parameters of 'qualified3' of similar type are
+// CHECK-MESSAGES: :[[@LINE-2]]:21: note: the first parameter in the range is 'I'
+// CHECK-MESSAGES: :[[@LINE-3]]:43: note: the last parameter in the range is 'CVI'
+// CHECK-MESSAGES: :[[@LINE-4]]:24: note: 'int' and 'const volatile int' parameters accept and bind the same kind of values
+
+void qualified4(int *IP, const int *CIP) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 2 adjacent parameters of 'qualified4' of similar type are
+// CHECK-MESSAGES: :[[@LINE-2]]:22: note: the first parameter in the range is 'IP'
+// CHECK-MESSAGES: :[[@LINE-3]]:37: note: the last parameter in the range is 'CIP'
+// CHECK-MESSAGES: :[[@LINE-4]]:26: note: 'int *' and 'const int *' parameters accept and bind the same kind of values
+
+void qualified5(const int CI, const long CL) {} // NO-WARN: Not the same type
+
+void qualifiedPtr1(int *IP, int *const IPC) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: 2 adjacent parameters of 'qualifiedPtr1' of similar type are
+// CHECK-MESSAGES: :[[@LINE-2]]:25: note: the first parameter in the range is 'IP'
+// CH

[PATCH] D75041: [clang-tidy] Extend 'bugprone-easily-swappable-parameters' with mixability because of implicit conversions

2021-06-23 Thread Whisperity via Phabricator via cfe-commits
whisperity updated this revision to Diff 353975.
whisperity marked 5 inline comments as done.
whisperity added a comment.

**NFC**.

- Rebase and update for changes of base patch D69560 
.
- Remove the `<<=` and `%=` operators in favour of named functions.
- Elaborated the documentation for `ConversionSequence`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75041

Files:
  clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.h
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-easily-swappable-parameters.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-ignore.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len3.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-qualifiermixing.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c
@@ -2,7 +2,8 @@
 // RUN:   -config='{CheckOptions: [ \
 // RUN: {key: bugprone-easily-swappable-parameters.MinimumLength, value: 2}, \
 // RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterNames, value: ""}, \
-// RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes, value: "bool;MyBool;struct U;MAKE_LOGICAL_TYPE(int)"} \
+// RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes, value: "bool;MyBool;struct U;MAKE_LOGICAL_TYPE(int)"}, \
+// RUN: {key: bugprone-easily-swappable-parameters.QualifiersMix, value: 0} \
 // RUN:  ]}' -- -x c
 
 #define bool _Bool
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-qualifiermixing.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-qualifiermixing.cpp
@@ -0,0 +1,112 @@
+// RUN: %check_clang_tidy %s bugprone-easily-swappable-parameters %t \
+// RUN:   -config='{CheckOptions: [ \
+// RUN: {key: bugprone-easily-swappable-parameters.MinimumLength, value: 2}, \
+// RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterNames, value: ""}, \
+// RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes, value: ""}, \
+// RUN: {key: bugprone-easily-swappable-parameters.QualifiersMix, value: 1} \
+// RUN:  ]}' --
+
+typedef int MyInt1;
+typedef int MyInt2;
+using CInt = const int;
+using CMyInt1 = const MyInt1;
+using CMyInt2 = const MyInt2;
+
+void qualified1(int I, const int CI) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 2 adjacent parameters of 'qualified1' of similar type are easily swapped by mistake [bugprone-easily-swappable-parameters]
+// CHECK-MESSAGES: :[[@LINE-2]]:21: note: the first parameter in the range is 'I'
+// CHECK-MESSAGES: :[[@LINE-3]]:34: note: the last parameter in the range is 'CI'
+// CHECK-MESSAGES: :[[@LINE-4]]:24: note: 'int' and 'const int' parameters accept and bind the same kind of values
+
+void qualified2(int I, volatile int VI) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 2 adjacent parameters of 'qualified2' of similar type are
+// CHECK-MESSAGES: :[[@LINE-2]]:21: note: the first parameter in the range is 'I'
+// CHECK-MESSAGES: :[[@LINE-3]]:37: note: the last parameter in the range is 'VI'
+// CHECK-MESSAGES: :[[@LINE-4]]:24: note: 'int' and 'volatile int' parameters accept and bind the same kind of values
+
+void qualified3(int I, const volatile int CVI) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 2 adjacent parameters of 'qualified3' of similar type are
+// CHECK-MESSAGES: :[[@LINE-2]]:21: note: the first parameter in the range is 'I'
+// CHECK-MESSAGES: :[[@LINE-3]]:43: note: the last parameter in the range is 'CVI'
+// CHECK-MESSAGES: :[[@LINE-4]]:24: note: 'int' and 'const volatile int' parameters accept and bind the same kind of values
+
+void qualified4(int *IP, const int *CIP) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 2 adjacent parameters of 'qualified4' of similar type are
+// CHECK-MESSAGES: :[[@LINE-2]]:22: note: the first parameter in the range is 'IP'
+// CHECK-MESSAGES: :[[@LINE-3]]:37: note: the last parameter in the range is 'CIP'
+// CHECK-MESSAGES: :[[@LINE-4]]:26: note: 'int *' and 'const int *' parameters accept and bind the same kind of values
+
+void qualified5(const int CI, const long CL) {} // NO-WARN: Not the same type
+
+v

[PATCH] D78652: [clang-tidy] Suppress reports to similarly used parameters in 'bugprone-easily-swappable-parameters'

2021-06-23 Thread Whisperity via Phabricator via cfe-commits
whisperity updated this revision to Diff 353978.
whisperity added a comment.

**NFC**: Rebase & update.

While this patch conceptually only depends on D69560 
, the diff itself has become linear during the 
code review and subsequent updates, and as such, must be applied on top of 
D75041 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78652

Files:
  clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.h
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-easily-swappable-parameters.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-ignore.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-implicit-qualifiers.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-implicits.c
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-implicits.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len3.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-qualifiermixing.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-relatedness.c
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-relatedness.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c
@@ -4,7 +4,8 @@
 // RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterNames, value: ""}, \
 // RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes, value: "bool;MyBool;struct U;MAKE_LOGICAL_TYPE(int)"}, \
 // RUN: {key: bugprone-easily-swappable-parameters.QualifiersMix, value: 0}, \
-// RUN: {key: bugprone-easily-swappable-parameters.ModelImplicitConversions, value: 0} \
+// RUN: {key: bugprone-easily-swappable-parameters.ModelImplicitConversions, value: 0}, \
+// RUN: {key: bugprone-easily-swappable-parameters.SuppressParametersUsedTogether, value: 0} \
 // RUN:  ]}' -- -x c
 
 #define bool _Bool
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-relatedness.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-relatedness.cpp
@@ -0,0 +1,231 @@
+// RUN: %check_clang_tidy %s bugprone-easily-swappable-parameters %t \
+// RUN:   -config='{CheckOptions: [ \
+// RUN: {key: bugprone-easily-swappable-parameters.MinimumLength, value: 2}, \
+// RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterNames, value: ""}, \
+// RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes, value: ""}, \
+// RUN: {key: bugprone-easily-swappable-parameters.QualifiersMix, value: 0}, \
+// RUN: {key: bugprone-easily-swappable-parameters.ModelImplicitConversions, value: 0}, \
+// RUN: {key: bugprone-easily-swappable-parameters.SuppressParametersUsedTogether, value: 1} \
+// RUN:  ]}' --
+
+namespace std {
+template 
+T max(const T &A, const T &B);
+} // namespace std
+
+bool coin();
+void f(int);
+void g(int);
+void h(int, int);
+void i(int, bool);
+void i(int, char);
+
+struct Tmp {
+  int f(int);
+  int g(int, int);
+};
+
+struct Int {
+  int I;
+};
+
+void compare(int Left, int Right) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: 2 adjacent parameters of 'compare' of similar type ('int')
+// CHECK-MESSAGES: :[[@LINE-2]]:18: note: the first parameter in the range is 'Left'
+// CHECK-MESSAGES: :[[@LINE-3]]:28: note: the last parameter in the range is 'Right'
+
+int decideSequence(int A, int B) {
+  if (A)
+return 1;
+  if (B)
+return 2;
+  return 3;
+}
+// CHECK-MESSAGES: :[[@LINE-7]]:20: warning: 2 adjacent parameters of 'decideSequence' of similar type ('int')
+// CHECK-MESSAGES: :[[@LINE-8]]:24: note: the first parameter in the range is 'A'
+// CHECK-MESSAGES: :[[@LINE-9]]:31: note: the last parameter in the range is 'B'
+
+int myMax(int A, int B) { // NO-WARN: Appears in same expression.
+  return A < B ? A : B;
+}
+
+int myMax2(int A, int B) { // NO-WARN: Appears in same expression.
+  if (A < B)
+return A;
+  return B;
+}
+
+int myMax3(int A, int B) { // NO-WARN: Appears in same expression.
+  return std::max(A, B);
+}
+
+int binaryToUnary(int A, int) {

[PATCH] D97297: [clang-tidy] Suppress reports to patternedly named parameters in 'bugprone-easily-swappable-parameters'

2021-06-23 Thread Whisperity via Phabricator via cfe-commits
whisperity updated this revision to Diff 353979.
whisperity added a comment.

**NFC**: Rebase & update.

While this patch conceptually only depends on D69560 
, the diff itself has become linear during the 
code review and subsequent updates, and as such, must be applied on top of 
D78652 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97297

Files:
  clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.h
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-easily-swappable-parameters.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-ignore.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-implicit-qualifiers.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-implicits.c
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-implicits.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len3.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-prefixsuffixname.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-qualifiermixing.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-relatedness.c
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-relatedness.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c
@@ -5,7 +5,8 @@
 // RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes, value: "bool;MyBool;struct U;MAKE_LOGICAL_TYPE(int)"}, \
 // RUN: {key: bugprone-easily-swappable-parameters.QualifiersMix, value: 0}, \
 // RUN: {key: bugprone-easily-swappable-parameters.ModelImplicitConversions, value: 0}, \
-// RUN: {key: bugprone-easily-swappable-parameters.SuppressParametersUsedTogether, value: 0} \
+// RUN: {key: bugprone-easily-swappable-parameters.SuppressParametersUsedTogether, value: 0}, \
+// RUN: {key: bugprone-easily-swappable-parameters.NamePrefixSuffixSilenceDissimilarityTreshold, value: 0} \
 // RUN:  ]}' -- -x c
 
 #define bool _Bool
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-relatedness.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-relatedness.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-relatedness.cpp
@@ -5,7 +5,8 @@
 // RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes, value: ""}, \
 // RUN: {key: bugprone-easily-swappable-parameters.QualifiersMix, value: 0}, \
 // RUN: {key: bugprone-easily-swappable-parameters.ModelImplicitConversions, value: 0}, \
-// RUN: {key: bugprone-easily-swappable-parameters.SuppressParametersUsedTogether, value: 1} \
+// RUN: {key: bugprone-easily-swappable-parameters.SuppressParametersUsedTogether, value: 1}, \
+// RUN: {key: bugprone-easily-swappable-parameters.NamePrefixSuffixSilenceDissimilarityTreshold, value: 0} \
 // RUN:  ]}' --
 
 namespace std {
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-relatedness.c
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-relatedness.c
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-relatedness.c
@@ -5,7 +5,8 @@
 // RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes, value: ""}, \
 // RUN: {key: bugprone-easily-swappable-parameters.QualifiersMix, value: 0}, \
 // RUN: {key: bugprone-easily-swappable-parameters.ModelImplicitConversions, value: 0}, \
-// RUN: {key: bugprone-easily-swappable-parameters.SuppressParametersUsedTogether, value: 1} \
+// RUN: {key: bugprone-easily-swappable-parameters.SuppressParametersUsedTogether, value: 1}, \
+// RUN: {key: bugprone-easily-swappable-parameters.NamePrefixSuffixSilenceDissimilarityTreshold, value: 0} \
 // RUN:  ]}' -- -x c
 
 int myprint();
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-qualifiermixing.cpp
==

[PATCH] D69560: [clang-tidy] Add 'bugprone-easily-swappable-parameters' check

2021-06-23 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

In D69560#2747092 , @alexfh wrote:

> BTW, any ideas why "patch application failed"? (See the Build status in the 
> Diff Detail section)

I think I figured out why the pre-build CI isn't working... it seems that the 
fact that this patch depends on an abandoned revision D76545 
 misleads the CI logic as it sees the 
dependency, and even though it is abandoned, tries to download and apply the 
contents of D76545 , which makes it fail...

  INFOD76545#251840 commit 1e9b6b89a7b5c49612018b120c2c142106056f82 has a 
later commit date then7cdbf1ed4b94259a3aad2a7575e928fa61b0e57e
  [...]
  ERROR   error: patch failed: clang-tools-extra/docs/clang-tidy/index.rst:62
  error: clang-tools-extra/docs/clang-tidy/index.rst: patch does not apply
  error: patch failed: clang-tools-extra/clang-tidy/ClangTidyForceLinker.h:15
  error: clang-tools-extra/clang-tidy/ClangTidyForceLinker.h: patch does not 
apply


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69560

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


[PATCH] D69560: [clang-tidy] Add 'bugprone-easily-swappable-parameters' check

2021-06-23 Thread Whisperity via Phabricator via cfe-commits
whisperity updated this revision to Diff 353983.
whisperity added a comment.

(Try nudging the CI to only apply this commit after removal of parent links.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69560

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-easily-swappable-parameters.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-ignore.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len3.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c
@@ -0,0 +1,148 @@
+// RUN: %check_clang_tidy %s bugprone-easily-swappable-parameters %t \
+// RUN:   -config='{CheckOptions: [ \
+// RUN: {key: bugprone-easily-swappable-parameters.MinimumLength, value: 2}, \
+// RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterNames, value: ""}, \
+// RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes, value: "bool;MyBool;struct U;MAKE_LOGICAL_TYPE(int)"} \
+// RUN:  ]}' -- -x c
+
+#define bool _Bool
+#define true 1
+#define false 0
+
+typedef bool MyBool;
+
+#define TheLogicalType bool
+
+void declVoid(void); // NO-WARN: Declaration only.
+void decl(); // NO-WARN: Declaration only.
+void oneParam(int I) {}  // NO-WARN: 1 parameter.
+void variadic(int I, ...) {} // NO-WARN: 1 visible parameter.
+
+void trivial(int I, int J) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: 2 adjacent parameters of 'trivial' of similar type ('int') are easily swapped by mistake [bugprone-easily-swappable-parameters]
+// CHECK-MESSAGES: :[[@LINE-2]]:18: note: the first parameter in the range is 'I'
+// CHECK-MESSAGES: :[[@LINE-3]]:25: note: the last parameter in the range is 'J'
+
+void qualifier(int I, const int CI) {} // NO-WARN: Distinct types.
+
+void restrictQualifier(char *restrict CPR1, char *restrict CPR2) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: 2 adjacent parameters of 'restrictQualifier' of similar type ('char *restrict')
+// CHECK-MESSAGES: :[[@LINE-2]]:39: note: the first parameter in the range is 'CPR1'
+// CHECK-MESSAGES: :[[@LINE-3]]:60: note: the last parameter in the range is 'CPR2'
+
+void pointer1(int *IP1, int *IP2) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: 2 adjacent parameters of 'pointer1' of similar type ('int *')
+// CHECK-MESSAGES: :[[@LINE-2]]:20: note: the first parameter in the range is 'IP1'
+// CHECK-MESSAGES: :[[@LINE-3]]:30: note: the last parameter in the range is 'IP2'
+
+void pointerConversion(int *IP, long *LP) {}
+// NO-WARN: Even though C can convert any T* to U* back and forth, compiler
+// warnings already exist for this.
+
+void testVariadicsCall() {
+  int IVal = 1;
+  decl(IVal); // NO-WARN: Particular calls to "variadics" are like template
+  // instantiations, and we do not model them.
+
+  variadic(IVal);  // NO-WARN.
+  variadic(IVal, 2, 3, 4); // NO-WARN.
+}
+
+struct S {};
+struct T {};
+
+void taggedTypes1(struct S SVar, struct T TVar) {} // NO-WARN: Distinct types.
+
+void taggedTypes2(struct S SVar1, struct S SVar2) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 2 adjacent parameters of 'taggedTypes2' of similar type ('struct S')
+// CHECK-MESSAGES: :[[@LINE-2]]:28: note: the first parameter in the range is 'SVar1'
+// CHECK-MESSAGES: :[[@LINE-3]]:44: note: the last parameter in the range is 'SVar2'
+
+void wrappers(struct { int I; } I1, struct { int I; } I2) {} // NO-WARN: Distinct anonymous types.
+
+void knr(I, J)
+  int I;
+  int J;
+{}
+// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: 2 adjacent parameters of 'knr' of similar type ('int')
+// CHECK-MESSAGES: :[[@LINE-4]]:7: note: the first parameter in the range is 'I'
+// CHECK-MESSAGES: :[[@LINE-4]]:7: note: the last parameter in the range is 'J'
+
+void boolAsWritten(bool B1, bool B2) {} // NO-WARN: The type name is ignored.
+// Note that "bool" is a macro that expands to "_Bool" internally, but it is
+// only "bool" that is ignored from the two.
+
+void underscoreBoolAsWritten(_Bool B1, _Bool B2) {}
+// Even though it is "_Bool" that is written in the code, the diagnostic message
+// respects the printing policy as defined by 

[PATCH] D104117: [clangd] Fix highlighting for implicit ObjC property refs

2021-06-23 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 353987.
dgoldman added a comment.

Minor comment fixes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104117

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -696,11 +696,16 @@
   int $Field_decl[[_someProperty]];
 }
 @property(nonatomic, assign) int $Field_decl[[someProperty]];
+@property(readonly, class) $Class[[Foo]] 
*$Field_decl_readonly_static[[sharedInstance]];
 @end
 @implementation $Class_decl[[Foo]]
 @synthesize someProperty = _someProperty;
+- (int)$Method_decl[[otherMethod]] {
+  return 0;
+}
 - (int)$Method_decl[[doSomething]] {
-  self.$Field[[someProperty]] = self.$Field[[someProperty]] + 1;
+  $Class[[Foo]].$Field_static[[sharedInstance]].$Field[[someProperty]] 
= 1;
+  self.$Field[[someProperty]] = self.$Field[[someProperty]] + 
self.$Field[[otherMethod]] + 1;
   self->$Field[[_someProperty]] = $Field[[_someProperty]] + 1;
 }
 @end
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -556,6 +556,41 @@
 return true;
   }
 
+  // Objective-C allows you to use property syntax `self.prop` as sugar for
+  // `[self prop]` and `[self setProp:]` when there's no explicit `@property`
+  // for `prop` as well as for class properties. We treat this like a property
+  // even though semantically it's equivalent to a method expression.
+  void highlightObjCImplicitPropertyRef(const ObjCMethodDecl *OMD,
+SourceLocation Loc) {
+auto &Tok = H.addToken(Loc, HighlightingKind::Field)
+.addModifier(HighlightingModifier::ClassScope);
+if (OMD->isClassMethod())
+  Tok.addModifier(HighlightingModifier::Static);
+if (isDefaultLibrary(OMD))
+  Tok.addModifier(HighlightingModifier::DefaultLibrary);
+  }
+
+  bool VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *OPRE) {
+// We need to handle implicit properties here since they will appear to
+// reference `ObjCMethodDecl` via an implicit `ObjCMessageExpr`, so normal
+// highlighting will not work.
+if (!OPRE->isImplicitProperty())
+  return true;
+// A single property expr can reference both a getter and setter, but we 
can
+// only provide a single semantic token, so prefer the getter. In most 
cases
+// the end result should be the same, although it's technically possible
+// that the user defines a setter for a system SDK.
+if (OPRE->isMessagingGetter()) {
+  highlightObjCImplicitPropertyRef(OPRE->getImplicitPropertyGetter(),
+   OPRE->getLocation());
+  return true;
+} else if (OPRE->isMessagingSetter()) {
+  highlightObjCImplicitPropertyRef(OPRE->getImplicitPropertySetter(),
+   OPRE->getLocation());
+}
+return true;
+  }
+
   bool VisitOverloadExpr(OverloadExpr *E) {
 if (!E->decls().empty())
   return true; // handled by findExplicitReferences.


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -696,11 +696,16 @@
   int $Field_decl[[_someProperty]];
 }
 @property(nonatomic, assign) int $Field_decl[[someProperty]];
+@property(readonly, class) $Class[[Foo]] *$Field_decl_readonly_static[[sharedInstance]];
 @end
 @implementation $Class_decl[[Foo]]
 @synthesize someProperty = _someProperty;
+- (int)$Method_decl[[otherMethod]] {
+  return 0;
+}
 - (int)$Method_decl[[doSomething]] {
-  self.$Field[[someProperty]] = self.$Field[[someProperty]] + 1;
+  $Class[[Foo]].$Field_static[[sharedInstance]].$Field[[someProperty]] = 1;
+  self.$Field[[someProperty]] = self.$Field[[someProperty]] + self.$Field[[otherMethod]] + 1;
   self->$Field[[_someProperty]] = $Field[[_someProperty]] + 1;
 }
 @end
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/Se

[PATCH] D104118: [OpenCL] Use DW_LANG_OpenCL language tag for OpenCL C

2021-06-23 Thread Stuart Brady via Phabricator via cfe-commits
stuart updated this revision to Diff 353988.
stuart added a comment.

Added handling of `-gstrict-dwarf` and updated tests accordingly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104118

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenOpenCL/debug-info-programming-language.cl


Index: clang/test/CodeGenOpenCL/debug-info-programming-language.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/debug-info-programming-language.cl
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -dwarf-version=5 -emit-llvm -triple %itanium_abi_triple %s 
-o - \
+// RUN:   -x cl -O0 -disable-llvm-passes -debug-info-kind=limited \
+// RUN:   | FileCheck --check-prefix=CHECK-OPENCL %s
+// RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s 
-o - \
+// RUN:   -x cl -O0 -disable-llvm-passes -debug-info-kind=limited \
+// RUN:   | FileCheck --check-prefix=CHECK-OPENCL %s
+// RUN: %clang_cc1 -dwarf-version=3 -gstrict-dwarf -emit-llvm -triple 
%itanium_abi_triple %s -o - \
+// RUN:   -x cl -O0 -disable-llvm-passes -debug-info-kind=limited \
+// RUN:   | FileCheck --check-prefix=CHECK-C99 %s
+// RUN: %clang_cc1 -dwarf-version=5 -gstrict-dwarf -emit-llvm -triple 
%itanium_abi_triple %s -o - \
+// RUN:   -x cl -O0 -disable-llvm-passes -debug-info-kind=limited \
+// RUN:   | FileCheck --check-prefix=CHECK-OPENCL %s
+
+kernel void empty() {}
+
+// CHECK-OPENCL: distinct !DICompileUnit(language: DW_LANG_OpenCL,
+// CHECK-C99: distinct !DICompileUnit(language: DW_LANG_C99,
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -578,6 +578,9 @@
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
   } else if (LO.ObjC) {
 LangTag = llvm::dwarf::DW_LANG_ObjC;
+  } else if (LO.OpenCL && (!CGM.getCodeGenOpts().DebugStrictDwarf ||
+   CGM.getCodeGenOpts().DwarfVersion >= 5)) {
+LangTag = llvm::dwarf::DW_LANG_OpenCL;
   } else if (LO.RenderScript) {
 LangTag = llvm::dwarf::DW_LANG_GOOGLE_RenderScript;
   } else if (LO.C99) {


Index: clang/test/CodeGenOpenCL/debug-info-programming-language.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/debug-info-programming-language.cl
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -dwarf-version=5 -emit-llvm -triple %itanium_abi_triple %s -o - \
+// RUN:   -x cl -O0 -disable-llvm-passes -debug-info-kind=limited \
+// RUN:   | FileCheck --check-prefix=CHECK-OPENCL %s
+// RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s -o - \
+// RUN:   -x cl -O0 -disable-llvm-passes -debug-info-kind=limited \
+// RUN:   | FileCheck --check-prefix=CHECK-OPENCL %s
+// RUN: %clang_cc1 -dwarf-version=3 -gstrict-dwarf -emit-llvm -triple %itanium_abi_triple %s -o - \
+// RUN:   -x cl -O0 -disable-llvm-passes -debug-info-kind=limited \
+// RUN:   | FileCheck --check-prefix=CHECK-C99 %s
+// RUN: %clang_cc1 -dwarf-version=5 -gstrict-dwarf -emit-llvm -triple %itanium_abi_triple %s -o - \
+// RUN:   -x cl -O0 -disable-llvm-passes -debug-info-kind=limited \
+// RUN:   | FileCheck --check-prefix=CHECK-OPENCL %s
+
+kernel void empty() {}
+
+// CHECK-OPENCL: distinct !DICompileUnit(language: DW_LANG_OpenCL,
+// CHECK-C99: distinct !DICompileUnit(language: DW_LANG_C99,
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -578,6 +578,9 @@
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
   } else if (LO.ObjC) {
 LangTag = llvm::dwarf::DW_LANG_ObjC;
+  } else if (LO.OpenCL && (!CGM.getCodeGenOpts().DebugStrictDwarf ||
+   CGM.getCodeGenOpts().DwarfVersion >= 5)) {
+LangTag = llvm::dwarf::DW_LANG_OpenCL;
   } else if (LO.RenderScript) {
 LangTag = llvm::dwarf::DW_LANG_GOOGLE_RenderScript;
   } else if (LO.C99) {
___
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-06-23 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D103131#2835981 , @kamleshbhalui 
wrote:

> In D103131#2835909 , @dblaikie 
> wrote:
>
>> In D103131#2835702 , 
>> @kamleshbhalui wrote:
>>
>>> Here is what we get when we replace int with float.
>>>
>>>   $lldb-11 ./a.out 
>>>   (lldb) target create "./a.out"
>>>   Current executable set to 
>>> '/folk/kkumar/tcllvm/llvm-build-lldb-rel/bin/a.out' (x86_64).
>>>   (lldb) b main
>>>   Breakpoint 1: where = a.out`main + 4 at test.c:3:12, address = 
>>> 0x00400484
>>>   (lldb) p oldname
>>>   (float) $0 = 1
>>>   (lldb) p newname
>>>   (void *) $1 = 0x3f80
>>
>> Yep, looks like it's ignoring the imported declaration in favor of the raw 
>> symbol table entry.
>>
>> How's lldb handle GCC-style debug info (the variable declaration, without 
>> any imported declaration) for the alias?
>
> lldb's behavior is same even with GCC -style debug info.

Hmm, good to know/unfortunate. Guess it'll need some work.


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] D104058: ThinLTO: Fix inline assembly references to static functions with CFI

2021-06-23 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen added inline comments.



Comment at: llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp:58-80
+std::string OldName = Name.str();
 std::string NewName = (Name + ModuleId).str();
 
 if (const auto *C = ExportGV.getComdat())
   if (C->getName() == Name)
 RenamedComdats.try_emplace(C, ExportM.getOrInsertComdat(NewName));
 

nickdesaulniers wrote:
> Can you avoid making a copy of the OldName by doing the 
> `appendToCompilerUsed` BEFORE making the dangling reference via 
> `ExportGV.setName(NewName);`?
No, I have to rename the existing function before I can create an alias with 
the same name, and as `ExportGV.setName()` invalidates `Name`, I need to create 
a copy first.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104058

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


[PATCH] D104381: [analyzer] Added a test case for PR46264

2021-06-23 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 353992.
ASDenysPetrov added a comment.

Updated due to comments.
Confirm crash on commit `3ed8ebc2f6b8172bed48cc5986d3b7af4cfca1bc` from 
24.05.2020.
@NoQ ?


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

https://reviews.llvm.org/D104381

Files:
  clang/test/Analysis/diagnostics/PR46264.cpp


Index: clang/test/Analysis/diagnostics/PR46264.cpp
===
--- /dev/null
+++ clang/test/Analysis/diagnostics/PR46264.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text 
-verify %s
+
+// PR46264
+// This case shall not crash with an assertion failure about void* 
dereferening.
+// The crash has been last seen on commit
+// `3ed8ebc2f6b8172bed48cc5986d3b7af4cfca1bc` from 24.05.2020.
+namespace ns1 {
+namespace a {
+class b {
+public:
+  typedef int b::*c;
+  operator c() { return d ? &b::d : 0; }
+  // expected-note@-1{{'?' condition is true}}
+  // expected-note@-2{{Assuming field 'd' is not equal to 0}}
+  // expected-note@-3{{Returning value, which participates in a condition 
later}}
+  int d;
+};
+} // namespace a
+using a::b;
+class e {
+  void f();
+  void g();
+  b h;
+};
+void e::f() {
+  e *i;
+  // expected-note@-1{{'i' declared without an initial value}}
+  if (h)
+// expected-note@-1{{Taking true branch}}
+// expected-note@-2{{'b::operator int ns1::a::b::*'}}
+// expected-note@-3{{Returning from 'b::operator int ns1::a::b::*'}}
+i->g();
+  // expected-note@-1{{Called C++ object pointer is uninitialized}}
+  // expected-warning@-2{{Called C++ object pointer is uninitialized}}
+}
+} // namespace ns1


Index: clang/test/Analysis/diagnostics/PR46264.cpp
===
--- /dev/null
+++ clang/test/Analysis/diagnostics/PR46264.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text -verify %s
+
+// PR46264
+// This case shall not crash with an assertion failure about void* dereferening.
+// The crash has been last seen on commit
+// `3ed8ebc2f6b8172bed48cc5986d3b7af4cfca1bc` from 24.05.2020.
+namespace ns1 {
+namespace a {
+class b {
+public:
+  typedef int b::*c;
+  operator c() { return d ? &b::d : 0; }
+  // expected-note@-1{{'?' condition is true}}
+  // expected-note@-2{{Assuming field 'd' is not equal to 0}}
+  // expected-note@-3{{Returning value, which participates in a condition later}}
+  int d;
+};
+} // namespace a
+using a::b;
+class e {
+  void f();
+  void g();
+  b h;
+};
+void e::f() {
+  e *i;
+  // expected-note@-1{{'i' declared without an initial value}}
+  if (h)
+// expected-note@-1{{Taking true branch}}
+// expected-note@-2{{'b::operator int ns1::a::b::*'}}
+// expected-note@-3{{Returning from 'b::operator int ns1::a::b::*'}}
+i->g();
+  // expected-note@-1{{Called C++ object pointer is uninitialized}}
+  // expected-warning@-2{{Called C++ object pointer is uninitialized}}
+}
+} // namespace ns1
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104285: [analyzer] Retrieve value by direct index from list initialization of constant array declaration.

2021-06-23 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@chrish_ericsson_atx

Sorry for the late reply. Thank you for reveiwing this.

> I think the presence of the initializer list in the test case is not 
> necessary to trigger the spurious warnings

Could you please provide some test cases that you think will uncover other 
issues. I'll add them to the test set.

I also have to mention one point of what this patch do more. Consider next:

  int const arr[2][2] = {{1, 2}, {3, 4}}; // global space
  int const *ptr = &arr[0][0];
  ptr[3]; // represented as ConcreteInt(0) 
  arr[1][1]; // represented as reg_$0

As you can see, now the access through the raw pointer is more presice as 
through the multi-level indexing. I didn't want to synchronyze those retrieved 
values both to be `reg_$0`. I've seen a way to handle it more sophisticatedly.
I'm gonna do the same for the multi-level indexing (aka `arr[1][2][3]`).




Comment at: clang/lib/AST/Type.cpp:149
+Extents.push_back(*CAT->getSize().getRawData());
+  } while (CAT = dyn_cast(CAT->getElementType()));
+  return Extents;

chrish_ericsson_atx wrote:
> 
+1



Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1671
   if (auto CI = R->getIndex().getAs()) {
 int64_t i = CI->getValue().getSExtValue();
+const Expr *E = InitList->getExprForConstArrayByRawIndex(i);

chrish_ericsson_atx wrote:
> I see where you got the int64_t from -- that's what getSExtValue() returns.  
> So, if the literal const index value in the expr is greater than LONG_MAX 
> (but less than ULONG_MAX, of course), this would assert.  That seems 
> undesirable
That's a great catch! I'll make changes soon.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104285

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


[clang] be9a87f - [clang-format] Add IfMacros option

2021-06-23 Thread Vitali Lovich via cfe-commits

Author: Vitali Lovich
Date: 2021-06-23T08:51:53-07:00
New Revision: be9a87fe9bc395074c383c07fbd9c0bce953985f

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

LOG: [clang-format] Add IfMacros option

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

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

Added: 


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

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index f05e11469a7b5..77c07284085c8 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2377,6 +2377,28 @@ the configuration (without a prefix: ``Auto``).
 
   For example: BOOST_FOREACH.
 
+**IfMacros** (``std::vector``)
+  A vector of macros that should be interpreted as conditionals
+  instead of as function calls.
+
+  These are expected to be macros of the form:
+
+  .. code-block:: c++
+
+IF(...)
+  
+else IF(...)
+  
+
+  In the .clang-format configuration file, this can be configured like:
+
+  .. code-block:: yaml
+
+IfMacros: ['IF']
+
+  For example: `KJ_IF_MAYBE
+  `_
+
 **IncludeBlocks** (``IncludeBlocksStyle``)
   Dependent on the value, multiple ``#include`` blocks can be sorted
   as one and divided based on category.
@@ -3480,10 +3502,12 @@ the configuration (without a prefix: ``Auto``).
  }
}
 
-  * ``SBPO_ControlStatementsExceptForEachMacros`` (in configuration: 
``ControlStatementsExceptForEachMacros``)
+  * ``SBPO_ControlStatementsExceptControlMacros`` (in configuration: 
``ControlStatementsExceptControlMacros``)
 Same as ``SBPO_ControlStatements`` except this option doesn't apply to
-ForEach macros. This is useful in projects where ForEach macros are
-treated as function calls instead of control statements.
+ForEach and If macros. This is useful in projects where ForEach/If
+macros are treated as function calls instead of control statements.
+``SBPO_ControlStatementsExceptForEachMacros`` remains an alias for
+backward compatability.
 
 .. code-block:: c++
 

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4b432c1f3bb8d..7b23c1ef77af2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -265,6 +265,10 @@ clang-format
   change that so that the lambda body is indented one level relative to the 
scope
   containing the lambda, regardless of where the lambda signature was placed.
 
+- Option ``IfMacros`` has been added. This lets you define macros that get
+  formatted like conditionals much like ``ForEachMacros`` get styled like
+  foreach loops.
+
 - ``git-clang-format`` no longer formats changes to symbolic links. (Fixes
   https://llvm.org/PR46992.)
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index d51666fe9a1b0..506feea26e8dc 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2117,6 +2117,26 @@ struct FormatStyle {
   /// For example: BOOST_FOREACH.
   std::vector ForEachMacros;
 
+  /// A vector of macros that should be interpreted as conditionals
+  /// instead of as function calls.
+  ///
+  /// These are expected to be macros of the form:
+  /// \code
+  ///   IF(...)
+  /// 
+  ///   else IF(...)
+  /// 
+  /// \endcode
+  ///
+  /// In the .clang-format configuration file, this can be configured like:
+  /// \code{.yaml}
+  ///   IfMacros: ['IF']
+  /// \endcode
+  ///
+  /// For example: `KJ_IF_MAYBE
+  /// 
`_
+  std::vector IfMacros;
+
   /// \brief A vector of macros that should be interpreted as type declarations
   /// instead of as function calls.
   ///
@@ -3033,8 +3053,10 @@ struct FormatStyle {
 /// \endcode
 SBPO_ControlStatements,
 /// Same as ``SBPO_ControlStatements`` except this option doesn't apply to
-/// ForEach macros. This is useful in projects where ForEach macros are
-/// treated as function calls instead of control statements.
+/// ForEach and If macros. This is useful in projects where ForEach/If
+/// macros are treated as function calls instead of control statements.
+/// ``SBPO_ControlStatementsExceptForEachMacros`` remains an alias for
+/// backward compatability.
 /// \code
 ///void f() {
 ///  Q_FOREACH(...) {
@@ -3042,7 +3064,7 @@ struc

[PATCH] D102730: [clang-format] Support custom If macros

2021-06-23 Thread Vitali Lovich 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 rGbe9a87fe9bc3: [clang-format] Add IfMacros option (authored 
by vlovich).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102730

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -525,6 +525,7 @@
"}");
 
   FormatStyle AllowsMergedIf = getLLVMStyle();
+  AllowsMergedIf.IfMacros.push_back("MYIF");
   AllowsMergedIf.AlignEscapedNewlines = FormatStyle::ENAS_Left;
   AllowsMergedIf.AllowShortIfStatementsOnASingleLine =
   FormatStyle::SIS_WithoutElse;
@@ -564,17 +565,62 @@
"  f();\n"
"}",
AllowsMergedIf);
+  verifyFormat("MYIF (a)\n"
+   "  // comment\n"
+   "  f();",
+   AllowsMergedIf);
+  verifyFormat("{\n"
+   "  MYIF (a)\n"
+   "  label:\n"
+   "f();\n"
+   "}",
+   AllowsMergedIf);
+  verifyFormat("#define A  \\\n"
+   "  MYIF (a) \\\n"
+   "  label:   \\\n"
+   "f()",
+   AllowsMergedIf);
+  verifyFormat("MYIF (a)\n"
+   "  ;",
+   AllowsMergedIf);
+  verifyFormat("MYIF (a)\n"
+   "  MYIF (b) return;",
+   AllowsMergedIf);
+
+  verifyFormat("MYIF (a) // Can't merge this\n"
+   "  f();\n",
+   AllowsMergedIf);
+  verifyFormat("MYIF (a) /* still don't merge */\n"
+   "  f();",
+   AllowsMergedIf);
+  verifyFormat("MYIF (a) { // Never merge this\n"
+   "  f();\n"
+   "}",
+   AllowsMergedIf);
+  verifyFormat("MYIF (a) { /* Never merge this */\n"
+   "  f();\n"
+   "}",
+   AllowsMergedIf);
 
   AllowsMergedIf.ColumnLimit = 14;
+  // Where line-lengths matter, a 2-letter synonym that maintains line length.
+  // Not IF to avoid any confusion that IF is somehow special.
+  AllowsMergedIf.IfMacros.push_back("FI");
   verifyFormat("if (a) return;", AllowsMergedIf);
   verifyFormat("if (a)\n"
"  return;",
AllowsMergedIf);
+  verifyFormat("FI (a) return;", AllowsMergedIf);
+  verifyFormat("FI (a)\n"
+   "  return;",
+   AllowsMergedIf);
 
   AllowsMergedIf.ColumnLimit = 13;
   verifyFormat("if (a)\n  return;", AllowsMergedIf);
+  verifyFormat("FI (a)\n  return;", AllowsMergedIf);
 
   FormatStyle AllowsMergedIfElse = getLLVMStyle();
+  AllowsMergedIfElse.IfMacros.push_back("MYIF");
   AllowsMergedIfElse.AllowShortIfStatementsOnASingleLine =
   FormatStyle::SIS_AllIfsAndElse;
   verifyFormat("if (a)\n"
@@ -626,10 +672,60 @@
"  else if constexpr (c) return;\n"
"  else return;",
AllowsMergedIfElse);
+  verifyFormat("MYIF (a)\n"
+   "  // comment\n"
+   "  f();\n"
+   "else\n"
+   "  // comment\n"
+   "  f();",
+   AllowsMergedIfElse);
+  verifyFormat("{\n"
+   "  MYIF (a)\n"
+   "  label:\n"
+   "f();\n"
+   "  else\n"
+   "  label:\n"
+   "f();\n"
+   "}",
+   AllowsMergedIfElse);
+  verifyFormat("MYIF (a)\n"
+   "  ;\n"
+   "else\n"
+   "  ;",
+   AllowsMergedIfElse);
+  verifyFormat("MYIF (a) {\n"
+   "} else {\n"
+   "}",
+   AllowsMergedIfElse);
+  verifyFormat("MYIF (a) return;\n"
+   "else MYIF (b) return;\n"
+   "else return;",
+   AllowsMergedIfElse);
+  verifyFormat("MYIF (a) {\n"
+   "} else return;",
+   AllowsMergedIfElse);
+  verifyFormat("MYIF (a) {\n"
+   "} else MYIF (b) return;\n"
+   "else return;",
+   AllowsMergedIfElse);
+  verifyFormat("MYIF (a) return;\n"
+   "else MYIF (b) {\n"
+   "} else return;",
+   AllowsMergedIfElse);
+  verifyFormat("MYIF (a)\n"
+   "  MYIF (b) return;\n"
+   "  else return;",
+   AllowsMergedIfElse);
+  verifyFormat("MYIF constexpr (a)\n"
+   "  MYIF constexpr (b) return;\n"
+   "  else MYIF constexpr (c) return;\n"
+   "  else return;",
+ 

[PATCH] D104342: [IR] convert warn-stack-size from module flag to fn attr

2021-06-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D104342#2834240 , @dblaikie wrote:

> In D104342#2834119 , 
> @nickdesaulniers wrote:
>
>> I would think 
>> https://clang.llvm.org/docs/DiagnosticsReference.html#wframe-larger-than 
>> would be an appropriate place to document this for `-Wframe-larger-than=`, 
>> but it seems this whole page is generated via TableGen. It's not clear to me 
>> how we could insert such a note.
>
> Yeah, I don't think we have a way to add more verbose/custom documentation 
> for diagnostics. (@aaron.ballman might have some ideas)

I'm not aware of any way to do that today -- it would require more machinery 
for generating the diagnostic documentation, which is made harder by this 
particular diagnostic being a backend one that's not written out from tablegen.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104342

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


[PATCH] D104714: [UpdateCCTestChecks] Support --check-globals

2021-06-23 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 353998.
jdenny marked an inline comment as done.
jdenny added a comment.

Applied arichardson's suggestion: comment on exclusion of separator comments.

Rebased.


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

https://reviews.llvm.org/D104714

Files:
  clang/test/utils/update_cc_test_checks/Inputs/check-globals.c
  clang/test/utils/update_cc_test_checks/Inputs/lit.cfg.example
  clang/test/utils/update_cc_test_checks/check-globals.test
  clang/test/utils/update_cc_test_checks/lit.local.cfg
  llvm/utils/UpdateTestChecks/common.py
  llvm/utils/update_cc_test_checks.py

Index: llvm/utils/update_cc_test_checks.py
===
--- llvm/utils/update_cc_test_checks.py
+++ llvm/utils/update_cc_test_checks.py
@@ -147,6 +147,8 @@
   help='Keep function signature information around for the check line')
   parser.add_argument('--check-attributes', action='store_true',
   help='Check "Function Attributes" for functions')
+  parser.add_argument('--check-globals', action='store_true',
+  help='Check global entries (global variables, metadata, attribute sets, ...) for functions')
   parser.add_argument('tests', nargs='+')
   args = common.parse_commandline_args(parser)
   infer_dependent_args(args)
@@ -301,6 +303,7 @@
 global_vars_seen_dict = {}
 prefix_set = set([prefix for p in filecheck_run_list for prefix in p[0]])
 output_lines = []
+has_checked_pre_function_globals = False
 
 include_generated_funcs = common.find_arg_in_test(ti,
   lambda args: ti.args.include_generated_funcs,
@@ -333,6 +336,10 @@
  prefixes,
  func_dict, func)
 
+  if ti.args.check_globals:
+common.add_global_checks(builder.global_var_dict(), '//', run_list,
+ output_lines, global_vars_seen_dict, True,
+ True)
   common.add_checks_at_end(output_lines, filecheck_run_list, builder.func_order(),
'//', lambda my_output_lines, prefixes, func:
check_generator(my_output_lines,
@@ -347,6 +354,9 @@
 m = common.CHECK_RE.match(line)
 if m and m.group(1) in prefix_set:
   continue  # Don't append the existing CHECK lines
+# Skip special separator comments added by commmon.add_global_checks.
+if line.strip() == '//' + common.SEPARATOR:
+  continue
 if idx in line2spell_and_mangled_list:
   added = set()
   for spell, mangled in line2spell_and_mangled_list[idx]:
@@ -364,6 +374,11 @@
 # line as part of common.add_ir_checks()
 output_lines.pop()
 last_line = output_lines[-1].strip()
+  if ti.args.check_globals and not has_checked_pre_function_globals:
+common.add_global_checks(builder.global_var_dict(), '//',
+ run_list, output_lines,
+ global_vars_seen_dict, True, True)
+has_checked_pre_function_globals = True
   if added:
 output_lines.append('//')
   added.add(mangled)
@@ -375,6 +390,9 @@
 if include_line:
   output_lines.append(line.rstrip('\n'))
 
+if ti.args.check_globals:
+  common.add_global_checks(builder.global_var_dict(), '//', run_list,
+   output_lines, global_vars_seen_dict, True, False)
 common.debug('Writing %d lines to %s...' % (len(output_lines), ti.path))
 with open(ti.path, 'wb') as f:
   f.writelines(['{}\n'.format(l).encode('utf-8') for l in output_lines])
Index: llvm/utils/UpdateTestChecks/common.py
===
--- llvm/utils/UpdateTestChecks/common.py
+++ llvm/utils/UpdateTestChecks/common.py
@@ -780,6 +780,8 @@
 for p in prefix_list:
   global_vars_seen = {}
   checkprefixes = p[0]
+  if checkprefixes is None:
+continue
   for checkprefix in checkprefixes:
 if checkprefix in global_vars_seen_dict:
 global_vars_seen.update(global_vars_seen_dict[checkprefix])
Index: clang/test/utils/update_cc_test_checks/lit.local.cfg
===
--- clang/test/utils/update_cc_test_checks/lit.local.cfg
+++ clang/test/utils/update_cc_test_checks/lit.local.cfg
@@ -19,9 +19,13 @@
 script_path = os.path.join(config.llvm_src_root, 'utils',
'update_cc_test_checks.py')
 assert os.path.isfile(script_path)
+lit = shell_quote(os.path.join(config.llvm_src_root, 'utils', 'lit', 'lit.py'))
+python = shell_quote(config.python_executable)
 config.substitutions.append(
 ('%update_cc_test_checks', "%s %s %s" %

[PATCH] D104714: [UpdateCCTestChecks] Support --check-globals

2021-06-23 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In D104714#2835874 , @ggeorgakoudis 
wrote:

> LGTM too!

Thanks.


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

https://reviews.llvm.org/D104714

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


[PATCH] D104342: [IR] convert warn-stack-size from module flag to fn attr

2021-06-23 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D104342#2836222 , @aaron.ballman 
wrote:

> In D104342#2834240 , @dblaikie 
> wrote:
>
>> In D104342#2834119 , 
>> @nickdesaulniers wrote:
>>
>>> I would think 
>>> https://clang.llvm.org/docs/DiagnosticsReference.html#wframe-larger-than 
>>> would be an appropriate place to document this for `-Wframe-larger-than=`, 
>>> but it seems this whole page is generated via TableGen. It's not clear to 
>>> me how we could insert such a note.
>>
>> Yeah, I don't think we have a way to add more verbose/custom documentation 
>> for diagnostics. (@aaron.ballman might have some ideas)
>
> I'm not aware of any way to do that today -- it would require more machinery 
> for generating the diagnostic documentation, which is made harder by this 
> particular diagnostic being a backend one that's not written out from 
> tablegen.

Fair enough - thanks for the context!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104342

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


[PATCH] D104790: [x86] fix mm*_undefined* intrinsics to use arbitrary frozen bit pattern

2021-06-23 Thread Juneyoung Lee via Phabricator via cfe-commits
aqjune created this revision.
aqjune added reviewers: efriedma, spatel, craig.topper, RKSimon.
Herald added a subscriber: pengfei.
aqjune requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This fixes lowering of `mm*_undefined*` intrinsics to use `freeze poison` 
instead of zeroinitializer.
(mentioned & discussed in D103874 )


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104790

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/X86/avx-builtins.c
  clang/test/CodeGen/X86/avx2-builtins.c
  clang/test/CodeGen/X86/avx512f-builtins.c
  clang/test/CodeGen/X86/sse-builtins.c
  clang/test/CodeGen/X86/sse2-builtins.c

Index: clang/test/CodeGen/X86/sse2-builtins.c
===
--- clang/test/CodeGen/X86/sse2-builtins.c
+++ clang/test/CodeGen/X86/sse2-builtins.c
@@ -1630,13 +1630,16 @@
 
 __m128d test_mm_undefined_pd() {
   // CHECK-LABEL: test_mm_undefined_pd
-  // CHECK: ret <2 x double> zeroinitializer
+  // CHECK: %[[FR:.*]] = freeze <2 x double> poison
+  // CHECK: ret <2 x double> %[[FR]]
   return _mm_undefined_pd();
 }
 
 __m128i test_mm_undefined_si128() {
   // CHECK-LABEL: test_mm_undefined_si128
-  // CHECK: ret <2 x i64> zeroinitializer
+  // CHECK: %[[FR:.*]] = freeze <2 x double> poison
+  // CHECK: %[[FR_BC:.*]] = bitcast <2 x double> %[[FR]] to <2 x i64>
+  // CHECK: ret <2 x i64> %[[FR_BC]]
   return _mm_undefined_si128();
 }
 
Index: clang/test/CodeGen/X86/sse-builtins.c
===
--- clang/test/CodeGen/X86/sse-builtins.c
+++ clang/test/CodeGen/X86/sse-builtins.c
@@ -786,7 +786,9 @@
 
 __m128 test_mm_undefined_ps() {
   // CHECK-LABEL: test_mm_undefined_ps
-  // CHECK: ret <4 x float> zeroinitializer
+  // CHECK: %[[FR:.*]] = freeze <2 x double> poison
+  // CHECK: %[[FR_BC:.*]] = bitcast <2 x double> %[[FR]] to <4 x float>
+  // CHECK: ret <4 x float> %[[FR_BC]]
   return _mm_undefined_ps();
 }
 
Index: clang/test/CodeGen/X86/avx512f-builtins.c
===
--- clang/test/CodeGen/X86/avx512f-builtins.c
+++ clang/test/CodeGen/X86/avx512f-builtins.c
@@ -3780,25 +3780,32 @@
 
 __m512 test_mm512_undefined() {
   // CHECK-LABEL: @test_mm512_undefined
-  // CHECK: ret <16 x float> zeroinitializer
+  // CHECK: %[[FR:.*]] = freeze <8 x double> poison
+  // CHECK: %[[FR_BC:.*]] = bitcast <8 x double> %[[FR]] to <16 x float>
+  // CHECK: ret <16 x float> %[[FR_BC]]
   return _mm512_undefined();
 }
 
 __m512 test_mm512_undefined_ps() {
   // CHECK-LABEL: @test_mm512_undefined_ps
-  // CHECK: ret <16 x float> zeroinitializer
+  // CHECK: %[[FR:.*]] = freeze <8 x double> poison
+  // CHECK: %[[FR_BC:.*]] = bitcast <8 x double> %[[FR]] to <16 x float>
+  // CHECK: ret <16 x float> %[[FR_BC]]
   return _mm512_undefined_ps();
 }
 
 __m512d test_mm512_undefined_pd() {
   // CHECK-LABEL: @test_mm512_undefined_pd
-  // CHECK: ret <8 x double> zeroinitializer
+  // CHECK: %[[FR:.*]] = freeze <8 x double> poison
+  // CHECK: ret <8 x double> %[[FR]]
   return _mm512_undefined_pd();
 }
 
 __m512i test_mm512_undefined_epi32() {
   // CHECK-LABEL: @test_mm512_undefined_epi32
-  // CHECK: ret <8 x i64> zeroinitializer
+  // CHECK: %[[FR:.*]] = freeze <8 x double> poison
+  // CHECK: %[[FR_BC:.*]] = bitcast <8 x double> %[[FR]] to <8 x i64>
+  // CHECK: ret <8 x i64> %[[FR_BC]]
   return _mm512_undefined_epi32();
 }
 
Index: clang/test/CodeGen/X86/avx2-builtins.c
===
--- clang/test/CodeGen/X86/avx2-builtins.c
+++ clang/test/CodeGen/X86/avx2-builtins.c
@@ -455,7 +455,9 @@
 
 __m128i test_mm_i32gather_epi64(long long const *b, __m128i c) {
   // CHECK-LABEL: test_mm_i32gather_epi64
-  // CHECK: call <2 x i64> @llvm.x86.avx2.gather.d.q(<2 x i64> zeroinitializer, i8* %{{.*}}, <4 x i32> %{{.*}}, <2 x i64> %{{.*}}, i8 2)
+  // CHECK: %[[FR:.*]] = freeze <2 x double> poison
+  // CHECK: %[[FR_BC:.*]] = bitcast <2 x double> %[[FR]] to <2 x i64>
+  // CHECK: call <2 x i64> @llvm.x86.avx2.gather.d.q(<2 x i64> %[[FR_BC]], i8* %{{.*}}, <4 x i32> %{{.*}}, <2 x i64> %{{.*}}, i8 2)
   return _mm_i32gather_epi64(b, c, 2);
 }
 
@@ -467,7 +469,9 @@
 
 __m256i test_mm256_i32gather_epi64(long long const *b, __m128i c) {
   // CHECK-LABEL: test_mm256_i32gather_epi64
-  // CHECK: call <4 x i64> @llvm.x86.avx2.gather.d.q.256(<4 x i64> zeroinitializer, i8* %{{.*}}, <4 x i32> %{{.*}}, <4 x i64> %{{.*}}, i8 2)
+  // CHECK: %[[FR:.*]] = freeze <4 x double> poison
+  // CHECK: %[[FR_BC:.*]] = bitcast <4 x double> %[[FR]] to <4 x i64>
+  // CHECK: call <4 x i64> @llvm.x86.avx2.gather.d.q.256(<4 x i64> %[[FR_BC]], i8* %{{.*}}, <4 x i32> %{{.*}}, <4 x i64> %{{.*}}, i8 2)
   return _mm256_i32gather_epi64(b, c, 2);
 }
 
@@ -479,10 +483,11 @@
 
 __m128d test_mm_i32gather_pd(double const *b, __m128i c) {
   

[PATCH] D104790: [x86] fix mm*_undefined* intrinsics to use arbitrary frozen bit pattern

2021-06-23 Thread Juneyoung Lee via Phabricator via cfe-commits
aqjune added a comment.

I couldn't find end-to-end tests for checking assembly generation.
To check whether this is working ok, which tests should I write and how would 
it look like?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104790

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


[PATCH] D97224: Use Address for CGBuilder's CreateAtomicRMW and CreateAtomicCmpXchg.

2021-06-23 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

Ping. I think this is correct, and would like to commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97224

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


[PATCH] D104729: [clang][PATCH][nfc] Refactor TargetInfo::adjust to pass DiagnosticsEngine to allow diagnostics on target-unsupported options

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

LGTM, but you should land this only after we accept D100118 
 because it's only needed for that 
functionality.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104729

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


[PATCH] D100118: [clang] Add support for new builtin __arithmetic_fence to control floating point optimization, and new clang option fprotect-parens

2021-06-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D100118#2833864 , @mibintc wrote:

> This patch addresses almost all the review comments, not yet sure about 
> @aaron.ballman 's question about CoreOptions

FWIW, I'm fine addressing that comment in a follow-up. Also, it looks like the 
Clang changes didn't make it into the latest updated patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100118

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


[PATCH] D104556: [InstrProfiling] Make CountersPtr in __profd_ relative

2021-06-23 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

A one-time exception to the .profraw compatibility policy sounds reasonable to 
me.

A little more context: llvm has historically rev'd the .profraw format with 
abandon to deliver performance/size improvements (as David & co. did with name 
compression) and new functionality (value profiling, continuous sync mode, 
...). That will keep happening. The freedom to rev the raw format comes from 
keeping it private between the profile reader library and the runtime. Some 
alternatives to hardcoding details of a particular version of the .profraw 
format were mentioned earlier in the thread: if the Linux PGO support can 
pursue one of these (or find some other solution), I think it will it prevent 
headaches down the road.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104556

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


[PATCH] D104777: PR50767: clear non-distinct debuginfo for function with nodebug definition after undecorated declaration

2021-06-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D104777#2835965 , @dblaikie wrote:

> @aaron.ballman Do we have attributes/infrastructure for attributes that have 
> to be the same from their first declaration or at least from their first 
> call? I'm wondering if it might be simpler/better to require nodebug to be 
> provided earlier, rather than fixing it up after the fact like this.
>
> (for instance, requiring it to be attributed on the declaration would ensure 
> we don't create call_site descriptions for calls to nodebug functions - which 
> would save some debug info size)

We don't have any attributes that have to be the same "from their first call" 
that I'm aware of. But we do have attributes that need to be the same on all 
declarations. IIRC, the `section` and `code_seg` attributes both have to be 
specified on the initial declaration in some circumstances, and `[[noreturn]]` 
needs to be on the first declaration we see. We don't have any tablegen 
machinery to enforce this, the logic needs to be manually written. I think it'd 
live somewhere around `Sema::mergeDeclAttributes()` or 
`Sema::MergeFunctionDecl()` most likely.

Fixing up after the fact would be a bit strange though. A declaration is 
typically considered marked by an attribute from the point of declaration 
including the attribute onward, not backwards. e.g., 
https://godbolt.org/z/4E1Ya764n I won't say we *never* do this back 
propagation, but I would say it's a sign that the attribute is venturing into 
novel, perhaps dangerous territory. For example with this patch, an AST matcher 
won't see the `nodebug` attribute on the initial declaration of `t1()` and so 
it won't react to it the same way that codegen is being changed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104777

___
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-06-23 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

I'll update tommorow.




Comment at: clang/unittests/StaticAnalyzer/RangeSetTest.cpp:120
+
+  template  const llvm::APSInt &from(T X) {
+static llvm::APSInt Int = APSIntTy.getZeroValue();

vsavchenko wrote:
> Default to `BaseType`?
It's implicitly deduced. I think it is not necessary.



Comment at: clang/unittests/StaticAnalyzer/RangeSetTest.cpp:131
+  template 
+  RangeSet from(RawRangeSetT Init, APSIntType Ty = APSIntTy) {
 RangeSet RangeSet = F.getEmptySet();

vsavchenko wrote:
> Unused parameter?
Oh... :-)



Comment at: clang/unittests/StaticAnalyzer/RangeSetTest.cpp:721-799
+TYPED_TEST(RangeSetCastToNoopTest, RangeSetCastToNoopTest) {
+  // Just to reduce the verbosity.
+  using F = typename TypeParam::FromType; // From
+  using T = typename TypeParam::ToType;   // To
+
+  using TV = TestValues;
+  constexpr auto MIN = TV::MIN;

vsavchenko wrote:
> If loop and promotion share the same test case, why should we split them into 
> two groups?
Yes, the tests are identical but they use different `testing::Types` in the 
suites. Also I don't want to mix them to make problem localizing easier if 
occurs. But still  I haven't strong preferences on that.


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

https://reviews.llvm.org/D103094

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


[PATCH] D100118: [clang] Add support for new builtin __arithmetic_fence to control floating point optimization, and new clang option fprotect-parens

2021-06-23 Thread Melanie Blower via Phabricator via cfe-commits
mibintc updated this revision to Diff 354009.
mibintc added a comment.

The patch I uploaded for review yesterday wasn't correct, not sure what 
happened.  This one looks better.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100118

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/TargetInfo.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/arithmetic-fence-builtin.c
  clang/test/CodeGen/arithmetic-fence-builtin.c
  clang/test/Driver/clang_f_opts.c
  clang/test/Sema/arithmetic-fence-builtin.c

Index: clang/test/Sema/arithmetic-fence-builtin.c
===
--- /dev/null
+++ clang/test/Sema/arithmetic-fence-builtin.c
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -o - -verify -x c++ %s
+// RUN: %clang_cc1 -triple ppc64le -DPPC -emit-llvm -o - -verify -x c++ %s
+// RUN: not %clang_cc1 -triple ppc64le -DPPC -emit-llvm -o - -x c++ %s \
+// RUN:-fprotect-parens 2>&1 | FileCheck -check-prefix=PPC %s
+#ifndef PPC
+int v;
+template  T addT(T a, T b) {
+  T *q = __arithmetic_fence(&a);
+  // expected-error@-1 {{invalid operand of type 'float *' where floating, complex or a vector of such types is required}}
+  // expected-error@-2 {{invalid operand of type 'int *' where floating, complex or a vector of such types is required}}
+  return __arithmetic_fence(a + b);
+  // expected-error@-1 {{invalid operand of type 'int' where floating, complex or a vector of such types is required}}
+}
+int addit(int a, int b) {
+  float x, y;
+  typedef struct {
+int a, b;
+  } stype;
+  stype s;
+  s = __arithmetic_fence(s);// expected-error {{invalid operand of type 'stype' where floating, complex or a vector of such types is required}}
+  x = __arithmetic_fence(); // expected-error {{too few arguments to function call, expected 1, have 0}}
+  x = __arithmetic_fence(x, y); // expected-error {{too many arguments to function call, expected 1, have 2}}
+  // Complex is supported.
+  _Complex double cd, cd1;
+  cd = __arithmetic_fence(cd1);
+  // Vector is supported.
+  typedef float __v4hi __attribute__((__vector_size__(8)));
+  __v4hi vec1, vec2;
+  vec1 = __arithmetic_fence(vec2);
+
+  v = __arithmetic_fence(a + b); // expected-error {{invalid operand of type 'int' where floating, complex or a vector of such types is required}}
+  float f = addT(a, b);   // expected-note {{in instantiation of function template specialization 'addT' requested here}}
+  int i = addT(1, 2);   // expected-note {{in instantiation of function template specialization 'addT' requested here}}
+  constexpr float d = 1.0 + 2.0;
+  constexpr float c = __arithmetic_fence(1.0 + 2.0);
+  constexpr float e = __arithmetic_fence(d);
+  return 0;
+}
+bool func(float f1, float f2, float f3) {
+  return (f1 == f2 && f1 == f3) || f2 == f3; // Should not warn here
+}
+static_assert( __arithmetic_fence(1.0 + 2.0), "message" );
+#else
+float addit(float a, float b) {
+  return __arithmetic_fence(a+b); // expected-error {{builtin is not supported on this target}}
+}
+#endif
+//PPC: error: option '-fprotect-parens' cannot be specified on this target
Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -1,13 +1,14 @@
 // REQUIRES: clang-driver
 
 // RUN: %clang -### -S -fasm -fblocks -fbuiltin -fno-math-errno -fcommon -fpascal-strings -fno-blocks -fno-builtin -fmath-errno -fno-common -fno-pascal-strings -fblocks -fbuiltin -fmath-errno -fcommon -fpascal-strings -fsplit-stack %s 2>&1 | FileCheck -check-prefix=CHECK-OPTIONS1 %s
-// RUN: %clang -### -S -fasm -fblocks -fbuiltin -fno-math-errno -fcommon -fpascal-strings -fno-asm -fno-blocks -fno-builtin -fmath-errno -fno-common -fno-pascal-strings -fno-show-source-location -fshort-enums %s 2>&1 | FileCheck -check-prefix=CHECK-OPTIONS2 %s
+// RUN: %clang -### -S -fasm -fblocks -fbuiltin -fno-math-errno -fcommon -fpascal-strings -fno-asm -fno-blocks -fno-builtin -fmath-errno -fno-common -fno-pascal-strings -fno-show-source-location -fshort-enums -fprotect-parens %s 2>&1 | FileCheck -check-prefix=CHECK-OPTIONS2 %s
 
 // CHECK-OPTIONS1: -fsplit-stack
 // CHECK-OPTIONS1: -fgnu-keywords
 // CHECK-OPTIONS1: -fblocks
 // CHECK-OPTIONS1: -fpascal-strings
 
+// CHECK-OPTIONS2: -fprotect-parens
 // CHECK-OPTIONS2: -fmath-errno
 // CHECK-OPTIONS2: -fno-gnu-

[PATCH] D103938: Diagnose -Wunused-value in constant evaluation context

2021-06-23 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/D103938/new/

https://reviews.llvm.org/D103938

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


[PATCH] D100118: [clang] Add support for new builtin __arithmetic_fence to control floating point optimization, and new clang option fprotect-parens

2021-06-23 Thread Melanie Blower via Phabricator via cfe-commits
mibintc marked 9 inline comments as done.
mibintc added a comment.

A couple inline replies to go along with the updated patch




Comment at: clang/include/clang/Driver/Options.td:1757
+  LangOpts<"ProtectParens">, DefaultFalse,
+  PosFlag Should this option also be exposed to clang-cl (should it be a `CoreOption`)?
I don't know the answer to this, do you have a recommendation? 



Comment at: clang/lib/Sema/SemaChecking.cpp:6427-6430
+if (const VectorType *VT = dyn_cast(ArgTy.getCanonicalType()))
+  return VT->getElementType().getTypePtr()->isFloatingType();
+if (const ComplexType *CT = 
dyn_cast(ArgTy.getCanonicalType()))
+  return CT->getElementType().getTypePtr()->isFloatingType();

aaron.ballman wrote:
> 
I found there was a boolean function, so i got rid of the lambda. 



Comment at: clang/lib/Sema/SemaCoroutine.cpp:294
 
-static Expr *buildBuiltinCall(Sema &S, SourceLocation Loc, Builtin::ID Id,
-  MultiExprArg CallArgs) {

I moved this function to public because another file is also using the same 
logic



Comment at: clang/lib/Sema/SemaExpr.cpp:4026
+  !E->isLValue() &&
+  (ExprTy->isFloatingType() || (ExprTy->isComplexType( {
+return BuildBuiltinCallExpr(R, Builtin::BI__arithmetic_fence, E);

aaron.ballman wrote:
> Do you have to worry about vector types here as well?
Oh yes, i didn't get this one. 



Comment at: clang/lib/Sema/SemaExpr.cpp:4027
+  (ExprTy->isFloatingType() || (ExprTy->isComplexType( {
+return BuildBuiltinCallExpr(R, Builtin::BI__arithmetic_fence, E);
+  }

aaron.ballman wrote:
> One worry I have about this is that the AST will be a bit mysterious for 
> people writing AST matchers. The source code will have parens in it, but the 
> AST will have a `ParenExpr` node or not only depending on the language 
> options. This may also cause problems for other parts of the code that are 
> checking for properly-parenthesized expressions (like && and || within the 
> same expression), so we should probably have a test case like:
> ```
> bool func(float f1, float f2, float f3) {
>   return (f1 == f2 && f1 == f3) || f2 == f3; // Should not warn here
> }
> ```
I added an AST test case 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100118

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


[PATCH] D104797: [WebAssembly] Implementation of global.get/set for reftypes in LLVM IR

2021-06-23 Thread Paulo Matos via Phabricator via cfe-commits
pmatos created this revision.
pmatos added a reviewer: tlively.
Herald added subscribers: ecnelises, sunfish, hiraditya, jgravelle-google, 
sbc100, dschuff.
pmatos requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, aheejin.
Herald added projects: clang, LLVM.

Reland of 31859f896 
.

This change implements new DAG notes GLOBAL_GET/GLOBAL_SET, and
lowering methods for load and stores of reference types from IR
globals. Once the lowering creates the new nodes, tablegen pattern
matches those and converts them to Wasm global.get/set.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104797

Files:
  clang/lib/Basic/Targets/WebAssembly.cpp
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/include/llvm/CodeGen/ValueTypes.h
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/CodeGen/MachineOperand.cpp
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/lib/CodeGen/TargetLoweringBase.cpp
  llvm/lib/CodeGen/ValueTypes.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.h
  llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyISD.def
  llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.h
  llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td
  llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
  llvm/test/CodeGen/WebAssembly/externref-globalget.ll
  llvm/test/CodeGen/WebAssembly/externref-globalset.ll
  llvm/test/CodeGen/WebAssembly/externref-inttoptr.ll
  llvm/test/CodeGen/WebAssembly/externref-ptrtoint.ll
  llvm/test/CodeGen/WebAssembly/externref-ptrtoint.s
  llvm/test/CodeGen/WebAssembly/externref-undef.ll
  llvm/test/CodeGen/WebAssembly/externref-unsized-load.ll
  llvm/test/CodeGen/WebAssembly/externref-unsized-store.ll
  llvm/test/CodeGen/WebAssembly/funcref-call.ll
  llvm/test/CodeGen/WebAssembly/funcref-globalget.ll
  llvm/test/CodeGen/WebAssembly/funcref-globalset.ll

Index: llvm/test/CodeGen/WebAssembly/funcref-globalset.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/funcref-globalset.ll
@@ -0,0 +1,20 @@
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
+
+%func = type opaque
+%funcref = type %func addrspace(20)* ;; addrspace 20 is nonintegral
+
+@funcref_global = local_unnamed_addr addrspace(1) global %funcref undef
+
+define void @set_funcref_global(%funcref %g) {
+  ;; this generates a global.set of @funcref_global
+  store %funcref %g, %funcref addrspace(1)* @funcref_global
+  ret void
+}
+
+; CHECK-LABEL: set_funcref_global:
+; CHECK-NEXT: functype   set_funcref_global (funcref) -> ()
+; CHECK-NEXT: local.get  0
+; CHECK-NEXT: global.set funcref_global
+; CHECK-NEXT: end_function
+
+; CHECK: .globl funcref_global
Index: llvm/test/CodeGen/WebAssembly/funcref-globalget.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/funcref-globalget.ll
@@ -0,0 +1,19 @@
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
+
+%func = type opaque
+%funcref = type %func addrspace(20)* ;; addrspace 20 is nonintegral
+
+@funcref_global = local_unnamed_addr addrspace(1) global %funcref undef
+
+define %funcref @return_funcref_global() {
+  ;; this generates a global.get of @funcref_global
+  %ref = load %funcref, %funcref addrspace(1)* @funcref_global
+  ret %funcref %ref
+}
+
+; CHECK-LABEL: return_funcref_global:
+; CHECK-NEXT: .functype   return_funcref_global () -> (funcref)
+; CHECK-NEXT: global.get funcref_global
+; CHECK-NEXT: end_function
+
+; CHECK: .globl funcref_global
Index: llvm/test/CodeGen/WebAssembly/funcref-call.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/funcref-call.ll
@@ -0,0 +1,23 @@
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
+
+%func = type void ()
+%funcref = type %func addrspace(20)* ;; addrspace 20 is nonintegral
+
+define void @call_funcref(%funcref %ref) {
+  call addrspace(20) void %ref() 
+  ret void
+}
+
+; CHECK-LABEL: call_funcref:
+; CHECK-NEXT: functype   call_funcref (funcref) -> ()
+; CHECK-NEXT: i32.const 0
+; CHECK-NEXT: local.get 0
+; CHECK-NEXT: table.set __funcref_call_table
+; CHECK-NEXT: local.get 0
+; CHECK-NEXT: call_indirect __funcref_call_table, () -> ()
+; CHECK-NEXT: i32.const 0
+; CHECK-NEXT: ref.null func
+; CHECK-NEXT: table.set __funcref_call_table
+; CHECK-NEXT: end_function
+
+; CHECK: .tabletype __funcref_call_table, funcref
Index: llvm/test/CodeGen/WebAsse

[PATCH] D104790: [x86] fix mm*_undefined* intrinsics to use arbitrary frozen bit pattern

2021-06-23 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

In D104790#2836253 , @aqjune wrote:

> I couldn't find end-to-end tests for checking assembly generation.
> To check whether this is working ok, which tests should I write and how would 
> it look like?

There are tests like test/CodeGen/X86/avx-intrinsics-fast-isel.ll that are 
supposed to contain the IR the frontend generates. They mostly contain 
optimized IR, but then run fast-isel in the backend. I don't think all 
intrinsics are tested this way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104790

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


[PATCH] D103938: Diagnose -Wunused-value in constant evaluation context

2021-06-23 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

I've given this some more thought, and I think it's only the "constant 
evaluated" check that we want to bypass in this case. It's common to use 
`sizeof` or `decltype` with a comma operator in order to put an expression in a 
SFINAE context, and I don't think we should warn on those cases. So I think we 
should still do the context check for `DiagIfReachable`, but only bail out for 
unevaluated contexts, not for constant-evaluated contexts. Does that seem 
reasonable?




Comment at: clang/test/SemaCXX/warn-unused-value.cpp:147
+  new double[false ? (1, 2) : 3]
+[false ? (1, 2) : 3]; // expected-warning {{expression result 
unused}}
+}

Please add a FIXME saying that we shouldn't diagnose the unreachable constant 
expression here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103938

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


[PATCH] D104797: [WebAssembly] Implementation of global.get/set for reftypes in LLVM IR

2021-06-23 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added a comment.

This patch would have fixed the problems with AArch64 caused by D95425 
. However, since that was landed and reverted, 
this landed: 
https://github.com/llvm/llvm-project/commit/ac81cb7e6dde9b0890ee1780eae94ab96743569b

This breaks the test `llvm/test/CodeGen/WebAssembly/externref-ptrtoint.ll` 
which was expected to fail. I still think that a `ptrtoint` on an `externref` 
value should fail, and yet since `ac81cb7e` allows `ptrtoint` on non-integral 
pointer types, the verifier is letting this test to go through and it crashes 
LLVM later on during some DAG node analysis.

@tlively Do you think it would be ok to re-add the code removed in `ac81cb7e` 
but only error if the pointer is to an **opaque** non-integral type?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104797

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


[PATCH] D104797: [WebAssembly] Implementation of global.get/set for reftypes in LLVM IR

2021-06-23 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added a subscriber: reames.
pmatos added a comment.

Adding @reames to subscribers since he's the author of 
https://github.com/llvm/llvm-project/commit/ac81cb7e6dde9b0890ee1780eae94ab96743569b
 and might have something to add to the discussion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104797

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


[PATCH] D104388: [clang-format] PR50727 C# Invoke Lamda Expression indentation incorrect

2021-06-23 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

ping


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

https://reviews.llvm.org/D104388

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


[PATCH] D100118: [clang] Add support for new builtin __arithmetic_fence to control floating point optimization, and new clang option fprotect-parens

2021-06-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Driver/Options.td:1757
+  LangOpts<"ProtectParens">, DefaultFalse,
+  PosFlag aaron.ballman wrote:
> > Should this option also be exposed to clang-cl (should it be a 
> > `CoreOption`)?
> I don't know the answer to this, do you have a recommendation? 
I think this would be useful for clang-cl users, so I'd recommend adding it to 
`CoreOption` unless there's a reason not to.



Comment at: clang/lib/AST/ExprConstant.cpp:9329-9331
+  case Builtin::BI__arithmetic_fence:
+return false;
+

Under what circumstances could we get here? (Given that this is within 
`PointerExprEvaluator`, I would have assumed this would be unreachable code.)



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:2841
+llvm::FastMathFlags FMF = Builder.getFastMathFlags();
+bool isArithmeticFenceEnabled = FMF.allowReassoc() &&
+  getContext().getTargetInfo().checkArithmeticFenceSupported();

May as well fix this clang-format issue.



Comment at: clang/lib/Sema/SemaExpr.cpp:6568
+Expr *Sema::BuildBuiltinCallExpr(SourceLocation Loc, Builtin::ID Id,
+  MultiExprArg CallArgs) {
+  StringRef Name = Context.BuiltinInfo.getName(Id);

Might as well hit this clang-format warning too.



Comment at: clang/test/AST/arithmetic-fence-builtin.c:34
+
+  v = (a + b);
+

Does the `(a + b)` still have an AST node for the `ParenExpr`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100118

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


[PATCH] D104800: [OpenCL] Do not include default header for preprocessor output as input

2021-06-23 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: Anastasia.
Herald added subscribers: kerbowa, nhaehnle, jvesely.
yaxunl requested review of this revision.

When clang driver is used with -save-temps to compile OpenCL program,
clang driver first launches clang -cc1 -E to generate preprocessor expansion 
output,
then launches clang -cc1 with the generated preprocessor expansion output as 
input
to generate LLVM IR.

Currently clang by default passes "-finclude-default-header" 
"-fdeclare-opencl-builtins"
in both steps, which causes default header included again in the second step, 
which
causes error.

This patch let clang not to include default header when input type is 
preprocessor expansion
output, which fixes the issue.


https://reviews.llvm.org/D104800

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/amdgpu-toolchain-opencl.cl


Index: clang/test/Driver/amdgpu-toolchain-opencl.cl
===
--- clang/test/Driver/amdgpu-toolchain-opencl.cl
+++ clang/test/Driver/amdgpu-toolchain-opencl.cl
@@ -7,6 +7,12 @@
 // RUN: %clang -### -target amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm 
-mcpu=fiji -Og %s 2>&1 | FileCheck -check-prefix=CHECK_Og %s
 // RUN: %clang -### -target amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm 
-mcpu=fiji -Ofast %s 2>&1 | FileCheck -check-prefix=CHECK_Ofast %s
 // RUN: %clang -### -target amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm 
-mcpu=fiji %s 2>&1 | FileCheck -check-prefix=CHECK_O_DEFAULT %s
+
+// Check default include file is not included for preprocessor output.
+
+// RUN: %clang -### -target amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm 
-mcpu=fiji %s 2>&1 | FileCheck -check-prefix=CHK-INC %s
+// RUN: %clang -### -target amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm 
-mcpu=fiji -save-temps %s 2>&1 | FileCheck -check-prefix=CHK-INC %s
+
 // CHECK_O0: clang{{.*}} "-O0"
 // CHECK_O1: clang{{.*}} "-O1"
 // CHECK_O2: clang{{.*}} "-O2"
@@ -17,3 +23,5 @@
 // CHECK_Ofast: {{.*}}clang{{.*}} "-Ofast"
 // CHECK_O_DEFAULT: clang{{.*}} "-O3"
 
+// CHK-INC: clang{{.*}} "-cc1" {{.*}}"-finclude-default-header" 
"-fdeclare-opencl-builtins" {{.*}}"-x" "cl"
+// CHK-INC-NOT: clang{{.*}} "-cc1" {{.*}}"-finclude-default-header" 
"-fdeclare-opencl-builtins" {{.*}}"-x" "cpp-output"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3272,7 +3272,8 @@
   CmdArgs.push_back(Args.MakeArgString(A->getOption().getPrefixedName()));
 
   // Only add the default headers if we are compiling OpenCL sources.
-  if ((types::isOpenCL(InputType) || Args.hasArg(options::OPT_cl_std_EQ)) &&
+  if ((types::isOpenCL(InputType) ||
+   (Args.hasArg(options::OPT_cl_std_EQ) && types::isSrcFile(InputType))) &&
   !Args.hasArg(options::OPT_cl_no_stdinc)) {
 CmdArgs.push_back("-finclude-default-header");
 CmdArgs.push_back("-fdeclare-opencl-builtins");


Index: clang/test/Driver/amdgpu-toolchain-opencl.cl
===
--- clang/test/Driver/amdgpu-toolchain-opencl.cl
+++ clang/test/Driver/amdgpu-toolchain-opencl.cl
@@ -7,6 +7,12 @@
 // RUN: %clang -### -target amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -Og %s 2>&1 | FileCheck -check-prefix=CHECK_Og %s
 // RUN: %clang -### -target amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -Ofast %s 2>&1 | FileCheck -check-prefix=CHECK_Ofast %s
 // RUN: %clang -### -target amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji %s 2>&1 | FileCheck -check-prefix=CHECK_O_DEFAULT %s
+
+// Check default include file is not included for preprocessor output.
+
+// RUN: %clang -### -target amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji %s 2>&1 | FileCheck -check-prefix=CHK-INC %s
+// RUN: %clang -### -target amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -save-temps %s 2>&1 | FileCheck -check-prefix=CHK-INC %s
+
 // CHECK_O0: clang{{.*}} "-O0"
 // CHECK_O1: clang{{.*}} "-O1"
 // CHECK_O2: clang{{.*}} "-O2"
@@ -17,3 +23,5 @@
 // CHECK_Ofast: {{.*}}clang{{.*}} "-Ofast"
 // CHECK_O_DEFAULT: clang{{.*}} "-O3"
 
+// CHK-INC: clang{{.*}} "-cc1" {{.*}}"-finclude-default-header" "-fdeclare-opencl-builtins" {{.*}}"-x" "cl"
+// CHK-INC-NOT: clang{{.*}} "-cc1" {{.*}}"-finclude-default-header" "-fdeclare-opencl-builtins" {{.*}}"-x" "cpp-output"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3272,7 +3272,8 @@
   CmdArgs.push_back(Args.MakeArgString(A->getOption().getPrefixedName()));
 
   // Only add the default headers if we are compiling OpenCL sources.
-  if ((types::isOpenCL(InputType) || Args.hasArg(options::OPT_cl_std_EQ)) &&
+  if ((types::isOpenCL(InputType) ||
+   (Args.hasArg(options::OPT_cl_std_EQ) && ty

[PATCH] D104800: [OpenCL] Do not include default header for preprocessor output as input

2021-06-23 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

I am not quite sure about whether "-fdeclare-opencl-builtins" should be kept 
when input is preprocessor output. Suggestions? Thanks.


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

https://reviews.llvm.org/D104800

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


[PATCH] D100118: [clang] Add support for new builtin __arithmetic_fence to control floating point optimization, and new clang option fprotect-parens

2021-06-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/AST/arithmetic-fence-builtin.c:34
+
+  v = (a + b);
+

aaron.ballman wrote:
> Does the `(a + b)` still have an AST node for the `ParenExpr`?
Nevermind, it won't, it'll have the `CallExpr` node.

I think this may be somewhat surprising to folks who use AST matchers or 
`-ast-print`, but I'm not certain that there's a better way to implement this 
that would keep the `ParenExpr` in the AST for full source fidelity, so I think 
this is reasonable enough.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100118

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


[PATCH] D104058: ThinLTO: Fix inline assembly references to static functions with CFI

2021-06-23 Thread Sami Tolvanen 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 rGe3d24b45b8f8: ThinLTO: Fix inline assembly references to 
static functions with CFI (authored by samitolvanen).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104058

Files:
  llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
  llvm/test/Transforms/ThinLTOBitcodeWriter/cfi-icall-static-inline-asm.ll


Index: llvm/test/Transforms/ThinLTOBitcodeWriter/cfi-icall-static-inline-asm.ll
===
--- /dev/null
+++ llvm/test/Transforms/ThinLTOBitcodeWriter/cfi-icall-static-inline-asm.ll
@@ -0,0 +1,19 @@
+; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o - %s | llvm-modextract -b -n 
0 -o - | llvm-dis | FileCheck %s
+
+; CHECK: @a = internal alias {{.*}}@a.[[HASH:[0-9a-f]+]]
+
+define void @b() {
+  %f = alloca void ()*, align 8
+  ; CHECK: store{{.*}} @a.[[HASH]],{{.*}} %f
+  store void ()* @a, void ()** %f, align 8
+  ; CHECK: %1 = call void ()* asm sideeffect "leaq a(%rip)
+  %1 = call void ()* asm sideeffect "leaq a(%rip), $0\0A\09", 
"=r,~{dirflag},~{fpsr},~{flags}"()
+  ret void
+}
+
+; CHECK: define{{.*}} @a.[[HASH]](){{.*}} !type
+define internal void @a() !type !0 {
+  ret void
+}
+
+!0 = !{i64 0, !"typeid1"}
Index: llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
===
--- llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
+++ llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
@@ -55,6 +55,7 @@
   }
 }
 
+std::string OldName = Name.str();
 std::string NewName = (Name + ModuleId).str();
 
 if (const auto *C = ExportGV.getComdat())
@@ -69,6 +70,15 @@
   ImportGV->setName(NewName);
   ImportGV->setVisibility(GlobalValue::HiddenVisibility);
 }
+
+if (Function *F = dyn_cast(&ExportGV)) {
+  // Create a local alias with the original name to avoid breaking
+  // references from inline assembly.
+  GlobalAlias *A = GlobalAlias::create(
+  F->getValueType(), F->getAddressSpace(), 
GlobalValue::InternalLinkage,
+  OldName, F, &ExportM);
+  appendToCompilerUsed(ExportM, A);
+}
   }
 
   if (!RenamedComdats.empty())


Index: llvm/test/Transforms/ThinLTOBitcodeWriter/cfi-icall-static-inline-asm.ll
===
--- /dev/null
+++ llvm/test/Transforms/ThinLTOBitcodeWriter/cfi-icall-static-inline-asm.ll
@@ -0,0 +1,19 @@
+; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o - %s | llvm-modextract -b -n 0 -o - | llvm-dis | FileCheck %s
+
+; CHECK: @a = internal alias {{.*}}@a.[[HASH:[0-9a-f]+]]
+
+define void @b() {
+  %f = alloca void ()*, align 8
+  ; CHECK: store{{.*}} @a.[[HASH]],{{.*}} %f
+  store void ()* @a, void ()** %f, align 8
+  ; CHECK: %1 = call void ()* asm sideeffect "leaq a(%rip)
+  %1 = call void ()* asm sideeffect "leaq a(%rip), $0\0A\09", "=r,~{dirflag},~{fpsr},~{flags}"()
+  ret void
+}
+
+; CHECK: define{{.*}} @a.[[HASH]](){{.*}} !type
+define internal void @a() !type !0 {
+  ret void
+}
+
+!0 = !{i64 0, !"typeid1"}
Index: llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
===
--- llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
+++ llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
@@ -55,6 +55,7 @@
   }
 }
 
+std::string OldName = Name.str();
 std::string NewName = (Name + ModuleId).str();
 
 if (const auto *C = ExportGV.getComdat())
@@ -69,6 +70,15 @@
   ImportGV->setName(NewName);
   ImportGV->setVisibility(GlobalValue::HiddenVisibility);
 }
+
+if (Function *F = dyn_cast(&ExportGV)) {
+  // Create a local alias with the original name to avoid breaking
+  // references from inline assembly.
+  GlobalAlias *A = GlobalAlias::create(
+  F->getValueType(), F->getAddressSpace(), GlobalValue::InternalLinkage,
+  OldName, F, &ExportM);
+  appendToCompilerUsed(ExportM, A);
+}
   }
 
   if (!RenamedComdats.empty())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4a14206 - [AIX] Emitting diagnostics error for profile options

2021-06-23 Thread Whitney Tsang via cfe-commits

Author: Whitney Tsang
Date: 2021-06-23T18:17:40Z
New Revision: 4a14206522384f5868227145a6598f41710e6c91

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

LOG: [AIX] Emitting diagnostics error for profile options

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/unsupported-option.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index b358813a1a017..aae56c8e87e3b 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -776,6 +776,21 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, 
Compilation &C,
   options::OPT_fprofile_instr_generate,
   options::OPT_fprofile_instr_generate_EQ,
   options::OPT_fno_profile_instr_generate);
+
+  if (TC.getTriple().isOSAIX()) {
+if (PGOGenerateArg)
+  if (!D.isUsingLTO(false /*IsDeviceOffloadAction */) ||
+  D.getLTOMode() != LTOK_Full)
+D.Diag(clang::diag::err_drv_argument_only_allowed_with)
+<< PGOGenerateArg->getSpelling() << "-flto";
+if (ProfileGenerateArg)
+  D.Diag(diag::err_drv_unsupported_opt_for_target)
+  << ProfileGenerateArg->getSpelling() << TC.getTriple().str();
+if (Arg *ProfileSampleUseArg = getLastProfileSampleUseArg(Args))
+  D.Diag(diag::err_drv_unsupported_opt_for_target)
+  << ProfileSampleUseArg->getSpelling() << TC.getTriple().str();
+  } 
+
   if (ProfileGenerateArg &&
   ProfileGenerateArg->getOption().matches(
   options::OPT_fno_profile_instr_generate))

diff  --git a/clang/test/Driver/unsupported-option.c 
b/clang/test/Driver/unsupported-option.c
index d0611977a99e1..91b6b585a36e7 100644
--- a/clang/test/Driver/unsupported-option.c
+++ b/clang/test/Driver/unsupported-option.c
@@ -1,7 +1,20 @@
 // RUN: not %clang %s --hedonism -### 2>&1 | \
 // RUN: FileCheck %s
+// CHECK: error: unsupported option '--hedonism'
+
 // RUN: not %clang %s --hell -### 2>&1 | \
 // RUN: FileCheck %s --check-prefix=DID-YOU-MEAN
-
-// CHECK: error: unsupported option '--hedonism'
 // DID-YOU-MEAN: error: unsupported option '--hell'; did you mean '--help'?
+
+// RUN: not %clang -fprofile-instr-generate -fprofile-sample-use=code.prof 
--target=powerpc-ibm-aix %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=INVALID-AIX-PROFILE
+// INVALID-AIX-PROFILE-DAG: error: unsupported option 
'-fprofile-instr-generate' for target
+// INVALID-AIX-PROFILE-DAG: error: unsupported option '-fprofile-sample-use=' 
for target
+
+// RUN: not %clang -fprofile-generate --target=powerpc-ibm-aix %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=AIX-PROFILE-LTO
+// AIX-PROFILE-LTO: error: invalid argument '-fprofile-generate' only allowed 
with '-flto'
+
+// RUN: not %clang -fprofile-generate -flto=thin --target=powerpc-ibm-aix %s 
2>&1 | \
+// RUN: FileCheck %s --check-prefix=AIX-PROFILE-THINLTO
+// AIX-PROFILE-THINLTO: error: invalid argument '-fprofile-generate' only 
allowed with '-flto'



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


[PATCH] D104505: [HIP] Defer operator overloading errors

2021-06-23 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/test/SemaCUDA/deferred-oeverload.cu:55
  callee3(); // dev-error {{no matching function for call to 'callee3'}}
  callee4(); // com-error {{no matching function for call to 'callee4'}}
+ S s;

tra wrote:
> If we're allowing to postpone an invalid call of a host function, shouldn't 
> we also allow postponing other errors? 
> E.g. should we postpone the error on an attempt to call `callee4()` ?
> Similarly, if we were to call a `undeclared_func()` here, should the error 
> also be postponed?
> 
> TBH, I don't quite understand now how to tell what is and isn't supposed to 
> be deferred with `-fgpu-defer-diags`.
> Is there a clear criteria what should and should not be deferred?
> 
We discussed about what diagnostics to be deferred before. We do not want to 
defer all diagnostics since nvcc apparently only ignores host/device related 
diagnostics. Our previous conclusion is to defer overloading resolution related 
diagnostics when the full candidates set include host device functions or 
wrong-sided candidates. This roughly matches nvcc's behavior.


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

https://reviews.llvm.org/D104505

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


[PATCH] D104777: PR50767: clear non-distinct debuginfo for function with nodebug definition after undecorated declaration

2021-06-23 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D104777#2836327 , @aaron.ballman 
wrote:

> In D104777#2835965 , @dblaikie 
> wrote:
>
>> @aaron.ballman Do we have attributes/infrastructure for attributes that have 
>> to be the same from their first declaration or at least from their first 
>> call? I'm wondering if it might be simpler/better to require nodebug to be 
>> provided earlier, rather than fixing it up after the fact like this.
>>
>> (for instance, requiring it to be attributed on the declaration would ensure 
>> we don't create call_site descriptions for calls to nodebug functions - 
>> which would save some debug info size)
>
> We don't have any attributes that have to be the same "from their first call" 
> that I'm aware of. But we do have attributes that need to be the same on all 
> declarations. IIRC, the `section` and `code_seg` attributes both have to be 
> specified on the initial declaration in some circumstances, and 
> `[[noreturn]]` needs to be on the first declaration we see. We don't have any 
> tablegen machinery to enforce this, the logic needs to be manually written. I 
> think it'd live somewhere around `Sema::mergeDeclAttributes()` or 
> `Sema::MergeFunctionDecl()` most likely.

Yeah, all that sounds reasonable to me - @brunodefraine could you look into 
supporting nodebug in a similar way as @aaron.ballman has described here?

> Fixing up after the fact would be a bit strange though. A declaration is 
> typically considered marked by an attribute from the point of declaration 
> including the attribute onward, not backwards. e.g., 
> https://godbolt.org/z/4E1Ya764n I won't say we *never* do this back 
> propagation, but I would say it's a sign that the attribute is venturing into 
> novel, perhaps dangerous territory. For example with this patch, an AST 
> matcher won't see the `nodebug` attribute on the initial declaration of 
> `t1()` and so it won't react to it the same way that codegen is being changed.

Yeah, fair concerns for sure - thanks for the tips!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104777

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


[PATCH] D104082: [CodeGen] Don't create a fake FunctionDecl when generating block/block_byref copy/dispose helper functions

2021-06-23 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D104082#2835496 , @fhahn wrote:

> In D104082#2835080 , @zequanwu 
> wrote:
>
>> Hi, this caused compiler crash with error "Assertion 
>> `cast(Scope)->describes(&MF->getFunction())' failed." on iOS 
>> platforms.  So, I reverted it.
>> I'm working on a reduced repro.
>
> FYI this also caused a failure on GreenDragon, with `-verify-machineinstrs`: 
> https://green.lab.llvm.org/green/job/test-suite-verify-machineinstrs-aarch64-O0-g/9663/consoleFull#-134330334249ba4694-19c4-4d7e-bec5-911270d8a58c
>
> The failure should be re-producible by building the following C++ file from 
> llvm-test-suite:
>
>   bin/clang++  -DNDEBUG  -B 
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
> -Wno-unused-command-line-argument -mllvm -verify-machineinstrs -O0 -g 
> -arch arm64 -isysroot 
> /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk
>-w -Werror=date-time -MD -MT 
> SingleSource/UnitTests/CMakeFiles/block-byref-cxxobj-test.dir/block-byref-cxxobj-test.cpp.o
>  -MF 
> SingleSource/UnitTests/CMakeFiles/block-byref-cxxobj-test.dir/block-byref-cxxobj-test.cpp.o.d
>  -o 
> SingleSource/UnitTests/CMakeFiles/block-byref-cxxobj-test.dir/block-byref-cxxobj-test.cpp.o
>  -c 
> /Users/buildslave/jenkins/workspace/test-suite-verify-machineinstrs-aarch64-O0-g/test-suite/SingleSource/UnitTests/block-byref-cxxobj-test.cpp

Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104082

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


[PATCH] D104800: [OpenCL] Do not include default header for preprocessor output as input

2021-06-23 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D104800#2836594 , @yaxunl wrote:

> I am not quite sure about whether "-fdeclare-opencl-builtins" should be kept 
> when input is preprocessor output. Suggestions? Thanks.

The question is that whether those builtins declared through 
"-fdeclare-opencl-builtins" will be in preprocessor expansion output. It seems 
not. If so, we still need "-fdeclare-opencl-builtins" when input type is 
preprocessor expansion output.


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

https://reviews.llvm.org/D104800

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


[PATCH] D104790: [x86] fix mm*_undefined* intrinsics to use arbitrary frozen bit pattern

2021-06-23 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

We may want to update the code in X86ISelLowering getAVX2GatherNode and 
getGatherNode to replace freeze+poison on Src with a zero vector. We already do 
this when the Src is undef.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104790

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


[PATCH] D104803: [AIX] Emitting diagnostics error for profile options

2021-06-23 Thread Whitney Tsang via Phabricator via cfe-commits
Whitney created this revision.
Whitney added reviewers: hubert.reinterpretcast, etiotto, bmahjour, kbarton, 
daltenty.
Whitney added a project: LLVM.
Whitney requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Only LLVM-based instrumentation profile is supported on AIX.
And it currently must be used with full LTO.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104803

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/unsupported-option.c


Index: clang/test/Driver/unsupported-option.c
===
--- clang/test/Driver/unsupported-option.c
+++ clang/test/Driver/unsupported-option.c
@@ -1,7 +1,20 @@
 // RUN: not %clang %s --hedonism -### 2>&1 | \
 // RUN: FileCheck %s
+// CHECK: error: unsupported option '--hedonism'
+
 // RUN: not %clang %s --hell -### 2>&1 | \
 // RUN: FileCheck %s --check-prefix=DID-YOU-MEAN
-
-// CHECK: error: unsupported option '--hedonism'
 // DID-YOU-MEAN: error: unsupported option '--hell'; did you mean '--help'?
+
+// RUN: not %clang -fprofile-instr-generate -fprofile-sample-use=code.prof 
--target=powerpc-ibm-aix %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=INVALID-AIX-PROFILE
+// INVALID-AIX-PROFILE-DAG: error: unsupported option 
'-fprofile-instr-generate' for target
+// INVALID-AIX-PROFILE-DAG: error: unsupported option '-fprofile-sample-use=' 
for target
+
+// RUN: not %clang -fprofile-generate --target=powerpc-ibm-aix %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=AIX-PROFILE-LTO
+// AIX-PROFILE-LTO: error: invalid argument '-fprofile-generate' only allowed 
with '-flto'
+
+// RUN: not %clang -fprofile-generate -flto=thin --target=powerpc-ibm-aix %s 
2>&1 | \
+// RUN: FileCheck %s --check-prefix=AIX-PROFILE-THINLTO
+// AIX-PROFILE-THINLTO: error: invalid argument '-fprofile-generate' only 
allowed with '-flto'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -776,6 +776,21 @@
   options::OPT_fprofile_instr_generate,
   options::OPT_fprofile_instr_generate_EQ,
   options::OPT_fno_profile_instr_generate);
+
+  if (TC.getTriple().isOSAIX()) {
+if (PGOGenerateArg)
+  if (!D.isUsingLTO(false /*IsDeviceOffloadAction */) ||
+  D.getLTOMode() != LTOK_Full)
+D.Diag(clang::diag::err_drv_argument_only_allowed_with)
+<< PGOGenerateArg->getSpelling() << "-flto";
+if (ProfileGenerateArg)
+  D.Diag(diag::err_drv_unsupported_opt_for_target)
+  << ProfileGenerateArg->getSpelling() << TC.getTriple().str();
+if (Arg *ProfileSampleUseArg = getLastProfileSampleUseArg(Args))
+  D.Diag(diag::err_drv_unsupported_opt_for_target)
+  << ProfileSampleUseArg->getSpelling() << TC.getTriple().str();
+  } 
+
   if (ProfileGenerateArg &&
   ProfileGenerateArg->getOption().matches(
   options::OPT_fno_profile_instr_generate))


Index: clang/test/Driver/unsupported-option.c
===
--- clang/test/Driver/unsupported-option.c
+++ clang/test/Driver/unsupported-option.c
@@ -1,7 +1,20 @@
 // RUN: not %clang %s --hedonism -### 2>&1 | \
 // RUN: FileCheck %s
+// CHECK: error: unsupported option '--hedonism'
+
 // RUN: not %clang %s --hell -### 2>&1 | \
 // RUN: FileCheck %s --check-prefix=DID-YOU-MEAN
-
-// CHECK: error: unsupported option '--hedonism'
 // DID-YOU-MEAN: error: unsupported option '--hell'; did you mean '--help'?
+
+// RUN: not %clang -fprofile-instr-generate -fprofile-sample-use=code.prof --target=powerpc-ibm-aix %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=INVALID-AIX-PROFILE
+// INVALID-AIX-PROFILE-DAG: error: unsupported option '-fprofile-instr-generate' for target
+// INVALID-AIX-PROFILE-DAG: error: unsupported option '-fprofile-sample-use=' for target
+
+// RUN: not %clang -fprofile-generate --target=powerpc-ibm-aix %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=AIX-PROFILE-LTO
+// AIX-PROFILE-LTO: error: invalid argument '-fprofile-generate' only allowed with '-flto'
+
+// RUN: not %clang -fprofile-generate -flto=thin --target=powerpc-ibm-aix %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=AIX-PROFILE-THINLTO
+// AIX-PROFILE-THINLTO: error: invalid argument '-fprofile-generate' only allowed with '-flto'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -776,6 +776,21 @@
   options::OPT_fprofile_instr_generate,
   options::OPT_fprofile_instr_generate_EQ,
   options::OPT_fno_profile_instr_generate);
+
+  if (TC.getTriple().isOSAIX()) {
+if (PGOGenerateArg)
+  if (!D.isUsingLTO(false /*IsDeviceOffloadAction */) ||
+  D.getLTOMode() != LTOK_Full)
+D.Diag(clang::d

[PATCH] D104774: [clang-format] Fix a bug that indents else-comment-if incorrectly

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

That was fast. I personally like it better to give others a chance to look at. 
;)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104774

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


  1   2   >