[PATCH] D139686: [lsan] Add lsan support for loongarch64

2022-12-09 Thread Youling Tang via Phabricator via cfe-commits
tangyouling updated this revision to Diff 481533.
tangyouling added a comment.

- Separate leak_check_segv.cpp modification.
- Add some comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139686

Files:
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/fsanitize.c
  compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
  compiler-rt/lib/lsan/lsan_common.cpp
  compiler-rt/lib/lsan/lsan_common.h
  compiler-rt/test/asan/lit.cfg.py
  compiler-rt/test/lsan/TestCases/swapcontext.cpp
  compiler-rt/test/lsan/TestCases/use_registers.cpp
  compiler-rt/test/lsan/lit.common.cfg.py

Index: compiler-rt/test/lsan/lit.common.cfg.py
===
--- compiler-rt/test/lsan/lit.common.cfg.py
+++ compiler-rt/test/lsan/lit.common.cfg.py
@@ -74,9 +74,9 @@
 config.substitutions.append( ("%clangxx_lsan ", build_invocation(clang_lsan_cxxflags)) )
 
 # LeakSanitizer tests are currently supported on
-# Android{aarch64, x86, x86_64}, x86-64 Linux, PowerPC64 Linux, arm Linux, mips64 Linux, s390x Linux and x86_64 Darwin.
+# Android{aarch64, x86, x86_64}, x86-64 Linux, PowerPC64 Linux, arm Linux, mips64 Linux, s390x Linux, loongarch64 Linux and x86_64 Darwin.
 supported_android = config.android and config.target_arch in ['x86_64', 'i386', 'aarch64'] and 'android-thread-properties-api' in config.available_features
-supported_linux = (not config.android) and config.host_os == 'Linux' and config.host_arch in ['aarch64', 'x86_64', 'ppc64', 'ppc64le', 'mips64', 'riscv64', 'arm', 'armhf', 'armv7l', 's390x']
+supported_linux = (not config.android) and config.host_os == 'Linux' and config.host_arch in ['aarch64', 'x86_64', 'ppc64', 'ppc64le', 'mips64', 'riscv64', 'arm', 'armhf', 'armv7l', 's390x', 'loongarch64']
 supported_darwin = config.host_os == 'Darwin' and config.target_arch in ['x86_64']
 supported_netbsd = config.host_os == 'NetBSD' and config.target_arch in ['x86_64', 'i386']
 if not (supported_android or supported_linux or supported_darwin or supported_netbsd):
Index: compiler-rt/test/lsan/TestCases/use_registers.cpp
===
--- compiler-rt/test/lsan/TestCases/use_registers.cpp
+++ compiler-rt/test/lsan/TestCases/use_registers.cpp
@@ -43,6 +43,8 @@
   "mov x14, %0"
   :
   : "r"(p));
+#elif defined(__loongarch_lp64)
+  asm("move $s8, %0" : : "r"(p));
 #elif defined(__powerpc__)
   asm("mr 30, %0"
   :
Index: compiler-rt/test/lsan/TestCases/swapcontext.cpp
===
--- compiler-rt/test/lsan/TestCases/swapcontext.cpp
+++ compiler-rt/test/lsan/TestCases/swapcontext.cpp
@@ -5,7 +5,7 @@
 // RUN: %env_lsan_opts= %run %t 2>&1
 // RUN: %env_lsan_opts= not %run %t foo 2>&1 | FileCheck %s
 // Missing 'getcontext' and 'makecontext' on Android.
-// UNSUPPORTED: arm,aarch64,powerpc64,android
+// UNSUPPORTED: arm,aarch64,loongarch64,powerpc64,android
 
 #include "sanitizer_common/sanitizer_ucontext.h"
 #include 
Index: compiler-rt/test/asan/lit.cfg.py
===
--- compiler-rt/test/asan/lit.cfg.py
+++ compiler-rt/test/asan/lit.cfg.py
@@ -202,7 +202,7 @@
 
 # Turn on leak detection on 64-bit Linux.
 leak_detection_android = config.android and 'android-thread-properties-api' in config.available_features and (config.target_arch in ['x86_64', 'i386', 'i686', 'aarch64'])
-leak_detection_linux = (config.host_os == 'Linux') and (not config.android) and (config.target_arch in ['x86_64', 'i386', 'riscv64'])
+leak_detection_linux = (config.host_os == 'Linux') and (not config.android) and (config.target_arch in ['x86_64', 'i386', 'riscv64', 'loongarch64'])
 leak_detection_mac = (config.host_os == 'Darwin') and (config.apple_platform == 'osx')
 leak_detection_netbsd = (config.host_os == 'NetBSD') and (config.target_arch in ['x86_64', 'i386'])
 if leak_detection_android or leak_detection_linux or leak_detection_mac or leak_detection_netbsd:
Index: compiler-rt/lib/lsan/lsan_common.h
===
--- compiler-rt/lib/lsan/lsan_common.h
+++ compiler-rt/lib/lsan/lsan_common.h
@@ -42,6 +42,8 @@
 #  define CAN_SANITIZE_LEAKS 1
 #elif defined(__arm__) && SANITIZER_LINUX
 #  define CAN_SANITIZE_LEAKS 1
+#elif SANITIZER_LOONGARCH64 && SANITIZER_LINUX
+#  define CAN_SANITIZE_LEAKS 1
 #elif SANITIZER_RISCV64 && SANITIZER_LINUX
 #  define CAN_SANITIZE_LEAKS 1
 #elif SANITIZER_NETBSD || SANITIZER_FUCHSIA
Index: compiler-rt/lib/lsan/lsan_common.cpp
===
--- compiler-rt/lib/lsan/lsan_common.cpp
+++ compiler-rt/lib/lsan/lsan_common.cpp
@@ -277,6 +277,9 @@
 #  elif defined(__aarch64__)
   // Accept up to 48 bit VMA.
   return ((p >> 48) == 0);
+#  elif defined(__loongarch_lp64)
+  // Allow 47-bit user-space VMA at current

[PATCH] D139686: [lsan] Add lsan support for loongarch64

2022-12-09 Thread Lu Weining via Phabricator via cfe-commits
SixWeining added inline comments.



Comment at: compiler-rt/test/lsan/TestCases/swapcontext.cpp:8
 // Missing 'getcontext' and 'makecontext' on Android.
-// UNSUPPORTED: arm,aarch64,powerpc64,android
+// UNSUPPORTED: arm,aarch64,loongarch64,powerpc64,android
 

Why we are here? For the same reason as `Android` mentioned above?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139686

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


[PATCH] D139444: [ZOS] Convert tests to check 'target={{.*}}-zos'

2022-12-09 Thread Ulrich Weigand via Phabricator via cfe-commits
uweigand added a comment.

In D139444#3982205 , @probinson wrote:

> If you can tell me the `platform.system()` value to look for to detect z/OS, 
> I can do that.

I don't know - this value is defined by the Python implementation on z/OS.  On 
most platforms, this matches the value returned by "uname -s", but I don't know 
what this is on z/OS either.


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

https://reviews.llvm.org/D139444

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


[PATCH] D138807: [RISCV] Support vector crypto extension ISA string and assembly

2022-12-09 Thread Brandon Wu via Phabricator via cfe-commits
4vtomat updated this revision to Diff 481540.
4vtomat added a comment.

Address Eric Gouriou's comments, thanks for reviewing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138807

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVInstrFormats.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVInstrInfoV.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZvk.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rvv/rv64zvkb.s
  llvm/test/MC/RISCV/rvv/rv64zvkg.s
  llvm/test/MC/RISCV/rvv/rv64zvknha.s
  llvm/test/MC/RISCV/rvv/rv64zvknhb.s
  llvm/test/MC/RISCV/rvv/rv64zvkns.s
  llvm/test/MC/RISCV/rvv/rv64zvksed.s
  llvm/test/MC/RISCV/rvv/rv64zvksh.s

Index: llvm/test/MC/RISCV/rvv/rv64zvksh.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvv/rv64zvksh.s
@@ -0,0 +1,21 @@
+# RUN: llvm-mc -triple=riscv64 -show-encoding --mattr=+experimental-zvksh %s \
+# RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv64 -show-encoding %s 2>&1 \
+# RUN:| FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv64 -filetype=obj --mattr=+experimental-zvksh %s \
+# RUN:| llvm-objdump -d --mattr=+experimental-zvksh  - \
+# RUN:| FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv64 -filetype=obj --mattr=+experimental-zvksh %s \
+# RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
+
+vsm3c.vi v10, v9, 7
+# CHECK-INST: vsm3c.vi v10, v9, 7
+# CHECK-ENCODING: [0x77,0xa5,0x93,0xae]
+# CHECK-ERROR: instruction requires the following: 'Zvksh'
+# CHECK-UNKNOWN: 77 a5 93 ae   
+
+vsm3me.vv v10, v9, v8
+# CHECK-INST: vsm3me.vv v10, v9, v8
+# CHECK-ENCODING: [0x77,0x25,0x94,0x82]
+# CHECK-ERROR: instruction requires the following: 'Zvksh'
+# CHECK-UNKNOWN: 77 25 94 82   
Index: llvm/test/MC/RISCV/rvv/rv64zvksed.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvv/rv64zvksed.s
@@ -0,0 +1,21 @@
+# RUN: llvm-mc -triple=riscv64 -show-encoding --mattr=+experimental-zvksed %s \
+# RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv64 -show-encoding %s 2>&1 \
+# RUN:| FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv64 -filetype=obj --mattr=+experimental-zvksed %s \
+# RUN:| llvm-objdump -d --mattr=+experimental-zvksed  - \
+# RUN:| FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv64 -filetype=obj --mattr=+experimental-zvksed %s \
+# RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
+
+vsm4k.vi v10, v9, 7
+# CHECK-INST: vsm4k.vi v10, v9, 7
+# CHECK-ENCODING: [0x77,0xa5,0x93,0x86]
+# CHECK-ERROR: instruction requires the following: 'Zvksed'
+# CHECK-UNKNOWN: 77 a5 93 86   
+
+vsm4r.vv v10, v9
+# CHECK-INST: vsm4r.vv v10, v9
+# CHECK-ENCODING: [0x77,0x25,0x98,0xa2]
+# CHECK-ERROR: instruction requires the following: 'Zvksed'
+# CHECK-UNKNOWN: 77 25 98 a2   
Index: llvm/test/MC/RISCV/rvv/rv64zvkns.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvv/rv64zvkns.s
@@ -0,0 +1,75 @@
+# RUN: llvm-mc -triple=riscv64 -show-encoding --mattr=+experimental-zvkns %s \
+# RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv64 -show-encoding %s 2>&1 \
+# RUN:| FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv64 -filetype=obj --mattr=+experimental-zvkns %s \
+# RUN:| llvm-objdump -d --mattr=+experimental-zvkns  - \
+# RUN:| FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv64 -filetype=obj --mattr=+experimental-zvkns %s \
+# RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
+
+vaesdf.vv v10, v9
+# CHECK-INST: vaesdf.vv v10, v9
+# CHECK-ENCODING: [0x77,0xa5,0x90,0xa2]
+# CHECK-ERROR: instruction requires the following: 'Zvkns'
+# CHECK-UNKNOWN: 77 a5 90 a2   
+
+vaesdf.vs v10, v9
+# CHECK-INST: vaesdf.vs v10, v9
+# CHECK-ENCODING: [0x77,0xa5,0x90,0xa6]
+# CHECK-ERROR: instruction requires the following: 'Zvkns'
+# CHECK-UNKNOWN: 77 a5 90 a6   
+
+vaesef.vv v10, v9
+# CHECK-INST: vaesef.vv v10, v9
+# CHECK-ENCODING: [0x77,0xa5,0x91,0xa2]
+# CHECK-ERROR: instruction requires the following: 'Zvkns'
+# CHECK-UNKNOWN: 77 a5 91 a2   
+   
+vaesef.vs v10, v9
+# CHECK-INST: vaesef.vs v10, v9
+# CHECK-ENCODING: [0x77,0xa5,0x91,0xa6]
+# CHECK-ERROR: instruction re

[PATCH] D134410: [clang][CodeGen] Add noundef metadata to load instructions (preliminary 1 or 5)

2022-12-09 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

In D134410#3898615 , @nlopes wrote:

> In D134410#3898563 , @nikic wrote:
>
>> FWIW, I don't agree with this. It's fine to change load semantics, as long 
>> as bitcode autoupgrade is handled correctly. I'd go even further and say 
>> that at least long term, any solution that does not have a plain `load` 
>> instruction return `poison` for uninitialized memory will be a maintenance 
>> mess.
>>
>> I think the core problem that prevents us from moving in this direction is 
>> that we have no way to represent a frozen load at all (as `freeze(load)` 
>> will propagate poison before freezing). If I understand correctly, you're 
>> trying to solve this by making *all* loads frozen loads, and use `load 
>> !noundef` to allow dropping the freeze. I think this would be a very bad 
>> outcome, especially as we're going to lose that `!noundef` on most load 
>> speculations, and I don't think we want to be introducing freezes when 
>> speculating loads (e.g. during LICM).
>>
>> I expect that the path of least resistance is going to be to support bitwise 
>> poison for load/store/phi/select and promote it to full-value poison on any 
>> other operation, allowing a freezing load to be expressed as `freeze(load)`.
>>
>> Please let me know if I completely misunderstood the scheme you have in 
>> mind...
>
> You got it right. But the load we propose is not exactly a freezing load. It 
> only returns `freeze poison` for uninit memory. It doesn't freeze stored 
> values.
> If we introduce a `!uninit_is_poison` flag, we can drop !noundef when 
> hoisting and add `!uninit_is_poison` instead (it's implied by !noundef).
>
> The question is what's the default for uninit memory: `freeze poison` or 
> `poison`? But I think we need both. And since we need both (unless we add a 
> freezing load or bitwise poison), why not keep a behavior closer to the 
> current?
> A freezing load is worse as a store+load needs to be forwarded though a 
> freeze, as the load is not a NOP anymore.
>
> Bitwise poison would be nice, but I don't know how to make it work. To make 
> it work with bit-fields, we would need and/or to propagate poison bit-wise as 
> well. But then we will break optimizations that transform between those and 
> arithmetic. Then you start wanting that add/mul/etc also propagate poison 
> bit-wise and then I don't know how to specify that semantics.  (if you want, 
> I can forward you a proposal we wrote a few years ago, but we never managed 
> to make sound, so it was never presented in public)
>
> I agree that bit-wise poison for loads sounds appealing (for bit fields, load 
> widening, etc), but without support in the rest of the IR, it's not worth 
> much. If it becomes value-wise in the 1st operation, then I don't think we 
> gain any expressivity.

I think the gain in expressiveness is that we can write something like 
`freeze(load)`. For example, D138766  
currently proposes to use a silly pattern like `bitcast(freeze(load(<4 x i8>)) 
to i32)` to achieve a "frozen load", because there is no other way to express 
it right now.

The other problem I see here is that we still need to do something about the 
memcpy -> load/store fold. As soon as we have poison from uninit values (either 
directly or via `!uninit_is_poison`) this will start causing miscompiles very 
quickly. The only way to do this right now is again with an `` vector 
load/store, which still optimizes terribly. This needs either load+store of 
integer to preserve poison, or again some form of byte type.

Something I've only recently realized is that we also run into this problem 
when inserting spurious load/store pairs, e.g. as done by LICM scalar 
promotion. If we're promoting say an i32 value to scalar that previously used a 
conditional store, then promotion will now introduce an unconditional load and 
store, which will spread poison from individual bytes. So that means that 
technically scalar promotion (and SimplifyCFG store speculation) also need to 
do some special dance to preserve poison. And without preservation of poison 
across load/store/phi in plain ints, this is going to be a bad optimization 
outcome either way: We'd have to use either a vector of i8 or a byte type for 
the inserted phi nodes and only cast to integer and back when manipulating the 
value, which would probably defeat the optimization. At that point probably 
best to freeze the first load (which again needs a freezing load).

(We should probably move the discussion around this patch series to discourse.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134410

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


[PATCH] D137058: [Driver] [Modules] Support -fmodule-output (1/2)

2022-12-09 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

thanks all for the patience on this one - and for the collaborative discussion 
- I do think the outcome is going to be an easier to remember option name ;)


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

https://reviews.llvm.org/D137058

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


[PATCH] D138861: [Clang] Implement CWG2640 Allow more characters in an n-char sequence

2022-12-09 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

Thanks Tom, I replied to your comments




Comment at: clang/lib/Lex/Lexer.cpp:3378-3379
 
-  if (LooseMatch)
+  // If no diagnostic has been emitted yet we do not want to recover here
+  // to make sure this function will be called again and a diagnostic emitted 
then.
+  if (LooseMatch && Diagnose)

tahonermann wrote:
> I'm having a hard time understanding what this comment is trying to convey. 
> The comment response to Aaron was much more helpful to me. How about this 
> suggested edit?
It's not that a diagnostic would be emitted twice, is that it would not be 
emitted at all.
By recovering - ie returning a loose match - we prevent the function to be 
called again on the same buffer.
So if during the first call Diagnose is false (because we were called from a 
try function), then the compilation will continue assuming we were in fact 
able to parse an identifier and never informs us of an invalid name.



Comment at: clang/lib/Lex/Lexer.cpp:3386
+
+  if (!Result || CurPtr - StartPtr == (ptrdiff_t)(Buffer.size() + 4))
 StartPtr = CurPtr;

tahonermann wrote:
> This is a bit of a tangent, but under what circumstances would `CurPtr - 
> StartPtr` not be equal to `Buffer.size() + 4`? Actually, I'm not sure that +4 
> is correct. It looks like `StartPtr` is expected to point to `N` at the 
> beginning of the function, so the initial `\` is not included in the range. 
> If `N` isn't seen, the function returns early. Likewise, if either of the `{` 
> or `}` delimiters is not found, the function returns early.
> 
> I think the goal of this code is to skip the `getAndAdvanceChar()` machinery 
> when the buffer is being claimed (no need to parse UCNs or trigraphs in the 
> character name), but it looks like, particularly with this DR, that we might 
> always be able to do that.
afaict, 4 is correct here because we are one past-the-end.
I do however agree that this whole pattern which is used a few times is 
probably unnecessary, i do think it would be good to investigate. Not in this 
patch though, imo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138861

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


[PATCH] D137051: [Clang] Allow additional mathematical symbols in identifiers.

2022-12-09 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D137051#3982833 , @tahonermann 
wrote:

> Oh, also, the review summary mentions "UAX32" (twice); those should be 
> "UAX31". Just please make sure the commit message is correct.
>
> Also, I'm terribly sorry for being so slow to get this reviewed!

I'm glad you noticed that...!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137051

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


[PATCH] D137058: [Driver] [Modules] Support -fmodule-output (1/2)

2022-12-09 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D137058#3983687 , @iains wrote:

> thanks all for the patience on this one - and for the collaborative 
> discussion - I do think the outcome is going to be an easier to remember 
> option name ;)

Yeah. Thanks for your suggestion too. Otherwise I guess we won't get back : )


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

https://reviews.llvm.org/D137058

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


[PATCH] D139627: clang/X86: Don't emit "min-legal-vector-width"="0"

2022-12-09 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

In D139627#3982387 , @arsenm wrote:

> In D139627#3982385 , @arsenm wrote:
>
>>> [1] `"min-legal-vector-width" = "0"` was clear to indicate there are only 
>>> scalar operations.
>>
>> It's not remotely clear what this means
>
> It also doesn't mean that, because the IR doesn't have to be consistent with 
> the attribute. The IR exists independent of the attribute, and the attribute 
> can only provide performance hints.

I don't agree. There are attributes like `zeroext`, `byref` are ABI related see 
https://llvm.org/docs/LangRef.html#parameter-attributes. I'd take 
`min-legal-vector-width` as a similar one.


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

https://reviews.llvm.org/D139627

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


[PATCH] D112621: [analyzer][solver] Introduce reasoning for not equal to operator

2022-12-09 Thread Manas Gupta via Phabricator via cfe-commits
manas marked 13 inline comments as done.
manas added a comment.

In D112621#3978285 , @steakhal wrote:

> For the test cases where we should be able to prove the case but return 
> `Unknown` instead, should be marked by a FIXME stating the expected value.
> Approximating a concrete value with `Unknown` is (almost) always correct. So, 
> in this case, you don't need to go and fix them unless you want to do the 
> extra mile.

I have added FIXME in `constant-folding.c` test file for now. I will fix it in 
a new review.

I have also opened a Discourse thread 

 on the missing optimization opportunity.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112621

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


[PATCH] D112621: [analyzer][solver] Introduce reasoning for not equal to operator

2022-12-09 Thread Manas Gupta via Phabricator via cfe-commits
manas updated this revision to Diff 481545.
manas added a comment.

Assert over non-empty ranges and add fixme for not handled cases


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112621

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/constant-folding.c

Index: clang/test/Analysis/constant-folding.c
===
--- clang/test/Analysis/constant-folding.c
+++ clang/test/Analysis/constant-folding.c
@@ -281,3 +281,152 @@
 clang_analyzer_eval((b % a) < x + 10); // expected-warning{{TRUE}}
   }
 }
+
+void testDisequalityRules(unsigned int u1, unsigned int u2, unsigned int u3,
+  int s1, int s2, int s3, unsigned char uch,
+  signed char sch, short ssh, unsigned short ush) {
+
+  // Checks for overflowing values
+  if (u1 > INT_MAX && u1 <= UINT_MAX / 2 + 4 && u1 != UINT_MAX / 2 + 2 &&
+  u1 != UINT_MAX / 2 + 3 && s1 >= INT_MIN + 1 && s1 <= INT_MIN + 2) {
+// u1: [INT_MAX+1, INT_MAX+1]U[INT_MAX+4, INT_MAX+4],
+// s1: [INT_MIN+1, INT_MIN+2]
+clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
+  }
+
+  if (u1 >= INT_MIN && u1 <= INT_MIN + 2 &&
+  s1 > INT_MIN + 2 && s1 < INT_MIN + 4) {
+// u1: [INT_MAX+1, INT_MAX+1]U[INT_MAX+4, INT_MAX+4],
+// s1: [INT_MIN+3, INT_MIN+3]
+clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
+  }
+
+  if (s1 < 0 && s1 > -4 && u1 > UINT_MAX - 4 && u1 < UINT_MAX - 1) {
+// s1: [-3, -1], u1: [UINT_MAX - 3, UINT_MAX - 2]
+clang_analyzer_eval(u1 != s1); // expected-warning{{UNKNOWN}}
+  }
+
+  if (s1 < 1 && s1 > -6 && s1 != -4 && s1 != -3 &&
+  u1 > UINT_MAX - 4 && u1 < UINT_MAX - 1) {
+// s1: [-5, -5]U[-2, 0], u1: [UINT_MAX - 3, UINT_MAX - 2]
+clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
+  }
+
+  if (s1 < 1 && s1 > -7 && s1 != -4 && s1 != -3 &&
+  u1 > UINT_MAX - 4 && u1 < UINT_MAX - 1) {
+// s1: [-6, -5]U[-2, 0], u1: [UINT_MAX - 3, UINT_MAX - 2]
+clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
+  }
+
+  if (s1 > 4 && u1 < 4) {
+// s1: [4, INT_MAX], u1: [0, 3]
+clang_analyzer_eval(s1 != u1); // expected-warning{{TRUE}}
+  }
+
+  // Check when RHS is in between two Ranges in LHS
+  if (((u1 >= 1 && u1 <= 2) || (u1 >= 8 && u1 <= 9)) &&
+  u2 >= 5 && u2 <= 6) {
+// u1: [1, 2]U[8, 9], u2: [5, 6]
+clang_analyzer_eval(u1 != u2); // expected-warning{{TRUE}}
+  }
+
+  // Checks for concrete value with same type
+  if (u1 > 1 && u1 < 3 && u2 > 1 && u2 < 3) {
+// u1: [2, 2], u2: [2, 2]
+clang_analyzer_eval(u1 != u2); // expected-warning{{FALSE}}
+  }
+
+  // Check for concrete value with different types
+  if (u1 > 4 && u1 < 6 && s1 > 4 && s1 < 6) {
+// u1: [5, 5], s1: [5, 5]
+clang_analyzer_eval(u1 != s1); // expected-warning{{FALSE}}
+  }
+
+  // Checks when ranges are not overlapping
+  if (u1 <= 10 && u2 >= 20) {
+// u1: [0,10], u2: [20,UINT_MAX]
+clang_analyzer_eval(u1 != u2); // expected-warning{{TRUE}}
+  }
+
+  if (s1 <= INT_MIN + 10 && s2 >= INT_MAX - 10) {
+// s1: [INT_MIN,INT_MIN + 10], s2: [INT_MAX - 10,INT_MAX]
+clang_analyzer_eval(s1 != s2); // expected-warning{{TRUE}}
+  }
+
+  // Checks when ranges are completely overlapping and have more than one point
+  if (u1 >= 20 && u1 <= 50 && u2 >= 20 && u2 <= 50) {
+// u1: [20,50], u2: [20,50]
+clang_analyzer_eval(u1 != u2); // expected-warning{{UNKNOWN}}
+  }
+
+  if (s1 >= -20 && s1 <= 20 && s2 >= -20 && s2 <= 20) {
+// s1: [-20,20], s2: [-20,20]
+clang_analyzer_eval(s1 != s2); // expected-warning{{UNKNOWN}}
+  }
+
+  // Checks when ranges are partially overlapping
+  if (u1 >= 100 && u1 <= 200 && u2 >= 150 && u2 <= 300) {
+// u1: [100,200], u2: [150,300]
+clang_analyzer_eval(u1 != u2); // expected-warning{{UNKNOWN}}
+  }
+
+  if (s1 >= -80 && s1 <= -50 && s2 >= -100 && s2 <= -75) {
+// s1: [-80,-50], s2: [-100,-75]
+clang_analyzer_eval(s1 != s2); // expected-warning{{UNKNOWN}}
+  }
+
+  // Checks for ranges which are subset of one-another
+  if (u1 >= 500 && u1 <= 1000 && u2 >= 750 && u2 <= 1000) {
+// u1: [500,1000], u2: [750,1000]
+clang_analyzer_eval(u1 != u2); // expected-warning{{UNKNOWN}}
+  }
+
+  if (s1 >= -1000 && s1 <= -500 && s2 >= -750 && s2 <= -500) {
+// s1: [-1000,-500], s2: [-750, -500]
+clang_analyzer_eval(s1 != s2); // expected-warning{{UNKNOWN}}
+  }
+
+  // Checks for comparison between different types
+  // Using different variables as previous constraints may interfere in the
+  // reasoning.
+  if (u3 <= 255 && s3 < 0) {
+// u3: [0, 255], s3: [INT_MIN, -1]
+clang_analyzer_eval(u3 != s3); // expected-warning{{TRUE}}
+  }
+
+  // Checks for char-uchar types
+  if (uch >= 1 && sch <= 1) {
+// uch: [1, UCHAR_MAX], sch: [SCHAR_MIN, 1]
+clang_analyzer_eval(uch != sch); // e

[PATCH] D139696: [include-cleaner] Add a unique_ptr-style member expr test in WalkASTTest.

2022-12-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: VitaNuo.
Herald added a subscriber: kadircet.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: clang-tools-extra.

This is a test I missed to mention in https://reviews.llvm.org/D139087.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139696

Files:
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -196,6 +196,18 @@
"Derived foo(); void fun() { foo().^a; }");
   testWalk("struct Base { int a; }; struct $explicit^Derived : public Base 
{};",
"Derived& foo(); void fun() { foo().^a; }");
+  testWalk(R"cpp(
+  template  struct unique_ptr {
+T *operator->();
+  };
+  struct $explicit^Foo { int a; };)cpp",
+   "void test(unique_ptr &V) { V->^a; }");
+  testWalk(R"cpp(
+  template  struct $explicit^unique_ptr {
+void release();
+  };
+  struct Foo {};)cpp",
+   "void test(unique_ptr &V) { V.^release(); }");
 }
 
 TEST(WalkAST, ConstructExprs) {


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -196,6 +196,18 @@
"Derived foo(); void fun() { foo().^a; }");
   testWalk("struct Base { int a; }; struct $explicit^Derived : public Base {};",
"Derived& foo(); void fun() { foo().^a; }");
+  testWalk(R"cpp(
+  template  struct unique_ptr {
+T *operator->();
+  };
+  struct $explicit^Foo { int a; };)cpp",
+   "void test(unique_ptr &V) { V->^a; }");
+  testWalk(R"cpp(
+  template  struct $explicit^unique_ptr {
+void release();
+  };
+  struct Foo {};)cpp",
+   "void test(unique_ptr &V) { V.^release(); }");
 }
 
 TEST(WalkAST, ConstructExprs) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139627: clang/X86: Don't emit "min-legal-vector-width"="0"

2022-12-09 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

In D139627#3982381 , @craig.topper 
wrote:

> In D139627#3982349 , @jdoerfert 
> wrote:
>
>> Isn't this (inherently) X86 specific?
>
> Yes it is. We could qualify the attribute emission with the targeting being 
> X86?

That's a good idea. How about AArch64? I found there are uses there in the test 
cases.


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

https://reviews.llvm.org/D139627

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


[clang] 4faf000 - Recommit of 8ae18303f97d5dcfaecc90b4d87effb2011ed82e - part 2

2022-12-09 Thread via cfe-commits

Author: serge-sans-paille
Date: 2022-12-09T10:07:02+01:00
New Revision: 4faf6cf989f3ae212912994022c0486a2dc4

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

LOG: Recommit of 8ae18303f97d5dcfaecc90b4d87effb2011ed82e - part 2

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
llvm/include/llvm/Option/OptTable.h
llvm/lib/Option/OptTable.cpp
llvm/unittests/Option/OptionMarshallingTest.cpp
llvm/utils/TableGen/OptParserEmitter.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 4621850f13772..60d62e2b9c5c1 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -331,8 +331,8 @@ static bool getStaticPIE(const ArgList &Args, const 
ToolChain &TC) {
   if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) {
 const Driver &D = TC.getDriver();
 const llvm::opt::OptTable &Opts = D.getOpts();
-const char *StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
-const char *NoPIEName = Opts.getOptionName(options::OPT_nopie);
+StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
+StringRef NoPIEName = Opts.getOptionName(options::OPT_nopie);
 D.Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName;
   }
   return HasStaticPIE;

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp 
b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 9d89148616be1..fde098840be4b 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -1055,7 +1055,7 @@ void 
PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
   // Only add the version-min options if we got a version from somewhere
   if (!version.empty() && sdk_type != XcodeSDK::Type::Linux) {
 #define OPTION(PREFIX, NAME, VAR, ...) 
\
-  const char *opt_##VAR = NAME;
\
+  llvm::StringRef opt_##VAR = NAME;
\
   (void)opt_##VAR;
 #include "clang/Driver/Options.inc"
 #undef OPTION

diff  --git a/llvm/include/llvm/Option/OptTable.h 
b/llvm/include/llvm/Option/OptTable.h
index 07d9870f71b33..390462d762e61 100644
--- a/llvm/include/llvm/Option/OptTable.h
+++ b/llvm/include/llvm/Option/OptTable.h
@@ -102,9 +102,7 @@ class OptTable {
   const Option getOption(OptSpecifier Opt) const;
 
   /// Lookup the name of the given option.
-  const char *getOptionName(OptSpecifier id) const {
-return getInfo(id).Name;
-  }
+  StringRef getOptionName(OptSpecifier id) const { return getInfo(id).Name; }
 
   /// Get the kind of the given option.
   unsigned getOptionKind(OptSpecifier id) const {

diff  --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
index ef4873eb7f9c4..f4426bc34b3f9 100644
--- a/llvm/lib/Option/OptTable.cpp
+++ b/llvm/lib/Option/OptTable.cpp
@@ -36,16 +36,10 @@ namespace opt {
 // Ordering on Info. The ordering is *almost* case-insensitive lexicographic,
 // with an exception. '\0' comes at the end of the alphabet instead of the
 // beginning (thus options precede any other options which prefix them).
-static int StrCmpOptionNameIgnoreCase(const char *A, const char *B) {
-  const char *X = A, *Y = B;
-  char a = tolower(*A), b = tolower(*B);
-  while (a == b) {
-if (a == '\0')
-  return 0;
-
-a = tolower(*++X);
-b = tolower(*++Y);
-  }
+static int StrCmpOptionNameIgnoreCase(StringRef A, StringRef B) {
+  size_t MinSize = std::min(A.size(), B.size());
+  if (int Res = A.substr(0, MinSize).compare_insensitive(B.substr(0, MinSize)))
+return Res;
 
   if (a == '\0') // A is a prefix of B.
 return 1;
@@ -60,7 +54,7 @@ static int StrCmpOptionNameIgnoreCase(const char *A, const 
char *B) {
 static int StrCmpOptionName(const char *A, const char *B) {
   if (int N = StrCmpOptionNameIgnoreCase(A, B))
 return N;
-  return strcmp(A, B);
+  return A.compare(B);
 }
 
 static inline bool operator<(const OptTable::Info &A, const OptTable::Info &B) 
{
@@ -186,7 +180,7 @@ static unsigned matchOption(const OptTable::Info *I, 
StringRef Str,
   bool Matched = IgnoreCase ? Rest.startswith_insensitive(I->Name)
 : Rest.startswith(I->Name);
   if (Matched)
-return Prefix.size() + StringRef(I->Name).size();
+return Prefix.size() + I->Name.size();
 }
   }
   return 0;
@@ -347,8 +341,8 @@ std::unique_ptr 
OptTable::parseOneArgGrouped(InputArgList &Args,
 
   const Info *End = OptionInfos.data() + OptionInfos.size();
   StringRef Name = St

[PATCH] D138571: Update ninja and cmake installation commands on LibASTMatchersTutorial

2022-12-09 Thread Ismael via Phabricator via cfe-commits
ismaelJimenez added a comment.

Dear reviewers, I do not have commit access. Could you please commit this 
change in my behalf? Thank you very much for your support!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138571

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


[clang] d881fdf - Revert "Recommit of 8ae18303f97d5dcfaecc90b4d87effb2011ed82e - part 2"

2022-12-09 Thread via cfe-commits

Author: serge-sans-paille
Date: 2022-12-09T10:15:41+01:00
New Revision: d881fdf72047fd18b88c6a65d0966cad542c95cd

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

LOG: Revert "Recommit of 8ae18303f97d5dcfaecc90b4d87effb2011ed82e - part 2"

This reverts commit 4faf6cf989f3ae212912994022c0486a2dc4.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
llvm/include/llvm/Option/OptTable.h
llvm/lib/Option/OptTable.cpp
llvm/unittests/Option/OptionMarshallingTest.cpp
llvm/utils/TableGen/OptParserEmitter.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 60d62e2b9c5c1..4621850f13772 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -331,8 +331,8 @@ static bool getStaticPIE(const ArgList &Args, const 
ToolChain &TC) {
   if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) {
 const Driver &D = TC.getDriver();
 const llvm::opt::OptTable &Opts = D.getOpts();
-StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
-StringRef NoPIEName = Opts.getOptionName(options::OPT_nopie);
+const char *StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
+const char *NoPIEName = Opts.getOptionName(options::OPT_nopie);
 D.Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName;
   }
   return HasStaticPIE;

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp 
b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index fde098840be4b..9d89148616be1 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -1055,7 +1055,7 @@ void 
PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
   // Only add the version-min options if we got a version from somewhere
   if (!version.empty() && sdk_type != XcodeSDK::Type::Linux) {
 #define OPTION(PREFIX, NAME, VAR, ...) 
\
-  llvm::StringRef opt_##VAR = NAME;
\
+  const char *opt_##VAR = NAME;
\
   (void)opt_##VAR;
 #include "clang/Driver/Options.inc"
 #undef OPTION

diff  --git a/llvm/include/llvm/Option/OptTable.h 
b/llvm/include/llvm/Option/OptTable.h
index 390462d762e61..07d9870f71b33 100644
--- a/llvm/include/llvm/Option/OptTable.h
+++ b/llvm/include/llvm/Option/OptTable.h
@@ -102,7 +102,9 @@ class OptTable {
   const Option getOption(OptSpecifier Opt) const;
 
   /// Lookup the name of the given option.
-  StringRef getOptionName(OptSpecifier id) const { return getInfo(id).Name; }
+  const char *getOptionName(OptSpecifier id) const {
+return getInfo(id).Name;
+  }
 
   /// Get the kind of the given option.
   unsigned getOptionKind(OptSpecifier id) const {

diff  --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
index f4426bc34b3f9..ef4873eb7f9c4 100644
--- a/llvm/lib/Option/OptTable.cpp
+++ b/llvm/lib/Option/OptTable.cpp
@@ -36,10 +36,16 @@ namespace opt {
 // Ordering on Info. The ordering is *almost* case-insensitive lexicographic,
 // with an exception. '\0' comes at the end of the alphabet instead of the
 // beginning (thus options precede any other options which prefix them).
-static int StrCmpOptionNameIgnoreCase(StringRef A, StringRef B) {
-  size_t MinSize = std::min(A.size(), B.size());
-  if (int Res = A.substr(0, MinSize).compare_insensitive(B.substr(0, MinSize)))
-return Res;
+static int StrCmpOptionNameIgnoreCase(const char *A, const char *B) {
+  const char *X = A, *Y = B;
+  char a = tolower(*A), b = tolower(*B);
+  while (a == b) {
+if (a == '\0')
+  return 0;
+
+a = tolower(*++X);
+b = tolower(*++Y);
+  }
 
   if (a == '\0') // A is a prefix of B.
 return 1;
@@ -54,7 +60,7 @@ static int StrCmpOptionNameIgnoreCase(StringRef A, StringRef 
B) {
 static int StrCmpOptionName(const char *A, const char *B) {
   if (int N = StrCmpOptionNameIgnoreCase(A, B))
 return N;
-  return A.compare(B);
+  return strcmp(A, B);
 }
 
 static inline bool operator<(const OptTable::Info &A, const OptTable::Info &B) 
{
@@ -180,7 +186,7 @@ static unsigned matchOption(const OptTable::Info *I, 
StringRef Str,
   bool Matched = IgnoreCase ? Rest.startswith_insensitive(I->Name)
 : Rest.startswith(I->Name);
   if (Matched)
-return Prefix.size() + I->Name.size();
+return Prefix.size() + StringRef(I->Name).size();
 }
   }
   return 0;
@@ -341,8 +347,8 @@ std::unique_ptr 
OptTable::parseOneArgGrouped(InputArgList &Args,
 
   const Info *End = OptionInfos.data() + OptionInfos.size();
   StringRe

[PATCH] D139544: [clang][dataflow] Add support for structured bindings of tuple-like types.

2022-12-09 Thread Domján Dániel via Phabricator via cfe-commits
isuckatcs added a comment.

Those `BindingDecl`s never appear in the CFG unless one of the is used.

Take a look at the other cases.

1.) Arrays

  void foo() {
  int arr[2];
  
  auto [i0, i1] = arr;
  }

  [B1]
 1: int arr[2];
 2: arr
 3: [B1.2] (ImplicitCastExpr, ArrayToPointerDecay, int *)
 4: *
 5: [B1.3][[B1.4]]
 6: [B1.5] (ImplicitCastExpr, LValueToRValue, int)
 7: {[B1.6]}
 8: auto = {arr[*]};
 Preds (1): B2
 Succs (1): B0

2.)  Structs

  struct S {
  int x;
  int y;
  };
  
  void foo() {
  S s;
  
  auto [i0, i1] = s;
  }

  [B1]
 1:  (CXXConstructExpr, [B1.2], S)
 2: S s;
 3: s
 4: [B1.3] (ImplicitCastExpr, NoOp, const struct S)
 5: [B1.4] (CXXConstructExpr, [B1.6], S)
 6: auto = s;
 Preds (1): B2
 Succs (1): B0

`i0` and `i1` are not in the CFG. They only get added, when one of them is 
actually used.

  int x = i0;

   9: i0
  10: [B1.9] (ImplicitCastExpr, LValueToRValue, int)
  11: int x = i0;

That means. when you see the `DeclRefExpr` you mentioned, the synthesized 
variable has already been created and the `BindingDecl` can see it.

  -DeclRefExpr  'std::tuple_element<0, std::tuple>::type':'int' lvalue Binding 0x559942acf350 'i0' 'std::tuple_element<0, 
std::tuple>::type':'int'

By the time you see this node, the variable has already been created and you 
can access it using `BindingDecl::getHoldingVar()`. You want to analyze these 
`BindingDecl`s when they are used not when you encounter the 
`DecompositionDecl`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139544

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


[clang] c9a6713 - Implement CWG2631

2022-12-09 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-12-09T10:25:44+01:00
New Revision: c9a6713b4788f10b81202b70993068e475b392f7

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

LOG: Implement CWG2631

Implement https://cplusplus.github.io/CWG/issues/2631.html.

Immediate calls in default arguments and defaults members
are not evaluated.

Instead, we evaluate them when constructing a
`CXXDefaultArgExpr`/`BuildCXXDefaultInitExpr`.

The immediate calls are executed by doing a
transform on the initializing expression.

Note that lambdas are not considering subexpressions so
we do not need to transform them.

As a result of this patch, unused default member
initializers are not considered odr-used, and
errors about members binding to local variables
in an outer scope only surface at the point
where a constructor is defined.

Reviewed By: aaron.ballman, #clang-language-wg

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

Added: 
clang/test/CodeGenCXX/default-arguments-with-immediate.cpp
clang/test/CodeGenCXX/meminit-initializers-odr.cpp
clang/test/PCH/default-argument-with-immediate-calls.cpp
clang/test/SemaCXX/cxx2a-consteval-default-params.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/Stmt.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/Parse/ParseCXXInlineMethods.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Sema/UsedDeclVisitor.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/test/CXX/class/class.local/p1-0x.cpp
clang/test/CXX/drs/dr26xx.cpp
clang/test/CodeGenCXX/builtin-source-location.cpp
clang/test/SemaCXX/cxx11-default-member-initializers.cpp
clang/test/SemaCXX/source_location.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 53155b0e2a492..6bd038fbdc16f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -642,6 +642,11 @@ C++ Language Changes in Clang
 - Implemented DR2358 allowing init captures in lambdas in default arguments.
 - implemented `DR2654 `_ which undeprecates
   all compound assignements operations on volatile qualified variables.
+- Implemented DR2631. Invalid ``consteval`` calls in default arguments and 
default
+  member initializers are diagnosed when and if the default is used.
+  This Fixes `Issue 56379 `_
+  and changes the value of ``std::source_location::current()``
+  used in default parameters calls compared to previous versions of Clang.
 
 C++20 Feature Support
 ^

diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 81267ff568c5b..9d3fd98f65e29 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1245,8 +1245,12 @@ class CXXThrowExpr : public Expr {
 /// This wraps up a function call argument that was created from the
 /// corresponding parameter's default argument, when the call did not
 /// explicitly supply arguments for all of the parameters.
-class CXXDefaultArgExpr final : public Expr {
+class CXXDefaultArgExpr final
+: public Expr,
+  private llvm::TrailingObjects {
   friend class ASTStmtReader;
+  friend class ASTReader;
+  friend TrailingObjects;
 
   /// The parameter whose default is being used.
   ParmVarDecl *Param;
@@ -1255,7 +1259,7 @@ class CXXDefaultArgExpr final : public Expr {
   DeclContext *UsedContext;
 
   CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *Param,
-DeclContext *UsedContext)
+Expr *RewrittenExpr, DeclContext *UsedContext)
   : Expr(SC,
  Param->hasUnparsedDefaultArg()
  ? Param->getType().getNonReferenceType()
@@ -1264,28 +1268,58 @@ class CXXDefaultArgExpr final : public Expr {
  Param->getDefaultArg()->getObjectKind()),
 Param(Param), UsedContext(UsedContext) {
 CXXDefaultArgExprBits.Loc = Loc;
+CXXDefaultArgExprBits.HasRewrittenInit = RewrittenExpr != nullptr;
+if (RewrittenExpr)
+  *getTrailingObjects() = RewrittenExpr;
 setDependence(computeDependence(this));
   }
 
+  CXXDefaultArgExpr(EmptyShell Empty, bool HasRewrittenInit)
+  : Expr(CXXDefaultArgExprClass, Empty) {
+CXXDefaultArgExprBits.HasRewrittenInit = HasRewrittenInit;
+  }
+
+  size_t numTrailing

[PATCH] D136554: Implement CWG2631

2022-12-09 Thread Corentin Jabot 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 rGc9a6713b4788: Implement CWG2631 (authored by cor3ntin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136554

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Sema/UsedDeclVisitor.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/CXX/class/class.local/p1-0x.cpp
  clang/test/CXX/drs/dr26xx.cpp
  clang/test/CodeGenCXX/builtin-source-location.cpp
  clang/test/CodeGenCXX/default-arguments-with-immediate.cpp
  clang/test/CodeGenCXX/meminit-initializers-odr.cpp
  clang/test/PCH/default-argument-with-immediate-calls.cpp
  clang/test/SemaCXX/cxx11-default-member-initializers.cpp
  clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
  clang/test/SemaCXX/source_location.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -15593,7 +15593,7 @@
 https://wg21.link/cwg2631";>2631
 DR
 Immediate function evaluations in default arguments
-Unknown
+Clang 16
   
   
 https://wg21.link/cwg2632";>2632
Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify %s
+// RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -DUSE_CONSTEVAL -fexceptions -verify %s
 // expected-no-diagnostics
 
 #define assert(...) ((__VA_ARGS__) ? ((void)0) : throw 42)
@@ -8,15 +9,22 @@
 template 
 struct Printer;
 
+#ifdef USE_CONSTEVAL
+#define SOURCE_LOC_EVAL_KIND consteval
+#else
+#define SOURCE_LOC_EVAL_KIND constexpr
+#endif
+
 namespace std {
 class source_location {
   struct __impl;
 
 public:
-  static constexpr source_location current(const __impl *__p = __builtin_source_location()) noexcept {
-source_location __loc;
-__loc.__m_impl = __p;
-return __loc;
+  static SOURCE_LOC_EVAL_KIND source_location
+current(const __impl *__p = __builtin_source_location()) noexcept {
+  source_location __loc;
+  __loc.__m_impl = __p;
+  return __loc;
   }
   constexpr source_location() = default;
   constexpr source_location(source_location const &) = default;
@@ -593,3 +601,51 @@
   }
   static_assert(test());
 }
+
+namespace Lambda {
+#line 8000 "TestLambda.cpp"
+constexpr int nested_lambda(int l = []{
+  return SL::current().line();
+}()) {
+  return l;
+}
+static_assert(nested_lambda() == __LINE__ - 4);
+
+constexpr int lambda_param(int l = [](int l = SL::current().line()) {
+  return l;
+}()) {
+  return l;
+}
+static_assert(lambda_param() == __LINE__);
+
+
+}
+
+constexpr int compound_literal_fun(int a =
+  (int){ SL::current().line() }
+) { return a ;}
+static_assert(compound_literal_fun() == __LINE__);
+
+struct CompoundLiteral {
+  int a = (int){ SL::current().line() };
+};
+static_assert(CompoundLiteral{}.a == __LINE__);
+
+
+// FIXME
+// Init captures are subexpressions of the lambda expression
+// so according to the standard immediate invocations in init captures
+// should be evaluated at the call site.
+// However Clang does not yet implement this as it would introduce
+// a fair bit of complexity.
+// We intend to implement that functionality once we find real world
+// use cases that require it.
+constexpr int test_init_capture(int a =
+[b = SL::current().line()] { return b; }()) {
+  return a;
+}
+#ifdef USE_CONSTEVAL
+static_assert(test_init_capture() == __LINE__ - 4);
+#else
+static_assert(test_init_capture() == __LINE__ );
+#endif
Index: clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
@@ -0,0 +1,81 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2b %s
+
+consteval int undefined();  // expected-note 4 {{declared here}}
+
+void check_lambdas_unused(
+int a = []
+{
+// The body of a lambda is not a subexpression of the lambda
+// so this is immediately evaluated even if the parameter
+// is never used.
+return 

[PATCH] D137051: [Clang] Allow additional mathematical symbols in identifiers.

2022-12-09 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 481556.
cor3ntin added a comment.

Fix grammar in diagnostic.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137051

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/lib/Lex/Lexer.cpp
  clang/lib/Lex/UnicodeCharSets.h
  clang/test/Driver/autocomplete.c
  clang/test/Lexer/unicode.c

Index: clang/test/Lexer/unicode.c
===
--- clang/test/Lexer/unicode.c
+++ clang/test/Lexer/unicode.c
@@ -45,7 +45,17 @@
 extern int _\N{TANGSALETTERGA}; // expected-error {{'TANGSALETTERGA' is not a valid Unicode character name}} \
 // expected-note {{characters names in Unicode escape sequences are sensitive to case and whitespace}}
 
+extern int 𝛛; // expected-warning {{mathematical notation character  in an identifier is a Clang extension}}
+extern int ₉; // expected-error {{character  not allowed at the start of an identifier}} \\
+ expected-warning {{declaration does not declare anything}}
 
+int a¹b₍₄₂₎∇; // expected-warning 6{{mathematical notation character}}
+
+int \u{221E} = 1; // expected-warning {{mathematical notation character}}
+int \N{MATHEMATICAL SANS-SERIF BOLD ITALIC PARTIAL DIFFERENTIAL} = 1;
+ // expected-warning@-1 {{mathematical notation character}}
+
+int a\N{SUBSCRIPT EQUALS SIGN} = 1; // expected-warning {{mathematical notation character}}
 
 // This character doesn't have the XID_Start property
 extern int  \U00016AC0; // TANGSA DIGIT ZERO  // cxx-error {{expected unqualified-id}} \
Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -111,6 +111,7 @@
 // WARNING-NEXT: -Wmain-return-type
 // WARNING-NEXT: -Wmalformed-warning-check
 // WARNING-NEXT: -Wmany-braces-around-scalar-init
+// WARNING-NEXT: -Wmathematical-notation-identifier-extension
 // WARNING-NEXT: -Wmax-tokens
 // WARNING-NEXT: -Wmax-unsigned-zero
 // RUN: %clang --autocomplete=-Wno-invalid-pp- | FileCheck %s -check-prefix=NOWARNING
Index: clang/lib/Lex/UnicodeCharSets.h
===
--- clang/lib/Lex/UnicodeCharSets.h
+++ clang/lib/Lex/UnicodeCharSets.h
@@ -366,6 +366,34 @@
 {0x1E4EC, 0x1E4F9}, {0x1E8D0, 0x1E8D6}, {0x1E944, 0x1E94A},
 {0x1E950, 0x1E959}, {0x1FBF0, 0x1FBF9}, {0xE0100, 0xE01EF}};
 
+// Clang supports the "Mathematical notation profile" as an extension,
+// as described in https://www.unicode.org/L2/L2022/22230-math-profile.pdf
+// Math_Start
+static const llvm::sys::UnicodeCharRange MathematicalNotationProfileIDStartRanges[] = {
+{0x02202, 0x02202}, // ∂
+{0x02207, 0x02207}, // ∇
+{0x0221E, 0x0221E}, // ∞
+{0x1D6C1, 0x1D6C1}, // 𝛁
+{0x1D6DB, 0x1D6DB}, // 𝛛
+{0x1D6FB, 0x1D6FB}, // 𝛻
+{0x1D715, 0x1D715}, // 𝜕
+{0x1D735, 0x1D735}, // 𝜵
+{0x1D74F, 0x1D74F}, // 𝝏
+{0x1D76F, 0x1D76F}, // 𝝯
+{0x1D789, 0x1D789}, // 𝞉
+{0x1D7A9, 0x1D7A9}, // 𝞩
+{0x1D7C3, 0x1D7C3}, // 𝟃
+};
+
+// Math_Continue
+static const llvm::sys::UnicodeCharRange MathematicalNotationProfileIDContinueRanges[] = {
+{0x000B2, 0x000B3}, // ²-³
+{0x000B9, 0x000B9}, // ¹
+{0x02070, 0x02070}, // ⁰
+{0x02074, 0x0207E}, // ⁴-⁾
+{0x02080, 0x0208E}, // ₀-₎
+};
+
 // C11 D.1, C++11 [charname.allowed]
 static const llvm::sys::UnicodeCharRange C11AllowedIDCharRanges[] = {
   // 1
Index: clang/lib/Lex/Lexer.cpp
===
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -1457,7 +1457,30 @@
   return UnicodeWhitespaceChars.contains(Codepoint);
 }
 
-static bool isAllowedIDChar(uint32_t C, const LangOptions &LangOpts) {
+static llvm::SmallString<5> codepointAsHexString(uint32_t C) {
+  llvm::SmallString<5> CharBuf;
+  llvm::raw_svector_ostream CharOS(CharBuf);
+  llvm::write_hex(CharOS, C, llvm::HexPrintStyle::Upper, 4);
+  return CharBuf;
+}
+
+// To mitigate https://github.com/llvm/llvm-project/issues/54732,
+// we allow "Mathematical Notation Characters" in identifiers.
+// This is a proposed profile that extends the XID_Start/XID_continue
+// with mathematical symbols, superscipts and subscripts digits
+// found in some production software.
+// https://www.unicode.org/L2/L2022/22230-math-profile.pdf
+static bool isMathematicalExtensionID(uint32_t C, const LangOptions &LangOpts, bool IsStart, bool & IsExtension) {
+  static const llvm::sys::UnicodeCharSet MathStartChars(MathematicalNotationProfileIDStartRanges);
+  static const llvm::sys::UnicodeCharSet MathContinueChars(MathematicalNotationProfileIDContinueRanges);
+  if(MathStartChars.contains(C) || (!IsStart && MathContinueChars.contains(

[PATCH] D137051: [Clang] Allow additional mathematical symbols in identifiers.

2022-12-09 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

Thanks Tom. I'm adding more reviewers in case someone else wants to look at it


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137051

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


[PATCH] D139398: [AMDGPU] Add bf16 storage support

2022-12-09 Thread Pierre van Houtryve via Phabricator via cfe-commits
Pierre-vh added inline comments.



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:913
+  else
+RegisterVT = (ScalarVT == MVT::bf16 ? MVT::v2bf16 : MVT::v2f16);
   IntermediateVT = RegisterVT;

arsenm wrote:
> If you wanted the promote to i32, you could have done it here instead of in 
> the tablegen cc handling
Do you mean somewhere else in that function? Changing v2bf16 to i32 here 
doesn't fix it 
I also tried changing the function above but I kept running into asserts so I 
just left the TableGen CC for now



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:5563
+  return DAG.getNode(ISD::BITCAST, SL, MVT::i16,
+ DAG.getFPExtendOrRound(Op->getOperand(0), SL, MVT::f16));
+}

arsenm wrote:
> Should be specific cast, not FPExtOrRound. I don't think the FP_ROUND case 
> would be correct
But we need to do f32 -> f16, isn't FP_ROUND used for that? I thought it's what 
we needed



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:5573-5576
+  SDLoc SL(Op);
+  return DAG.getNode(
+  ISD::FP_EXTEND, SL, MVT::f32,
+  DAG.getNode(ISD::BITCAST, SL, MVT::f16, Op->getOperand(0)));

arsenm wrote:
> ExpandNode covers lowering BF16_TO_FP. It also has a shift by 16-bits into 
> the high bits. Is this correct?
Ah I didn't know that, though as long as we use custom lowering, and our 
FP_TO_BF16/BF16_TO_FP methods are consistent, it should be fine, no?



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:4819-4831
+// When we don't have 16 bit instructions, bf16 is illegal and gets
+// softened to i16 for storage, with float being used for arithmetic.
+//
+// After softening, some i16 -> fp32 bf16_to_fp operations can be left 
over.
+// Lower those to (f32 (fp_extend (f16 (bitconvert x
+if (!Op->getValueType(0).isFloatingPoint() ||
+Op->getOperand(0).getValueType() != MVT::i16)

arsenm wrote:
> Pierre-vh wrote:
> > arsenm wrote:
> > > Pierre-vh wrote:
> > > > arsenm wrote:
> > > > > Pierre-vh wrote:
> > > > > > arsenm wrote:
> > > > > > > The generic legalizer should have handled this?
> > > > > > It looks like those operations are not implemented in the generic 
> > > > > > legalizer, e.g. I get 
> > > > > > ``` 
> > > > > > Do not know how to promote this operator's operand!
> > > > > > ```
> > > > > Right, this is the code that would go there
> > > > Do I just copy/paste this code in that PromoteInt function, and keep a 
> > > > copy here too in LowerOperation? (not really a fan of copy-pasting code 
> > > > in different files, I'd rather keep it all here)
> > > > We need to have the lowering too AFAIK, it didn't go well when I tried 
> > > > to remove it
> > > I'm not following why you need to handle it here
> > IIRC:
> >  - I need to handle FP_TO_BF16 in ReplaceNodeResult because that's what the 
> > Integer Legalizer calls (through CustomLowerNode)
> >  - I need to handle both opcodes in LowerOperation because otherwise 
> > they'll fail selection. They can be left over from expanding/legalizing 
> > other operations.
> But why are they custom? We don't have to handle FP16_TO_FP or FP_TO_FP16 
> there, and they aren't custom lowered. They have the same basic properties. 
> We have this:
> 
> 
> ```
> setOperationAction(ISD::FP16_TO_FP, MVT::i16, Promote);
> AddPromotedToType(ISD::FP16_TO_FP, MVT::i16, MVT::i32);
> setOperationAction(ISD::FP_TO_FP16, MVT::i16, Promote);
> AddPromotedToType(ISD::FP_TO_FP16, MVT::i16, MVT::i32);
> ```
> 
> I'd expect the same basic pattern
PromoteIntegerOperand, PromoteFloatOperand and PromoteIntegerResult don't 
handle FP_TO_BF16 and BF16_TO_FP, and unless we put a Custom lowering mode 
it'll assert/unreachable.
I tried to make it work (for a while) using the default expand but I can't 
quite get it to work. It feels like there is some legalizer work missing for 
handling BF16 like we want to.
Even though it's not ideal I think the custom lowering is easiest


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139398

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


[PATCH] D112621: [analyzer][solver] Introduce reasoning for not equal to operator

2022-12-09 Thread Manas Gupta via Phabricator via cfe-commits
manas updated this revision to Diff 481560.
manas added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112621

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/constant-folding.c


Index: clang/test/Analysis/constant-folding.c
===
--- clang/test/Analysis/constant-folding.c
+++ clang/test/Analysis/constant-folding.c
@@ -293,13 +293,6 @@
 clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
   }
 
-  if (u1 > INT_MAX && u1 <= UINT_MAX / 2 + 4 && u1 != UINT_MAX / 2 + 2 &&
-  u1 != UINT_MAX / 2 + 3 && s1 >= INT_MIN + 1 && s1 <= INT_MIN + 2) {
-// u1: [INT_MAX+1, INT_MAX+1]U[INT_MAX+4, INT_MAX+4],
-// s1: [INT_MIN+1, INT_MIN+2]
-clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
-  }
-
   if (u1 >= INT_MIN && u1 <= INT_MIN + 2 &&
   s1 > INT_MIN + 2 && s1 < INT_MIN + 4) {
 // u1: [INT_MAX+1, INT_MAX+1]U[INT_MAX+4, INT_MAX+4],
@@ -309,7 +302,7 @@
 
   if (s1 < 0 && s1 > -4 && u1 > UINT_MAX - 4 && u1 < UINT_MAX - 1) {
 // s1: [-3, -1], u1: [UINT_MAX - 3, UINT_MAX - 2]
-clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
+clang_analyzer_eval(u1 != s1); // expected-warning{{UNKNOWN}}
   }
 
   if (s1 < 1 && s1 > -6 && s1 != -4 && s1 != -3 &&
@@ -324,6 +317,11 @@
 clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
   }
 
+  if (s1 > 4 && u1 < 4) {
+// s1: [4, INT_MAX], u1: [0, 3]
+clang_analyzer_eval(s1 != u1); // expected-warning{{TRUE}}
+  }
+
   // Check when RHS is in between two Ranges in LHS
   if (((u1 >= 1 && u1 <= 2) || (u1 >= 8 && u1 <= 9)) &&
   u2 >= 5 && u2 <= 6) {
@@ -401,9 +399,12 @@
 clang_analyzer_eval(uch != sch); // expected-warning{{UNKNOWN}}
   }
 
+  // FIXME: Casting smaller signed types to unsigned one may leave us with
+  // overlapping values, falsely indicating UNKNOWN, where it is possible to
+  // assert TRUE.
   if (uch > 1 && sch < 1) {
-// uch: [2, CHAR_MAX], sch: [SCHAR_MIN, 0]
-clang_analyzer_eval(uch != sch); // expected-warning{{TRUE}}
+// uch: [2, UCHAR_MAX], sch: [SCHAR_MIN, 0]
+clang_analyzer_eval(uch != sch); // expected-warning{{UNKNOWN}}
   }
 
   if (uch <= 1 && uch >= 1 && sch <= 1 && sch >= 1) {
@@ -417,9 +418,10 @@
 clang_analyzer_eval(ush != ssh); // expected-warning{{UNKNOWN}}
   }
 
+  // FIXME: Casting leave us with overlapping values. Should be TRUE.
   if (ush > 1 && ssh < 1) {
 // ush: [2, USHRT_MAX], ssh: [SHRT_MIN, 0]
-clang_analyzer_eval(ush != ssh); // expected-warning{{TRUE}}
+clang_analyzer_eval(ush != ssh); // expected-warning{{UNKNOWN}}
   }
 
   if (ush <= 1 && ush >= 1 && ssh <= 1 && ssh >= 1) {
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1619,13 +1619,10 @@
RangeSet RHS,
QualType T) {
 
-  // We must check for empty RangeSets. This gets done via VisitBinaryOperator
-  // for other operators, but BO_NE is handled specifically.
-  if (LHS.isEmpty() || RHS.isEmpty())
-return RangeFactory.getEmptySet();
+  assert(!LHS.isEmpty() && !RHS.isEmpty() && "Both ranges should be 
non-empty");
 
   if (LHS.getAPSIntType() == RHS.getAPSIntType()) {
-if (intersect(RangeFactory, LHS, RHS) == RangeFactory.getEmptySet())
+if (intersect(RangeFactory, LHS, RHS).isEmpty())
   return getTrueRange(T);
 
   } else {
@@ -1636,8 +1633,7 @@
 RangeSet CastedLHS = RangeFactory.castTo(LHS, CastingType);
 RangeSet CastedRHS = RangeFactory.castTo(RHS, CastingType);
 
-if (intersect(RangeFactory, CastedLHS, CastedRHS) ==
-RangeFactory.getEmptySet())
+if (intersect(RangeFactory, CastedLHS, CastedRHS).isEmpty())
   return getTrueRange(T);
   }
 


Index: clang/test/Analysis/constant-folding.c
===
--- clang/test/Analysis/constant-folding.c
+++ clang/test/Analysis/constant-folding.c
@@ -293,13 +293,6 @@
 clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
   }
 
-  if (u1 > INT_MAX && u1 <= UINT_MAX / 2 + 4 && u1 != UINT_MAX / 2 + 2 &&
-  u1 != UINT_MAX / 2 + 3 && s1 >= INT_MIN + 1 && s1 <= INT_MIN + 2) {
-// u1: [INT_MAX+1, INT_MAX+1]U[INT_MAX+4, INT_MAX+4],
-// s1: [INT_MIN+1, INT_MIN+2]
-clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
-  }
-
   if (u1 >= INT_MIN && u1 <= INT_MIN + 2 &&
   s1 > INT_MIN + 2 && s1 < INT_MIN + 4) {
 // u1: [INT_MAX+1, INT_MAX+1]U[INT_MAX+4, INT_MAX+4],
@@ -309,7 +302,7 @@
 
   if (s1 < 0 && s1 > -4 && u1 > UINT_MAX - 4 && u1 < UINT_MAX - 1) {
 // s1: 

[clang] 138942c - Recommit of 8ae18303f97d5dcfaecc90b4d87effb2011ed82e - part 2

2022-12-09 Thread via cfe-commits

Author: serge-sans-paille
Date: 2022-12-09T10:41:34+01:00
New Revision: 138942c833b3baa12d19216797efca6d4dd010d2

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

LOG: Recommit of 8ae18303f97d5dcfaecc90b4d87effb2011ed82e - part 2

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp
llvm/include/llvm/Option/OptTable.h
llvm/lib/Option/OptTable.cpp
llvm/unittests/Option/OptionMarshallingTest.cpp
llvm/utils/TableGen/OptParserEmitter.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 4621850f13772..60d62e2b9c5c1 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -331,8 +331,8 @@ static bool getStaticPIE(const ArgList &Args, const 
ToolChain &TC) {
   if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) {
 const Driver &D = TC.getDriver();
 const llvm::opt::OptTable &Opts = D.getOpts();
-const char *StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
-const char *NoPIEName = Opts.getOptionName(options::OPT_nopie);
+StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
+StringRef NoPIEName = Opts.getOptionName(options::OPT_nopie);
 D.Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName;
   }
   return HasStaticPIE;

diff  --git a/llvm/include/llvm/Option/OptTable.h 
b/llvm/include/llvm/Option/OptTable.h
index 07d9870f71b33..e884ebeb788c4 100644
--- a/llvm/include/llvm/Option/OptTable.h
+++ b/llvm/include/llvm/Option/OptTable.h
@@ -44,7 +44,7 @@ class OptTable {
 /// A null terminated array of prefix strings to apply to name while
 /// matching.
 const char *const *Prefixes;
-const char *Name;
+StringRef Name;
 const char *HelpText;
 const char *MetaVar;
 unsigned ID;
@@ -102,9 +102,7 @@ class OptTable {
   const Option getOption(OptSpecifier Opt) const;
 
   /// Lookup the name of the given option.
-  const char *getOptionName(OptSpecifier id) const {
-return getInfo(id).Name;
-  }
+  StringRef getOptionName(OptSpecifier id) const { return getInfo(id).Name; }
 
   /// Get the kind of the given option.
   unsigned getOptionKind(OptSpecifier id) const {
@@ -184,7 +182,7 @@ class OptTable {
   ///  takes
   ///
   /// \return true in success, and false in fail.
-  bool addValues(const char *Option, const char *Values);
+  bool addValues(StringRef Option, const char *Values);
 
   /// Parse a single argument; returning the new argument and
   /// updating Index.

diff  --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
index ef4873eb7f9c4..f23561b5d078d 100644
--- a/llvm/lib/Option/OptTable.cpp
+++ b/llvm/lib/Option/OptTable.cpp
@@ -36,31 +36,23 @@ namespace opt {
 // Ordering on Info. The ordering is *almost* case-insensitive lexicographic,
 // with an exception. '\0' comes at the end of the alphabet instead of the
 // beginning (thus options precede any other options which prefix them).
-static int StrCmpOptionNameIgnoreCase(const char *A, const char *B) {
-  const char *X = A, *Y = B;
-  char a = tolower(*A), b = tolower(*B);
-  while (a == b) {
-if (a == '\0')
-  return 0;
-
-a = tolower(*++X);
-b = tolower(*++Y);
-  }
+static int StrCmpOptionNameIgnoreCase(StringRef A, StringRef B) {
+  size_t MinSize = std::min(A.size(), B.size());
+  if (int Res = A.substr(0, MinSize).compare_insensitive(B.substr(0, MinSize)))
+return Res;
 
-  if (a == '\0') // A is a prefix of B.
-return 1;
-  if (b == '\0') // B is a prefix of A.
-return -1;
+  if (A.size() == B.size())
+return 0;
 
-  // Otherwise lexicographic.
-  return (a < b) ? -1 : 1;
+  return (A.size() == MinSize) ? 1 /* A is a prefix of B. */
+   : -1 /* B is a prefix of A */;
 }
 
 #ifndef NDEBUG
-static int StrCmpOptionName(const char *A, const char *B) {
+static int StrCmpOptionName(StringRef A, StringRef B) {
   if (int N = StrCmpOptionNameIgnoreCase(A, B))
 return N;
-  return strcmp(A, B);
+  return A.compare(B);
 }
 
 static inline bool operator<(const OptTable::Info &A, const OptTable::Info &B) 
{
@@ -86,7 +78,7 @@ static inline bool operator<(const OptTable::Info &A, const 
OptTable::Info &B) {
 #endif
 
 // Support lower_bound between info and an option name.
-static inline bool operator<(const OptTable::Info &I, const char *Name) {
+static inline bool operator<(const OptTable::Info &I, StringRef Name) {
   return StrCmpOptionNameIgnoreCase(I.Name, Name) < 0;
 }
 
@@ -321,7 +313,7 @@ unsigned OptTable::findNearest(StringRef Option, 
std::string &NearestString,
   return BestDistance;
 }
 
-bool OptTable::addValues(const char *Option, const char *Values) {
+bool O

[PATCH] D139444: [ZOS] Convert tests to check 'target={{.*}}-zos'

2022-12-09 Thread Ulrich Weigand via Phabricator via cfe-commits
uweigand added a comment.

In D139444#3983679 , @uweigand wrote:

> In D139444#3982205 , @probinson 
> wrote:
>
>> If you can tell me the `platform.system()` value to look for to detect z/OS, 
>> I can do that.
>
> I don't know - this value is defined by the Python implementation on z/OS.  
> On most platforms, this matches the value returned by "uname -s", but I don't 
> know what this is on z/OS either.

@Kai - maybe you can help with this.


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

https://reviews.llvm.org/D139444

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


[clang] 9e2dc98 - [Clang] improve grammar in warn_utf8_symbol_homoglyph diagnostic

2022-12-09 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-12-09T10:52:13+01:00
New Revision: 9e2dc984ba1b25625e6ddc38ba681b194172379a

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

LOG: [Clang] improve grammar in warn_utf8_symbol_homoglyph diagnostic

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/test/Lexer/unicode.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 75a133d619d4d..a915f75a8ccb0 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -127,7 +127,7 @@ def ext_unicode_whitespace : ExtWarn<
   "treating Unicode character as whitespace">,
   InGroup>;
 def warn_utf8_symbol_homoglyph : Warning<
-  "treating Unicode character  as identifier character rather than "
+  "treating Unicode character  as an identifier character rather than "
   "as '%1' symbol">, InGroup>;
 def warn_utf8_symbol_zero_width : Warning<
   "identifier contains Unicode character  that is invisible in "

diff  --git a/clang/test/Lexer/unicode.c b/clang/test/Lexer/unicode.c
index 0aea76fb479cc..98a2e86aea55b 100644
--- a/clang/test/Lexer/unicode.c
+++ b/clang/test/Lexer/unicode.c
@@ -75,9 +75,9 @@ int main (void) {
   return 🌷;
 }
 
-int n; = 3; // expected-warning {{treating Unicode character  as 
identifier character rather than as ';' symbol}}
-int *n꞉꞉v = &n;; // expected-warning 2{{treating Unicode character  as 
identifier character rather than as ':' symbol}}
- // expected-warning@-1 {{treating Unicode character  
as identifier character rather than as ';' symbol}}
+int n; = 3; // expected-warning {{treating Unicode character  as an 
identifier character rather than as ';' symbol}}
+int *n꞉꞉v = &n;; // expected-warning 2{{treating Unicode character  as 
an identifier character rather than as ':' symbol}}
+ // expected-warning@-1 {{treating Unicode character  
as an identifier character rather than as ';' symbol}}
 int v=[=](auto){return~x;}(); // expected-warning 12{{treating Unicode 
character}}
 
 int ⁠xx‍;



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


[PATCH] D137051: [Clang] Allow additional mathematical symbols in identifiers.

2022-12-09 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticLexKinds.td:129-130
   InGroup>;
 def warn_utf8_symbol_homoglyph : Warning<
   "treating Unicode character  as identifier character rather than "
   "as '%1' symbol">, InGroup>;

tahonermann wrote:
> I think this diagnostic should also have an "an" before "identifier" if you 
> wish to take on correcting it as well.
Done 
https://github.com/llvm/llvm-project/commit/9e2dc984ba1b25625e6ddc38ba681b194172379a
 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137051

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


[PATCH] D139686: [lsan] Add lsan support for loongarch64

2022-12-09 Thread Youling Tang via Phabricator via cfe-commits
tangyouling added inline comments.



Comment at: compiler-rt/test/lsan/TestCases/swapcontext.cpp:8
 // Missing 'getcontext' and 'makecontext' on Android.
-// UNSUPPORTED: arm,aarch64,powerpc64,android
+// UNSUPPORTED: arm,aarch64,loongarch64,powerpc64,android
 

SixWeining wrote:
> Why we are here? For the same reason as `Android` mentioned above?
Not for that reason.
Test passed when adding a sleep() in Child(), but not quite sure what the 
reason is?
```
 void Child() {
   int child_stack;
+  sleep(1);
   printf("Child: %p\n", &child_stack);
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139686

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


[PATCH] D137059: [Driver] [C++20] [Modules] Support -fmodule-output= (2/2)

2022-12-09 Thread Iain Sandoe via Phabricator via cfe-commits
iains accepted this revision.
iains added a comment.
This revision is now accepted and ready to land.

this LGTM ( but please wait for an ack from @dblaikie ) and again thanks for 
patience in seeing this through.


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

https://reviews.llvm.org/D137059

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


[PATCH] D139409: [include-cleaner] Handle dependent type members in AST

2022-12-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:67
 
+  bool VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E) {
+QualType QT = E->getBaseType().getCanonicalType();

Rebase the current patch. Move the implementation in the `resolveType` method, 
then this method will just pass the `BaseType` to `resolveType`.




Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:79
+
+if (isa(UnqualifiedType)) {
+  const TemplateSpecializationType *TST =

if we just aim to support the `vector().size()` case, we only need this part 
of code right?



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:81
+  const TemplateSpecializationType *TST =
+  cast(UnqualifiedType);
+  TemplateDecl *TD = TST->getTemplateName().getAsTemplateDecl();

You can simplify it in a single if statement:

`if (const TemplateSpecializationType *TS = 
Type->getAs()) `



Comment at: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp:198
+   "template void k(typename Base::Nested d) { "
+   "d.^method(); }");
+  testWalk("template struct $explicit^Base { struct Nested { void "

Thanks for coming up these cases. IMO a more reasonable behavior would be that 
the target symbol of the reported reference is `Nested` rather than the outer 
class `Base`, but implementing it would require some dependent name lookup in 
the `Base` (in clangd we have a similar thing `HeuristicResolver`, but it is 
sophisticated).

I think it is find to ignore these cases (these cases are more tricky, and less 
interesting to us) right now, this would simplify the implementation.

Note that the existing behavior of accessing a member expr from a dependent 
type is that we don't report any reference on `d.^method()`, so the original 
"include base header via a base-member-access from a derived-class object" 
issue doesn't exist. We aim to improve this behavior for some critical cases.

The critical case we want to support is the `vector().size()`, if other 
cases come up in the furture, we could revisit it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139409

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


[PATCH] D139700: [clang][Inter] Implement __builtin_expect

2022-12-09 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, tahonermann, shafik, erichkeane.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This adds a `InterpStack::discard()` version that takes a `PrimType` argument.

I'm not sure what to do if we actually want to //use// a value from the stack...


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139700

Files:
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/lib/AST/Interp/InterpStack.h
  clang/lib/AST/Interp/InterpState.h
  clang/test/AST/Interp/builtins.cpp

Index: clang/test/AST/Interp/builtins.cpp
===
--- clang/test/AST/Interp/builtins.cpp
+++ clang/test/AST/Interp/builtins.cpp
@@ -22,3 +22,11 @@
 bool is_this_constant() {
   return __builtin_is_constant_evaluated(); // CHECK: ret i1 false
 }
+
+long my_expected() {
+  return __builtin_expect(17, 12); // CHECK: ret {{.*}} 17
+}
+
+long my_expected(long foo) {
+  return __builtin_expect(foo, 100);
+}
Index: clang/lib/AST/Interp/InterpState.h
===
--- clang/lib/AST/Interp/InterpState.h
+++ clang/lib/AST/Interp/InterpState.h
@@ -86,6 +86,8 @@
 return M ? M->getSource(F, PC) : F->getSource(PC);
   }
 
+  std::optional classify(QualType T) const { return Ctx.classify(T); }
+
 private:
   /// AST Walker state.
   State &Parent;
Index: clang/lib/AST/Interp/InterpStack.h
===
--- clang/lib/AST/Interp/InterpStack.h
+++ clang/lib/AST/Interp/InterpStack.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_CLANG_AST_INTERP_INTERPSTACK_H
 #define LLVM_CLANG_AST_INTERP_INTERPSTACK_H
 
+#include "Pointer.h"
 #include "PrimType.h"
 #include 
 #include 
@@ -61,6 +62,17 @@
 shrink(aligned_size());
   }
 
+  /// Discards the top value of the given PrimType.
+  void discard(PrimType Type) {
+#ifndef NDEBUG
+assert(ItemTypes.back() == Type);
+ItemTypes.pop_back();
+#endif
+
+TYPE_SWITCH(Type, auto *Ptr = &peek(); Ptr->~T();
+shrink(aligned_size()););
+  }
+
   /// Returns a reference to the value on the top of the stack.
   template  T &peek() const {
 return *reinterpret_cast(peek(aligned_size()));
Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -36,12 +36,25 @@
   return true;
 }
 
-bool InterpretBuiltin(InterpState &S, CodePtr PC, unsigned BuiltinID) {
+bool InterpretBuiltin(InterpState &S, CodePtr PC,
+  const FunctionDecl *FuncDecl) {
+  unsigned BuiltinID = FuncDecl->getBuiltinID();
+  assert(BuiltinID != 0);
+
   switch (BuiltinID) {
   case Builtin::BI__builtin_is_constant_evaluated:
 S.Stk.push(Boolean::from(S.inConstantContext()));
 Ret(S, PC);
 return true;
+
+  case Builtin::BI__builtin_expect: {
+// __builtin_expect(long, long).
+//   Pop the last argument from the stack,
+//   leave the first one and just ignore the function.
+PrimType LongT = *S.classify(FuncDecl->getParamDecl(1)->getType());
+S.Stk.discard(LongT);
+return true;
+  }
   }
 
   return false;
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -109,7 +109,7 @@
 /// Interpreter entry point.
 bool Interpret(InterpState &S, APValue &Result);
 
-bool InterpretBuiltin(InterpState &S, CodePtr PC, unsigned BuiltinID);
+bool InterpretBuiltin(InterpState &S, CodePtr PC, const FunctionDecl *FuncDecl);
 
 enum class ArithOp { Add, Sub };
 
@@ -1407,7 +1407,7 @@
   InterpFrame *FrameBefore = S.Current;
   S.Current = NewFrame.get();
 
-  if (InterpretBuiltin(S, PC, Func->getBuiltinID())) {
+  if (InterpretBuiltin(S, PC, Func->getDecl())) {
 NewFrame.release();
 return true;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138807: [RISCV] Support vector crypto extension ISA string and assembly

2022-12-09 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

I just wanted to document the discussion we had in the RISC-V sync call 
yesterday. There were no objections to treating the vector crypto work like any 
other experimental extension, per our current policy (I think the main reason 
people might object is if substantial churn was expected that might impact 
non-experimental extensions - that's not the case here).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138807

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


[PATCH] D138861: [Clang] Implement CWG2640 Allow more characters in an n-char sequence

2022-12-09 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

Thanks Tom, I replied to your comments




Comment at: clang/lib/Lex/Lexer.cpp:3386
+
+  if (!Result || CurPtr - StartPtr == (ptrdiff_t)(Buffer.size() + 4))
 StartPtr = CurPtr;

cor3ntin wrote:
> tahonermann wrote:
> > This is a bit of a tangent, but under what circumstances would `CurPtr - 
> > StartPtr` not be equal to `Buffer.size() + 4`? Actually, I'm not sure that 
> > +4 is correct. It looks like `StartPtr` is expected to point to `N` at the 
> > beginning of the function, so the initial `\` is not included in the range. 
> > If `N` isn't seen, the function returns early. Likewise, if either of the 
> > `{` or `}` delimiters is not found, the function returns early.
> > 
> > I think the goal of this code is to skip the `getAndAdvanceChar()` 
> > machinery when the buffer is being claimed (no need to parse UCNs or 
> > trigraphs in the character name), but it looks like, particularly with this 
> > DR, that we might always be able to do that.
> afaict, 4 is correct here because we are one past-the-end.
> I do however agree that this whole pattern which is used a few times is 
> probably unnecessary, i do think it would be good to investigate. Not in this 
> patch though, imo
I looked into it, I'm sure we could improve but not easily, `getAndAdvanceChar` 
does set some flags on the token in the presence of trigraphs/line splicing and 
we need those flags to be set, this is the reason we do need to call that 
method.
It's not super efficient but it's such an edge case... I'd rather not touch 
that now


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138861

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


[PATCH] D139701: [Clang] Don't emit "min-legal-vector-width"="0" for AMDGPU

2022-12-09 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei created this revision.
pengfei added reviewers: craig.topper, arsenm, RKSimon.
Herald added subscribers: kosarev, StephenFan, jdoerfert, kerbowa, tpr, 
dstuttard, yaxunl, jvesely, kzhuravl.
Herald added a project: All.
pengfei requested review of this revision.
Herald added subscribers: cfe-commits, wdng.
Herald added a project: clang.

This is an alternative way of D139627  
suggested by Craig. I'm not sure
if there are other targets care about this attribute. Let's just start
from AMDGPU.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139701

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/OpenMP/amdgcn-attributes.cpp


Index: clang/test/OpenMP/amdgcn-attributes.cpp
===
--- clang/test/OpenMP/amdgcn-attributes.cpp
+++ clang/test/OpenMP/amdgcn-attributes.cpp
@@ -32,12 +32,12 @@
   return x + 1;
 }
 
-// DEFAULT: attributes #0 = { convergent noinline norecurse nounwind optnone 
"frame-pointer"="none" "kernel" "min-legal-vector-width"="0" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"uniform-work-group-size"="true" }
-// CPU: attributes #0 = { convergent noinline norecurse nounwind optnone 
"frame-pointer"="none" "kernel" "min-legal-vector-width"="0" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst"
 "uniform-work-group-size"="true" }
-// NOIEEE: attributes #0 = { convergent noinline norecurse nounwind optnone 
"amdgpu-ieee"="false" "frame-pointer"="none" "kernel" 
"min-legal-vector-width"="0" "no-nans-fp-math"="true" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "uniform-work-group-size"="true" }
-// UNSAFEATOMIC: attributes #0 = { convergent noinline norecurse nounwind 
optnone "amdgpu-unsafe-fp-atomics"="true" "frame-pointer"="none" "kernel" 
"min-legal-vector-width"="0" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "uniform-work-group-size"="true" }
-
-// DEFAULT: attributes #1 = { convergent mustprogress noinline nounwind 
optnone "frame-pointer"="none" "min-legal-vector-width"="0" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" }
-// CPU: attributes #1 = { convergent mustprogress noinline nounwind optnone 
"frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst"
 }
-// NOIEEE: attributes #1 = { convergent mustprogress noinline nounwind optnone 
"amdgpu-ieee"="false" "frame-pointer"="none" "min-legal-vector-width"="0" 
"no-nans-fp-math"="true" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" }
-// UNSAFEATOMIC: attributes #1 = { convergent mustprogress noinline nounwind 
optnone "amdgpu-unsafe-fp-atomics"="true" "frame-pointer"="none" 
"min-legal-vector-width"="0" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" }
+// DEFAULT: attributes #0 = { convergent noinline norecurse nounwind optnone 
"frame-pointer"="none" "kernel" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "uniform-work-group-size"="true" }
+// CPU: attributes #0 = { convergent noinline norecurse nounwind optnone 
"frame-pointer"="none" "kernel" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst"
 "uniform-work-group-size"="true" }
+// NOIEEE: attributes #0 = { convergent noinline norecurse nounwind optnone 
"amdgpu-ieee"="false" "frame-pointer"="none" "kernel" "no-nans-fp-math"="true" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"uniform-work-group-size"="true" }
+// UNSAFEATOMIC: attributes #0 = { convergent noinline norecurse nounwind 
optnone "amdgpu-unsafe-fp-atomics"="true" "frame-pointer"="none" "kernel" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"uniform-work-group-size"="true" }
+
+// DEFAULT: attributes #1 = { convergent mustprogress noinline nounwind 
optnone "frame-pointer"="none" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" }
+// CPU: attributes #1 = { convergent mustprogress noinline nounwind optnone 
"frame-pointer"="none" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst"
 }
+// NOIEEE: attributes #1 = { convergent mustprogress noinline nounwind optnone 
"amdgpu-ieee"="false" "frame-pointer"="none" "no-nans-fp-math"="true" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" }
+// UNSAFEATOMIC: att

[clang-tools-extra] 526fb5f - [include-cleaner] Fix walkUsed only report a single macro ref.

2022-12-09 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-12-09T12:12:16+01:00
New Revision: 526fb5fae79f1b037eb084783d5eb082258ede9b

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

LOG: [include-cleaner] Fix walkUsed only report a single macro ref.

The fix 962343a979d51cea9363167e9121c446abbdfdbc was reverted during a
rebase of a later patch. Added a test.

Added: 


Modified: 
clang-tools-extra/include-cleaner/lib/Analysis.cpp
clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/Analysis.cpp 
b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
index 95cf8ab7550a5..fa3bbaab27c24 100644
--- a/clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -52,7 +52,7 @@ void walkUsed(llvm::ArrayRef ASTRoots,
   }
   for (const SymbolReference &MacroRef : MacroRefs) {
 assert(MacroRef.Target.kind() == Symbol::Macro);
-return CB(MacroRef, headersForSymbol(MacroRef.Target, SM, PI));
+CB(MacroRef, headersForSymbol(MacroRef.Target, SM, PI));
   }
 }
 

diff  --git a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
index 9a1f4fce801c3..13f5aad4912a4 100644
--- a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -145,25 +145,33 @@ TEST_F(WalkUsedTest, MultipleProviders) {
 TEST_F(WalkUsedTest, MacroRefs) {
   llvm::Annotations Code(R"cpp(
 #include "hdr.h"
-int x = ^ANSWER;
+int x = $1^ANSWER;
+int y = $2^ANSWER;
   )cpp");
   llvm::Annotations Hdr(guard("#define ^ANSWER 42"));
   Inputs.Code = Code.code();
   Inputs.ExtraFiles["hdr.h"] = Hdr.code();
   TestAST AST(Inputs);
   auto &SM = AST.sourceManager();
-  auto HdrFile = SM.getFileManager().getFile("hdr.h").get();
+  const auto *HdrFile = SM.getFileManager().getFile("hdr.h").get();
   auto HdrID = SM.translateFile(HdrFile);
 
   IdentifierTable Idents;
-  Symbol Answer =
+  Symbol Answer1 =
+  Macro{&Idents.get("ANSWER"), SM.getComposedLoc(HdrID, Hdr.point())};
+  Symbol Answer2 =
   Macro{&Idents.get("ANSWER"), SM.getComposedLoc(HdrID, Hdr.point())};
   EXPECT_THAT(
-  offsetToProviders(
-  AST, SM,
-  {SymbolReference{SM.getComposedLoc(SM.getMainFileID(), Code.point()),
-   Answer, RefType::Explicit}}),
-  UnorderedElementsAre(Pair(Code.point(), UnorderedElementsAre(HdrFile;
+  offsetToProviders(AST, SM,
+{SymbolReference{SM.getComposedLoc(SM.getMainFileID(),
+   Code.point("1")),
+ Answer1, RefType::Explicit},
+ SymbolReference{SM.getComposedLoc(SM.getMainFileID(),
+   Code.point("2")),
+ Answer2, RefType::Explicit}}),
+  UnorderedElementsAre(
+  Pair(Code.point("1"), UnorderedElementsAre(HdrFile)),
+  Pair(Code.point("2"), UnorderedElementsAre(HdrFile;
 }
 
 TEST(Analyze, Basic) {



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


[PATCH] D138779: [include-cleaner] Filter out references that not spelled in the main file.

2022-12-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 481591.
hokein marked 4 inline comments as done.
hokein added a comment.

address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138779

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -18,6 +18,7 @@
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -27,6 +28,7 @@
 namespace {
 using testing::Contains;
 using testing::ElementsAre;
+using testing::AllOf;
 using testing::Pair;
 using testing::UnorderedElementsAre;
 
@@ -252,5 +254,126 @@
 )cpp");
 }
 
+MATCHER_P3(expandedAt, FileID, Offset, SM, "") {
+  auto [ExpanedFileID, ExpandedOffset] = SM->getDecomposedExpansionLoc(arg);
+  return ExpanedFileID == FileID && ExpandedOffset == Offset;
+}
+MATCHER_P3(spelledAt, FileID, Offset, SM, "") {
+  auto [SpelledFileID, SpelledOffset] = SM->getDecomposedSpellingLoc(arg);
+  return SpelledFileID == FileID && SpelledOffset == Offset;
+}
+TEST(WalkUsed, FilterRefsNotSpelledInMainFile) {
+  // Each test is expected to have a single expected ref of `target` symbol
+  // (or have none).
+  // The location in the reported ref is a macro location. $expand points to
+  // the macro location, and $spell points to the spelled location.
+  struct {
+llvm::StringRef Header;
+llvm::StringRef Main;
+  } TestCases[] = {
+  // Tests for decl references.
+  {
+  /*Header=*/"int target();",
+  R"cpp(
+#define CALL_FUNC $spell^target()
+
+int b = $expand^CALL_FUNC;
+  )cpp",
+  },
+  {/*Header=*/R"cpp(
+   int target();
+   #define CALL_FUNC target()
+   )cpp",
+   // No ref of `target` being reported, as it is not spelled in main file.
+   "int a = CALL_FUNC;"},
+  {
+  /*Header=*/"int target();",
+  R"cpp(
+#define PLUS_ONE(X) X() + 1
+int a = $expand^PLUS_ONE($spell^target);
+  )cpp",
+  },
+  {
+  /*Header=*/R"cpp(
+int target();
+#define PLUS_ONE(X) X() + 1
+  )cpp",
+  R"cpp(
+int a = $expand^PLUS_ONE($spell^target);
+  )cpp",
+  },
+  {
+  /*Header=*/R"cpp(
+int target();
+#define PLUS_ONE(X) X() + 1
+  )cpp",
+  R"cpp(
+int a = $expand^PLUS_ONE($spell^target);
+  )cpp",
+  },
+  // Tests for macro references
+  {/*Header=*/"#define target 1",
+   R"cpp(
+  #define USE_target $spell^target
+  int b = $expand^USE_target;
+)cpp"},
+  {/*Header=*/R"cpp(
+  #define target 1
+  #define USE_target target
+)cpp",
+   // No ref of `target` being reported, it is not spelled in main file.
+   R"cpp(
+  int a = USE_target;
+)cpp"},
+  };
+
+  for (const auto &T : TestCases) {
+llvm::Annotations Main(T.Main);
+TestInputs Inputs(Main.code());
+Inputs.ExtraFiles["header.h"] = guard(T.Header);
+RecordedPP Recorded;
+Inputs.MakeAction = [&]() {
+  struct RecordAction : public SyntaxOnlyAction {
+RecordedPP &Out;
+RecordAction(RecordedPP &Out) : Out(Out) {}
+bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
+  auto &PP = CI.getPreprocessor();
+  PP.addPPCallbacks(Out.record(PP));
+  return true;
+}
+  };
+  return std::make_unique(Recorded);
+};
+Inputs.ExtraArgs.push_back("-include");
+Inputs.ExtraArgs.push_back("header.h");
+TestAST AST(Inputs);
+llvm::SmallVector TopLevelDecls;
+for (Decl *D : AST.context().getTranslationUnitDecl()->decls())
+  TopLevelDecls.emplace_back(D);
+auto &SM = AST.sourceManager();
+
+SourceLocation RefLoc;
+walkUsed(TopLevelDecls, Recorded.MacroReferences,
+ /*PragmaIncludes=*/nullptr, SM,
+ [&](const SymbolReference &Ref, llvm::ArrayRef) {
+   if (!Ref.RefLocation.isMacroID())
+ return;
+   if (llvm::to_string(Ref.Target) == "target") {
+ ASSERT_TRUE(RefLoc.isInvalid())
+ << "Expected only one 'target' ref loc per testcase";
+ RefLoc = Ref.RefLocatio

[PATCH] D138779: [include-cleaner] Filter out references that not spelled in the main file.

2022-12-09 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks!




Comment at: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp:292
+  R"cpp(
+#define PLUS_ONE(X) X() + 1
+int a = $expand^PLUS_ONE($spell^target);

nit: this and the following test case is pretty much the same. maybe drop this 
one?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138779

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


[clang-tools-extra] edd5d77 - [clangd] NFC. Add a newline at the end of the file

2022-12-09 Thread Ilya Biryukov via cfe-commits

Author: Ilya Biryukov
Date: 2022-12-09T12:31:50+01:00
New Revision: edd5d777e981ab6a4952c14c35f3ead330c4a761

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

LOG: [clangd] NFC. Add a newline at the end of the file

Added: 


Modified: 
clang-tools-extra/clangd/DecisionForest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/DecisionForest.cpp 
b/clang-tools-extra/clangd/DecisionForest.cpp
index 0b54a6c65beb0..a05a9ee436f1d 100644
--- a/clang-tools-extra/clangd/DecisionForest.cpp
+++ b/clang-tools-extra/clangd/DecisionForest.cpp
@@ -95,4 +95,4 @@ evaluateDecisionForest(const SymbolQualitySignals &Quality,
 } // namespace clangd
 } // namespace clang
 
-#endif // !CLANGD_DECISION_FOREST
\ No newline at end of file
+#endif // !CLANGD_DECISION_FOREST



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


[PATCH] D139586: [Clang][C++23] Lifetime extension in range-based for loops

2022-12-09 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

Thanks a lot for working on this.

I will try to do a more detailed review later, but at least I think we might 
want more tests. Maybe codegen tests that do not rely on 
[[clang::lifetimebound]], and tests with more chaining (`a().b().c()`) .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139586

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


[PATCH] D139704: [clang][RISCV] Added target attributes to runtime functions

2022-12-09 Thread Elena Lepilkina via Phabricator via cfe-commits
eklepilkina created this revision.
Herald added subscribers: sunshaoce, VincentWu, vkmr, frasercrmck, evandro, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, 
shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, 
arichardson, nemanjai.
Herald added a project: All.
eklepilkina requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, eopXD, MaskRay.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139704

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/PowerPC/ignore-exceptions.cpp
  clang/test/CodeGen/atomic_ops.c
  clang/test/CodeGen/attr-cpuspecific.c
  clang/test/CodeGen/attr-target-clones.c
  clang/test/CodeGen/attr-target-mv-va-args.c
  clang/test/CodeGen/attr-target-mv.c
  clang/test/CodeGenCXX/RISCV/riscv-target-features-attr.cpp
  clang/test/CodeGenCXX/attr-cpuspecific.cpp
  clang/test/CodeGenCXX/attr-target-clones.cpp
  clang/test/CodeGenCXX/attr-target-mv-diff-ns.cpp
  clang/test/CodeGenCXX/attr-target-mv-member-funcs.cpp
  clang/test/CodeGenCXX/attr-target-mv-out-of-line-defs.cpp
  clang/test/CodeGenCXX/attr-target-mv-overloads.cpp
  clang/test/CodeGenCXX/dynamic-cast.cpp
  clang/test/CodeGenCXX/runtimecc.cpp
  clang/test/CodeGenObjC/arc.m
  clang/test/CodeGenObjC/attr-objc-runtime-visible.m
  clang/test/CodeGenObjC/class-stubs.m
  clang/test/CodeGenObjC/nonlazy-msgSend.m
  clang/test/CodeGenObjC/objc-literal-debugger-test.m
  clang/test/PCH/objc_container.m

Index: clang/test/PCH/objc_container.m
===
--- clang/test/PCH/objc_container.m
+++ clang/test/PCH/objc_container.m
@@ -23,4 +23,4 @@
 // CHECK-IR: ret void
 
 // CHECK-IR: attributes #0 = { noinline nounwind {{.*}} }
-// CHECK-IR: attributes #1 = { nonlazybind }
+// CHECK-IR: attributes #1 = { nonlazybind {{.*}} }
Index: clang/test/CodeGenObjC/objc-literal-debugger-test.m
===
--- clang/test/CodeGenObjC/objc-literal-debugger-test.m
+++ clang/test/CodeGenObjC/objc-literal-debugger-test.m
@@ -52,4 +52,4 @@
 
 // CHECK: declare i8* @objc_msgSend(i8*, i8*, ...) [[NLB:#[0-9]+]]
 
-// CHECK: attributes [[NLB]] = { nonlazybind }
+// CHECK: attributes [[NLB]] = { nonlazybind "frame-pointer"="none" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
Index: clang/test/CodeGenObjC/nonlazy-msgSend.m
===
--- clang/test/CodeGenObjC/nonlazy-msgSend.m
+++ clang/test/CodeGenObjC/nonlazy-msgSend.m
@@ -5,4 +5,4 @@
   [x foo];
 }
 
-// CHECK: attributes [[NLB]] = { nonlazybind }
+// CHECK: attributes [[NLB]] = { nonlazybind {{.*}}}
Index: clang/test/CodeGenObjC/class-stubs.m
===
--- clang/test/CodeGenObjC/class-stubs.m
+++ clang/test/CodeGenObjC/class-stubs.m
@@ -81,4 +81,4 @@
 @end
 
 // -- calls to objc_loadClassRef() are readnone
-// CHECK: attributes [[ATTRLIST]] = { nounwind nonlazybind memory(none) }
+// CHECK: attributes [[ATTRLIST]] = { nounwind nonlazybind memory(none) {{.*}} }
Index: clang/test/CodeGenObjC/attr-objc-runtime-visible.m
===
--- clang/test/CodeGenObjC/attr-objc-runtime-visible.m
+++ clang/test/CodeGenObjC/attr-objc-runtime-visible.m
@@ -14,6 +14,6 @@
 // CHECK: [[CLASSNAME:@.*]] = private unnamed_addr constant [22 x i8] c"MyRuntimeVisibleClass
 // CHECK: define{{.*}} i8* @getClass() #0 {
 Class getClass(void) {
-  // CHECK: call i8* @objc_lookUpClass(i8* getelementptr inbounds ([22 x i8], [22 x i8]* [[CLASSNAME]], i32 0, i32 0)) #2
+  // CHECK: call i8* @objc_lookUpClass(i8* getelementptr inbounds ([22 x i8], [22 x i8]* [[CLASSNAME]], i32 0, i32 0)) #{{[0-9]+}}
   return [A class];
 }
Index: clang/test/CodeGenObjC/arc.m
===
--- clang/test/CodeGenObjC/arc.m
+++ clang/test/CodeGenObjC/arc.m
@@ -1586,6 +1586,6 @@
   __strong id t[] = (__strong id[]){a, b};
 }
 
-// ARC-ALIEN: attributes [[NLB]] = { nonlazybind }
-// ARC-NATIVE: attributes [[NLB]] = { nonlazybind }
-// CHECK: attributes [[NUW]] = { nounwind }
+// ARC-ALIEN: attributes [[NLB]] = { nonlazybind {{.*}}}
+// ARC-NATIVE: attributes [[NLB]] = { nonlazybind {{.*}}}
+// CHECK: attributes [[NUW]] = { nounwind {{.*}}}
Index: clang/test/CodeGenCXX/runtimecc.cpp
===
--- clang/test/CodeGenCXX/runtimecc.cpp
+++ clang/test/CodeGenCXX/runtimecc.cpp
@@ -26,7 +26,7 @@
 // CHECK-NEXT: ret void
 }
 
-// CHECK: declare i32 @__cxa_atexit(ptr, ptr, ptr) [[NOUNWIND]]
+// CHECK: declare i32 @__cxa_atexit(ptr, ptr, ptr) [[NOUNWIND1:#[0-9]+]]
 
 namespac

[clang-tools-extra] bf6e655 - [include-cleaner] Filter out references that not spelled in the main file.

2022-12-09 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-12-09T12:59:34+01:00
New Revision: bf6e65516223586180d4082735b706bd4602ba11

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

LOG: [include-cleaner] Filter out references that not spelled in the main file.

A HTML report of gtest after this patch:
https://gist.githubusercontent.com/hokein/73eee6f65a803e5702d8388c187524a6/raw/cf05a503519703a2fb87840bb0b270fe11a7a9fd/RecordTest.html

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

Added: 


Modified: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
clang-tools-extra/include-cleaner/lib/Analysis.cpp
clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Removed: 




diff  --git 
a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h 
b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
index 146c652f730de..f6afaff09cfd9 100644
--- a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
+++ b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
@@ -40,6 +40,7 @@ using UsedSymbolCB = llvm::function_ref 
Providers)>;
 
 /// Find and report all references to symbols in a region of code.
+/// It only reports references from main file.
 ///
 /// The AST traversal is rooted at ASTRoots - typically top-level declarations
 /// of a single source file.

diff  --git a/clang-tools-extra/include-cleaner/lib/Analysis.cpp 
b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
index fa3bbaab27c24..9ffa8e7f3a15d 100644
--- a/clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -42,8 +42,9 @@ void walkUsed(llvm::ArrayRef ASTRoots,
   // This is duplicated in writeHTMLReport, changes should be mirrored there.
   tooling::stdlib::Recognizer Recognizer;
   for (auto *Root : ASTRoots) {
-auto &SM = Root->getASTContext().getSourceManager();
 walkAST(*Root, [&](SourceLocation Loc, NamedDecl &ND, RefType RT) {
+  if (!SM.isWrittenInMainFile(SM.getSpellingLoc(Loc)))
+return;
   // FIXME: Most of the work done here is repetative. It might be useful to
   // have a cache/batching.
   SymbolReference SymRef{Loc, ND, RT};
@@ -52,7 +53,9 @@ void walkUsed(llvm::ArrayRef ASTRoots,
   }
   for (const SymbolReference &MacroRef : MacroRefs) {
 assert(MacroRef.Target.kind() == Symbol::Macro);
-CB(MacroRef, headersForSymbol(MacroRef.Target, SM, PI));
+if (!SM.isWrittenInMainFile(SM.getSpellingLoc(MacroRef.RefLocation)))
+  continue;
+CB(MacroRef, findHeaders(MacroRef.Target.macro().Definition, SM, PI));
   }
 }
 

diff  --git a/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp 
b/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
index 6d165b5d22ded..22debdc5e83d5 100644
--- a/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
+++ b/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
@@ -518,12 +518,18 @@ void writeHTMLReport(FileID File, const 
include_cleaner::Includes &Includes,
  HeaderSearch &HS, PragmaIncludes *PI,
  llvm::raw_ostream &OS) {
   Reporter R(OS, Ctx, HS, Includes, PI, File);
+  const auto& SM = Ctx.getSourceManager();
   for (Decl *Root : Roots)
 walkAST(*Root, [&](SourceLocation Loc, const NamedDecl &D, RefType T) {
+  if(!SM.isWrittenInMainFile(SM.getSpellingLoc(Loc)))
+return;
   R.addRef(SymbolReference{Loc, D, T});
 });
-  for (const SymbolReference &Ref : MacroRefs)
+  for (const SymbolReference &Ref : MacroRefs) {
+if (!SM.isWrittenInMainFile(SM.getSpellingLoc(Ref.RefLocation)))
+  continue;
 R.addRef(Ref);
+  }
   R.write();
 }
 

diff  --git a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
index 13f5aad4912a4..72bec106c12e0 100644
--- a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -18,6 +18,7 @@
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -27,6 +28,7 @@ namespace clang::include_cleaner {
 namespace {
 using testing::Contains;
 using testing::ElementsAre;
+using testing::AllOf;
 using testing::Pair;
 using testing::UnorderedElementsAre;
 
@@ -252,5 +254,119 @@ TEST(FixIncludes, Basic) {
 )cpp");
 }
 
+MATCHER_P3(expandedAt, FileID, Offset, SM, "") {
+  auto [ExpanedFileID, ExpandedOffset] = SM->getDecomposedExpansionLoc(arg);
+  return ExpanedFileID 

[PATCH] D138779: [include-cleaner] Filter out references that not spelled in the main file.

2022-12-09 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
hokein marked an inline comment as done.
Closed by commit rGbf6e65516223: [include-cleaner] Filter out references that 
not spelled in the main file. (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D138779?vs=481591&id=481598#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138779

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -18,6 +18,7 @@
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -27,6 +28,7 @@
 namespace {
 using testing::Contains;
 using testing::ElementsAre;
+using testing::AllOf;
 using testing::Pair;
 using testing::UnorderedElementsAre;
 
@@ -252,5 +254,119 @@
 )cpp");
 }
 
+MATCHER_P3(expandedAt, FileID, Offset, SM, "") {
+  auto [ExpanedFileID, ExpandedOffset] = SM->getDecomposedExpansionLoc(arg);
+  return ExpanedFileID == FileID && ExpandedOffset == Offset;
+}
+MATCHER_P3(spelledAt, FileID, Offset, SM, "") {
+  auto [SpelledFileID, SpelledOffset] = SM->getDecomposedSpellingLoc(arg);
+  return SpelledFileID == FileID && SpelledOffset == Offset;
+}
+TEST(WalkUsed, FilterRefsNotSpelledInMainFile) {
+  // Each test is expected to have a single expected ref of `target` symbol
+  // (or have none).
+  // The location in the reported ref is a macro location. $expand points to
+  // the macro location, and $spell points to the spelled location.
+  struct {
+llvm::StringRef Header;
+llvm::StringRef Main;
+  } TestCases[] = {
+  // Tests for decl references.
+  {
+  /*Header=*/"int target();",
+  R"cpp(
+#define CALL_FUNC $spell^target()
+
+int b = $expand^CALL_FUNC;
+  )cpp",
+  },
+  {/*Header=*/R"cpp(
+   int target();
+   #define CALL_FUNC target()
+   )cpp",
+   // No ref of `target` being reported, as it is not spelled in main file.
+   "int a = CALL_FUNC;"},
+  {
+  /*Header=*/R"cpp(
+int target();
+#define PLUS_ONE(X) X() + 1
+  )cpp",
+  R"cpp(
+int a = $expand^PLUS_ONE($spell^target);
+  )cpp",
+  },
+  {
+  /*Header=*/R"cpp(
+int target();
+#define PLUS_ONE(X) X() + 1
+  )cpp",
+  R"cpp(
+int a = $expand^PLUS_ONE($spell^target);
+  )cpp",
+  },
+  // Tests for macro references
+  {/*Header=*/"#define target 1",
+   R"cpp(
+  #define USE_target $spell^target
+  int b = $expand^USE_target;
+)cpp"},
+  {/*Header=*/R"cpp(
+  #define target 1
+  #define USE_target target
+)cpp",
+   // No ref of `target` being reported, it is not spelled in main file.
+   R"cpp(
+  int a = USE_target;
+)cpp"},
+  };
+
+  for (const auto &T : TestCases) {
+llvm::Annotations Main(T.Main);
+TestInputs Inputs(Main.code());
+Inputs.ExtraFiles["header.h"] = guard(T.Header);
+RecordedPP Recorded;
+Inputs.MakeAction = [&]() {
+  struct RecordAction : public SyntaxOnlyAction {
+RecordedPP &Out;
+RecordAction(RecordedPP &Out) : Out(Out) {}
+bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
+  auto &PP = CI.getPreprocessor();
+  PP.addPPCallbacks(Out.record(PP));
+  return true;
+}
+  };
+  return std::make_unique(Recorded);
+};
+Inputs.ExtraArgs.push_back("-include");
+Inputs.ExtraArgs.push_back("header.h");
+TestAST AST(Inputs);
+llvm::SmallVector TopLevelDecls;
+for (Decl *D : AST.context().getTranslationUnitDecl()->decls())
+  TopLevelDecls.emplace_back(D);
+auto &SM = AST.sourceManager();
+
+SourceLocation RefLoc;
+walkUsed(TopLevelDecls, Recorded.MacroReferences,
+ /*PragmaIncludes=*/nullptr, SM,
+ [&](const SymbolReference &Ref, llvm::ArrayRef) {
+   if (!Ref.RefLocation.isMacroID())
+ return;
+   if (llvm::to_string(Ref.Target) == "target") {
+ ASSERT_TRUE(RefLoc.isInvalid())
+ << "Expected only one 'target' re

[PATCH] D139705: [clang] fix zero-initialization fix-it for variable template

2022-12-09 Thread v1nh1shungry via Phabricator via cfe-commits
v1nh1shungry created this revision.
v1nh1shungry added reviewers: aaron.ballman, erichkeane.
Herald added a project: All.
v1nh1shungry requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Current version there is a fix-it for

  cpp
  template  constexpr int x = 0;
  template <> constexpr int x; // fix-it here

but it will cause

  cpp
  template <> constexpr int x = 0;


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139705

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/FixIt/fixit-const-var-init.cpp


Index: clang/test/FixIt/fixit-const-var-init.cpp
===
--- /dev/null
+++ clang/test/FixIt/fixit-const-var-init.cpp
@@ -0,0 +1,25 @@
+// RUN: not %clang_cc1 -fdiagnostics-parseable-fixits -x c++ -std=c++14 %s 
2>&1 | FileCheck %s
+
+const int a; // expected-error {{default initialization of an object of const 
type}}
+// CHECK: fix-it:"{{.*}}":{3:12-3:12}:" = 0"
+
+template  const int b; // expected-error {{default 
initialization of an object of const type}}
+// CHECK: fix-it:"{{.*}}":{6:36-6:36}:" = 0"
+
+template  const int b; // expected-error {{default 
initialization of an object of const type}}
+// CHECK: fix-it:"{{.*}}":{9:39-9:39}:" = 0"
+
+template <> const int b; // expected-error {{default 
initialization of an object of const type}}
+// CHECK: fix-it:"{{.*}}":{12:36-12:36}:" = 0"
+
+constexpr float c; // expected-error {{must be initialized by a constant 
expression}}
+// CHECK: fix-it:"{{.*}}":{15:18-15:18}:" = 0.0"
+
+template  constexpr float d; // expected-error {{must be 
initialized by a constant expression}}
+// CHECK: fix-it:"{{.*}}":{18:42-18:42}:" = 0.0"
+
+template  constexpr float d; // expected-error {{must be 
initialized by a constant expression}}
+// CHECK: fix-it:"{{.*}}":{21:45-21:45}:" = 0.0"
+
+template <> constexpr float d; // expected-error {{must be 
initialized by a constant expression}}
+// CHECK: fix-it:"{{.*}}":{24:42-24:42}:" = 0.0"
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -3860,8 +3860,20 @@
   if (VD->getInit() || VD->getEndLoc().isMacroID())
 return false;
 
+  SourceLocation EndLoc = VD->getEndLoc();
+  if (const auto *VTSD = dyn_cast(VD)) {
+if (const auto *VTPSD =
+dyn_cast(VD)) {
+  if (const ASTTemplateArgumentListInfo *Info =
+  VTPSD->getTemplateArgsAsWritten())
+EndLoc = Info->getRAngleLoc();
+}
+if (const ASTTemplateArgumentListInfo *Info = VTSD->getTemplateArgsInfo())
+  EndLoc = Info->getRAngleLoc();
+  }
+
   QualType VariableTy = VD->getType().getCanonicalType();
-  SourceLocation Loc = S.getLocForEndOfToken(VD->getEndLoc());
+  SourceLocation Loc = S.getLocForEndOfToken(EndLoc);
   std::string Init = S.getFixItZeroInitializerForType(VariableTy, Loc);
   if (!Init.empty()) {
 Sequence.AddZeroInitializationStep(Entity.getType());


Index: clang/test/FixIt/fixit-const-var-init.cpp
===
--- /dev/null
+++ clang/test/FixIt/fixit-const-var-init.cpp
@@ -0,0 +1,25 @@
+// RUN: not %clang_cc1 -fdiagnostics-parseable-fixits -x c++ -std=c++14 %s 2>&1 | FileCheck %s
+
+const int a; // expected-error {{default initialization of an object of const type}}
+// CHECK: fix-it:"{{.*}}":{3:12-3:12}:" = 0"
+
+template  const int b; // expected-error {{default initialization of an object of const type}}
+// CHECK: fix-it:"{{.*}}":{6:36-6:36}:" = 0"
+
+template  const int b; // expected-error {{default initialization of an object of const type}}
+// CHECK: fix-it:"{{.*}}":{9:39-9:39}:" = 0"
+
+template <> const int b; // expected-error {{default initialization of an object of const type}}
+// CHECK: fix-it:"{{.*}}":{12:36-12:36}:" = 0"
+
+constexpr float c; // expected-error {{must be initialized by a constant expression}}
+// CHECK: fix-it:"{{.*}}":{15:18-15:18}:" = 0.0"
+
+template  constexpr float d; // expected-error {{must be initialized by a constant expression}}
+// CHECK: fix-it:"{{.*}}":{18:42-18:42}:" = 0.0"
+
+template  constexpr float d; // expected-error {{must be initialized by a constant expression}}
+// CHECK: fix-it:"{{.*}}":{21:45-21:45}:" = 0.0"
+
+template <> constexpr float d; // expected-error {{must be initialized by a constant expression}}
+// CHECK: fix-it:"{{.*}}":{24:42-24:42}:" = 0.0"
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -3860,8 +3860,20 @@
   if (VD->getInit() || VD->getEndLoc().isMacroID())
 return false;
 
+  SourceLocation EndLoc = VD->getEndLoc();
+  if (const auto *VTSD = dyn_cast(VD)) {
+if (const auto *VTPSD =
+dyn_cast(VD)) {
+  if (const ASTTemplateArgumentListInfo *Info =
+  VTPSD->getTemp

Re: [clang] d881fdf - Revert "Recommit of 8ae18303f97d5dcfaecc90b4d87effb2011ed82e - part 2"

2022-12-09 Thread Roman Lebedev via cfe-commits
Reminder to please always mention the reason for the revert in the
commit message.

On Fri, Dec 9, 2022 at 12:15 PM via cfe-commits
 wrote:
>
>
> Author: serge-sans-paille
> Date: 2022-12-09T10:15:41+01:00
> New Revision: d881fdf72047fd18b88c6a65d0966cad542c95cd
>
> URL: 
> https://github.com/llvm/llvm-project/commit/d881fdf72047fd18b88c6a65d0966cad542c95cd
> DIFF: 
> https://github.com/llvm/llvm-project/commit/d881fdf72047fd18b88c6a65d0966cad542c95cd.diff
>
> LOG: Revert "Recommit of 8ae18303f97d5dcfaecc90b4d87effb2011ed82e - part 2"
>
> This reverts commit 4faf6cf989f3ae212912994022c0486a2dc4.
>
> Added:
>
>
> Modified:
> clang/lib/Driver/ToolChains/Gnu.cpp
> lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
> llvm/include/llvm/Option/OptTable.h
> llvm/lib/Option/OptTable.cpp
> llvm/unittests/Option/OptionMarshallingTest.cpp
> llvm/utils/TableGen/OptParserEmitter.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
> b/clang/lib/Driver/ToolChains/Gnu.cpp
> index 60d62e2b9c5c1..4621850f13772 100644
> --- a/clang/lib/Driver/ToolChains/Gnu.cpp
> +++ b/clang/lib/Driver/ToolChains/Gnu.cpp
> @@ -331,8 +331,8 @@ static bool getStaticPIE(const ArgList &Args, const 
> ToolChain &TC) {
>if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) {
>  const Driver &D = TC.getDriver();
>  const llvm::opt::OptTable &Opts = D.getOpts();
> -StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
> -StringRef NoPIEName = Opts.getOptionName(options::OPT_nopie);
> +const char *StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
> +const char *NoPIEName = Opts.getOptionName(options::OPT_nopie);
>  D.Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName;
>}
>return HasStaticPIE;
>
> diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp 
> b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
> index fde098840be4b..9d89148616be1 100644
> --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
> +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
> @@ -1055,7 +1055,7 @@ void 
> PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
>// Only add the version-min options if we got a version from somewhere
>if (!version.empty() && sdk_type != XcodeSDK::Type::Linux) {
>  #define OPTION(PREFIX, NAME, VAR, ...)   
>   \
> -  llvm::StringRef opt_##VAR = NAME;  
>   \
> +  const char *opt_##VAR = NAME;  
>   \
>(void)opt_##VAR;
>  #include "clang/Driver/Options.inc"
>  #undef OPTION
>
> diff  --git a/llvm/include/llvm/Option/OptTable.h 
> b/llvm/include/llvm/Option/OptTable.h
> index 390462d762e61..07d9870f71b33 100644
> --- a/llvm/include/llvm/Option/OptTable.h
> +++ b/llvm/include/llvm/Option/OptTable.h
> @@ -102,7 +102,9 @@ class OptTable {
>const Option getOption(OptSpecifier Opt) const;
>
>/// Lookup the name of the given option.
> -  StringRef getOptionName(OptSpecifier id) const { return getInfo(id).Name; }
> +  const char *getOptionName(OptSpecifier id) const {
> +return getInfo(id).Name;
> +  }
>
>/// Get the kind of the given option.
>unsigned getOptionKind(OptSpecifier id) const {
>
> diff  --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
> index f4426bc34b3f9..ef4873eb7f9c4 100644
> --- a/llvm/lib/Option/OptTable.cpp
> +++ b/llvm/lib/Option/OptTable.cpp
> @@ -36,10 +36,16 @@ namespace opt {
>  // Ordering on Info. The ordering is *almost* case-insensitive lexicographic,
>  // with an exception. '\0' comes at the end of the alphabet instead of the
>  // beginning (thus options precede any other options which prefix them).
> -static int StrCmpOptionNameIgnoreCase(StringRef A, StringRef B) {
> -  size_t MinSize = std::min(A.size(), B.size());
> -  if (int Res = A.substr(0, MinSize).compare_insensitive(B.substr(0, 
> MinSize)))
> -return Res;
> +static int StrCmpOptionNameIgnoreCase(const char *A, const char *B) {
> +  const char *X = A, *Y = B;
> +  char a = tolower(*A), b = tolower(*B);
> +  while (a == b) {
> +if (a == '\0')
> +  return 0;
> +
> +a = tolower(*++X);
> +b = tolower(*++Y);
> +  }
>
>if (a == '\0') // A is a prefix of B.
>  return 1;
> @@ -54,7 +60,7 @@ static int StrCmpOptionNameIgnoreCase(StringRef A, 
> StringRef B) {
>  static int StrCmpOptionName(const char *A, const char *B) {
>if (int N = StrCmpOptionNameIgnoreCase(A, B))
>  return N;
> -  return A.compare(B);
> +  return strcmp(A, B);
>  }
>
>  static inline bool operator<(const OptTable::Info &A, const OptTable::Info 
> &B) {
> @@ -180,7 +186,7 @@ static unsigned matchOption(const OptTable::Info *I, 
> StringRef Str,
>bool Matched = IgnoreCase ? Rest.startswith_insensitive(I->Name)
>   

[clang] 77ab728 - [analyzer][solver] Introduce reasoning for not equal to operator

2022-12-09 Thread Balazs Benics via cfe-commits

Author: Manas
Date: 2022-12-09T13:30:57+01:00
New Revision: 77ab7281aa36800dc77dab07bd40e6e0fd9f0b78

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

LOG: [analyzer][solver] Introduce reasoning for not equal to operator

With this patch, the solver can infer results for not equal (!=) operator
over Ranges as well. This also fixes the issue of comparison between
different types, by first converting the RangeSets to the resulting type,
which then can be used for comparisons.

Patch by Manas.

Reviewed By: steakhal

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
clang/test/Analysis/constant-folding.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index ca9bc523b1d55..eda06c64a9f4b 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1333,18 +1333,7 @@ class SymbolicRangeInferrer
   }
 
   RangeSet VisitBinaryOperator(RangeSet LHS, BinaryOperator::Opcode Op,
-   RangeSet RHS, QualType T) {
-switch (Op) {
-case BO_Or:
-  return VisitBinaryOperator(LHS, RHS, T);
-case BO_And:
-  return VisitBinaryOperator(LHS, RHS, T);
-case BO_Rem:
-  return VisitBinaryOperator(LHS, RHS, T);
-default:
-  return infer(T);
-}
-  }
+   RangeSet RHS, QualType T);
 
   
//===--===//
   // Ranges and operators
@@ -1625,6 +1614,32 @@ class SymbolicRangeInferrer
 //   Range-based reasoning about symbolic operations
 
//===--===//
 
+template <>
+RangeSet SymbolicRangeInferrer::VisitBinaryOperator(RangeSet LHS,
+   RangeSet RHS,
+   QualType T) {
+
+  assert(!LHS.isEmpty() && !RHS.isEmpty() && "Both ranges should be 
non-empty");
+
+  if (LHS.getAPSIntType() == RHS.getAPSIntType()) {
+if (intersect(RangeFactory, LHS, RHS).isEmpty())
+  return getTrueRange(T);
+  } else {
+// Both RangeSets should be casted to bigger unsigned type.
+APSIntType CastingType(std::max(LHS.getBitWidth(), RHS.getBitWidth()),
+   LHS.isUnsigned() || RHS.isUnsigned());
+
+RangeSet CastedLHS = RangeFactory.castTo(LHS, CastingType);
+RangeSet CastedRHS = RangeFactory.castTo(RHS, CastingType);
+
+if (intersect(RangeFactory, CastedLHS, CastedRHS).isEmpty())
+  return getTrueRange(T);
+  }
+
+  // In all other cases, the resulting range cannot be deduced.
+  return infer(T);
+}
+
 template <>
 RangeSet SymbolicRangeInferrer::VisitBinaryOperator(Range LHS, Range 
RHS,
QualType T) {
@@ -1785,6 +1800,23 @@ RangeSet 
SymbolicRangeInferrer::VisitBinaryOperator(Range LHS,
   return {RangeFactory, ValueFactory.getValue(Min), 
ValueFactory.getValue(Max)};
 }
 
+RangeSet SymbolicRangeInferrer::VisitBinaryOperator(RangeSet LHS,
+BinaryOperator::Opcode Op,
+RangeSet RHS, QualType T) {
+  switch (Op) {
+  case BO_NE:
+return VisitBinaryOperator(LHS, RHS, T);
+  case BO_Or:
+return VisitBinaryOperator(LHS, RHS, T);
+  case BO_And:
+return VisitBinaryOperator(LHS, RHS, T);
+  case BO_Rem:
+return VisitBinaryOperator(LHS, RHS, T);
+  default:
+return infer(T);
+  }
+}
+
 
//===--===//
 //  Constraint manager implementation details
 
//===--===//

diff  --git a/clang/test/Analysis/constant-folding.c 
b/clang/test/Analysis/constant-folding.c
index 5de4f0ae3cd35..f0598d4ae948b 100644
--- a/clang/test/Analysis/constant-folding.c
+++ b/clang/test/Analysis/constant-folding.c
@@ -281,3 +281,152 @@ void testRemainderRules(unsigned int a, unsigned int b, 
int c, int d) {
 clang_analyzer_eval((b % a) < x + 10); // expected-warning{{TRUE}}
   }
 }
+
+void testDisequalityRules(unsigned int u1, unsigned int u2, unsigned int u3,
+  int s1, int s2, int s3, unsigned char uch,
+  signed char sch, short ssh, unsigned short ush) {
+
+  // Checks for overflowing values
+  if (u1 > INT_MAX && u1 <= UINT_MAX / 2 + 4 && u1 != UINT_MAX / 2 + 2 &&
+  u1 != UINT_MAX / 2 + 3 && s1 >= INT_MIN + 1 &

Re: [clang] d881fdf - Revert "Recommit of 8ae18303f97d5dcfaecc90b4d87effb2011ed82e - part 2"

2022-12-09 Thread Roman Lebedev via cfe-commits
Also, when recommiting these patches, please fix the commit message,
the current one is very non-descriptive.

On Fri, Dec 9, 2022 at 12:15 PM via cfe-commits
 wrote:
>
>
> Author: serge-sans-paille
> Date: 2022-12-09T10:15:41+01:00
> New Revision: d881fdf72047fd18b88c6a65d0966cad542c95cd
>
> URL: 
> https://github.com/llvm/llvm-project/commit/d881fdf72047fd18b88c6a65d0966cad542c95cd
> DIFF: 
> https://github.com/llvm/llvm-project/commit/d881fdf72047fd18b88c6a65d0966cad542c95cd.diff
>
> LOG: Revert "Recommit of 8ae18303f97d5dcfaecc90b4d87effb2011ed82e - part 2"
>
> This reverts commit 4faf6cf989f3ae212912994022c0486a2dc4.
>
> Added:
>
>
> Modified:
> clang/lib/Driver/ToolChains/Gnu.cpp
> lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
> llvm/include/llvm/Option/OptTable.h
> llvm/lib/Option/OptTable.cpp
> llvm/unittests/Option/OptionMarshallingTest.cpp
> llvm/utils/TableGen/OptParserEmitter.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
> b/clang/lib/Driver/ToolChains/Gnu.cpp
> index 60d62e2b9c5c1..4621850f13772 100644
> --- a/clang/lib/Driver/ToolChains/Gnu.cpp
> +++ b/clang/lib/Driver/ToolChains/Gnu.cpp
> @@ -331,8 +331,8 @@ static bool getStaticPIE(const ArgList &Args, const 
> ToolChain &TC) {
>if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) {
>  const Driver &D = TC.getDriver();
>  const llvm::opt::OptTable &Opts = D.getOpts();
> -StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
> -StringRef NoPIEName = Opts.getOptionName(options::OPT_nopie);
> +const char *StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
> +const char *NoPIEName = Opts.getOptionName(options::OPT_nopie);
>  D.Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName;
>}
>return HasStaticPIE;
>
> diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp 
> b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
> index fde098840be4b..9d89148616be1 100644
> --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
> +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
> @@ -1055,7 +1055,7 @@ void 
> PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
>// Only add the version-min options if we got a version from somewhere
>if (!version.empty() && sdk_type != XcodeSDK::Type::Linux) {
>  #define OPTION(PREFIX, NAME, VAR, ...)   
>   \
> -  llvm::StringRef opt_##VAR = NAME;  
>   \
> +  const char *opt_##VAR = NAME;  
>   \
>(void)opt_##VAR;
>  #include "clang/Driver/Options.inc"
>  #undef OPTION
>
> diff  --git a/llvm/include/llvm/Option/OptTable.h 
> b/llvm/include/llvm/Option/OptTable.h
> index 390462d762e61..07d9870f71b33 100644
> --- a/llvm/include/llvm/Option/OptTable.h
> +++ b/llvm/include/llvm/Option/OptTable.h
> @@ -102,7 +102,9 @@ class OptTable {
>const Option getOption(OptSpecifier Opt) const;
>
>/// Lookup the name of the given option.
> -  StringRef getOptionName(OptSpecifier id) const { return getInfo(id).Name; }
> +  const char *getOptionName(OptSpecifier id) const {
> +return getInfo(id).Name;
> +  }
>
>/// Get the kind of the given option.
>unsigned getOptionKind(OptSpecifier id) const {
>
> diff  --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
> index f4426bc34b3f9..ef4873eb7f9c4 100644
> --- a/llvm/lib/Option/OptTable.cpp
> +++ b/llvm/lib/Option/OptTable.cpp
> @@ -36,10 +36,16 @@ namespace opt {
>  // Ordering on Info. The ordering is *almost* case-insensitive lexicographic,
>  // with an exception. '\0' comes at the end of the alphabet instead of the
>  // beginning (thus options precede any other options which prefix them).
> -static int StrCmpOptionNameIgnoreCase(StringRef A, StringRef B) {
> -  size_t MinSize = std::min(A.size(), B.size());
> -  if (int Res = A.substr(0, MinSize).compare_insensitive(B.substr(0, 
> MinSize)))
> -return Res;
> +static int StrCmpOptionNameIgnoreCase(const char *A, const char *B) {
> +  const char *X = A, *Y = B;
> +  char a = tolower(*A), b = tolower(*B);
> +  while (a == b) {
> +if (a == '\0')
> +  return 0;
> +
> +a = tolower(*++X);
> +b = tolower(*++Y);
> +  }
>
>if (a == '\0') // A is a prefix of B.
>  return 1;
> @@ -54,7 +60,7 @@ static int StrCmpOptionNameIgnoreCase(StringRef A, 
> StringRef B) {
>  static int StrCmpOptionName(const char *A, const char *B) {
>if (int N = StrCmpOptionNameIgnoreCase(A, B))
>  return N;
> -  return A.compare(B);
> +  return strcmp(A, B);
>  }
>
>  static inline bool operator<(const OptTable::Info &A, const OptTable::Info 
> &B) {
> @@ -180,7 +186,7 @@ static unsigned matchOption(const OptTable::Info *I, 
> StringRef Str,
>bool Matched = IgnoreCase ? Rest.startswith_insensitiv

[PATCH] D112621: [analyzer][solver] Introduce reasoning for not equal to operator

2022-12-09 Thread Balázs Benics 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 rG77ab7281aa36: [analyzer][solver] Introduce reasoning for not 
equal to operator (authored by manas, committed by steakhal).

Changed prior to commit:
  https://reviews.llvm.org/D112621?vs=481560&id=481602#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112621

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/constant-folding.c

Index: clang/test/Analysis/constant-folding.c
===
--- clang/test/Analysis/constant-folding.c
+++ clang/test/Analysis/constant-folding.c
@@ -281,3 +281,152 @@
 clang_analyzer_eval((b % a) < x + 10); // expected-warning{{TRUE}}
   }
 }
+
+void testDisequalityRules(unsigned int u1, unsigned int u2, unsigned int u3,
+  int s1, int s2, int s3, unsigned char uch,
+  signed char sch, short ssh, unsigned short ush) {
+
+  // Checks for overflowing values
+  if (u1 > INT_MAX && u1 <= UINT_MAX / 2 + 4 && u1 != UINT_MAX / 2 + 2 &&
+  u1 != UINT_MAX / 2 + 3 && s1 >= INT_MIN + 1 && s1 <= INT_MIN + 2) {
+// u1: [INT_MAX+1, INT_MAX+1]U[INT_MAX+4, INT_MAX+4],
+// s1: [INT_MIN+1, INT_MIN+2]
+clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
+  }
+
+  if (u1 >= INT_MIN && u1 <= INT_MIN + 2 &&
+  s1 > INT_MIN + 2 && s1 < INT_MIN + 4) {
+// u1: [INT_MAX+1, INT_MAX+1]U[INT_MAX+4, INT_MAX+4],
+// s1: [INT_MIN+3, INT_MIN+3]
+clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
+  }
+
+  if (s1 < 0 && s1 > -4 && u1 > UINT_MAX - 4 && u1 < UINT_MAX - 1) {
+// s1: [-3, -1], u1: [UINT_MAX - 3, UINT_MAX - 2]
+clang_analyzer_eval(u1 != s1); // expected-warning{{UNKNOWN}}
+  }
+
+  if (s1 < 1 && s1 > -6 && s1 != -4 && s1 != -3 &&
+  u1 > UINT_MAX - 4 && u1 < UINT_MAX - 1) {
+// s1: [-5, -5]U[-2, 0], u1: [UINT_MAX - 3, UINT_MAX - 2]
+clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
+  }
+
+  if (s1 < 1 && s1 > -7 && s1 != -4 && s1 != -3 &&
+  u1 > UINT_MAX - 4 && u1 < UINT_MAX - 1) {
+// s1: [-6, -5]U[-2, 0], u1: [UINT_MAX - 3, UINT_MAX - 2]
+clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
+  }
+
+  if (s1 > 4 && u1 < 4) {
+// s1: [4, INT_MAX], u1: [0, 3]
+clang_analyzer_eval(s1 != u1); // expected-warning{{TRUE}}
+  }
+
+  // Check when RHS is in between two Ranges in LHS
+  if (((u1 >= 1 && u1 <= 2) || (u1 >= 8 && u1 <= 9)) &&
+  u2 >= 5 && u2 <= 6) {
+// u1: [1, 2]U[8, 9], u2: [5, 6]
+clang_analyzer_eval(u1 != u2); // expected-warning{{TRUE}}
+  }
+
+  // Checks for concrete value with same type
+  if (u1 > 1 && u1 < 3 && u2 > 1 && u2 < 3) {
+// u1: [2, 2], u2: [2, 2]
+clang_analyzer_eval(u1 != u2); // expected-warning{{FALSE}}
+  }
+
+  // Check for concrete value with different types
+  if (u1 > 4 && u1 < 6 && s1 > 4 && s1 < 6) {
+// u1: [5, 5], s1: [5, 5]
+clang_analyzer_eval(u1 != s1); // expected-warning{{FALSE}}
+  }
+
+  // Checks when ranges are not overlapping
+  if (u1 <= 10 && u2 >= 20) {
+// u1: [0,10], u2: [20,UINT_MAX]
+clang_analyzer_eval(u1 != u2); // expected-warning{{TRUE}}
+  }
+
+  if (s1 <= INT_MIN + 10 && s2 >= INT_MAX - 10) {
+// s1: [INT_MIN,INT_MIN + 10], s2: [INT_MAX - 10,INT_MAX]
+clang_analyzer_eval(s1 != s2); // expected-warning{{TRUE}}
+  }
+
+  // Checks when ranges are completely overlapping and have more than one point
+  if (u1 >= 20 && u1 <= 50 && u2 >= 20 && u2 <= 50) {
+// u1: [20,50], u2: [20,50]
+clang_analyzer_eval(u1 != u2); // expected-warning{{UNKNOWN}}
+  }
+
+  if (s1 >= -20 && s1 <= 20 && s2 >= -20 && s2 <= 20) {
+// s1: [-20,20], s2: [-20,20]
+clang_analyzer_eval(s1 != s2); // expected-warning{{UNKNOWN}}
+  }
+
+  // Checks when ranges are partially overlapping
+  if (u1 >= 100 && u1 <= 200 && u2 >= 150 && u2 <= 300) {
+// u1: [100,200], u2: [150,300]
+clang_analyzer_eval(u1 != u2); // expected-warning{{UNKNOWN}}
+  }
+
+  if (s1 >= -80 && s1 <= -50 && s2 >= -100 && s2 <= -75) {
+// s1: [-80,-50], s2: [-100,-75]
+clang_analyzer_eval(s1 != s2); // expected-warning{{UNKNOWN}}
+  }
+
+  // Checks for ranges which are subset of one-another
+  if (u1 >= 500 && u1 <= 1000 && u2 >= 750 && u2 <= 1000) {
+// u1: [500,1000], u2: [750,1000]
+clang_analyzer_eval(u1 != u2); // expected-warning{{UNKNOWN}}
+  }
+
+  if (s1 >= -1000 && s1 <= -500 && s2 >= -750 && s2 <= -500) {
+// s1: [-1000,-500], s2: [-750, -500]
+clang_analyzer_eval(s1 != s2); // expected-warning{{UNKNOWN}}
+  }
+
+  // Checks for comparison between different types
+  // Using different variables as previous constraints may interfere in the
+  // reasoning.
+  if (u3 <= 255 && s3 < 0) {
+// u3: [0, 255], s3: [INT_MIN, -1]
+  

[PATCH] D139544: [clang][dataflow] Add support for structured bindings of tuple-like types.

2022-12-09 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

> Those BindingDecls never appear in the CFG unless one of the is used.

Indeed. That''s the issue (which this discussion has helped clarify) -- the 
binding decls are not in the CFG and I was expecting them to be.

> By the time you see this node, the variable has already been created and you 
> can access it using BindingDecl::getHoldingVar(). You want to analyze these 
> BindingDecls when they are used not when you encounter the DecompositionDecl.

Great, that's exactly what this patch does. So, it sounds like we have what we 
need.  Thank you!

Gabor -- now that I understand the issues involved, I think there are two 
options here:

1. When we encounter a `DeclRefExpr` to a `BindingDecl`, just treat that 
DeclRefExpr as the underlying binding expression. So, BindingDecl's are never 
interpreted directly -- we always see through them to their binding expression.
2. (What I have here): When we encounter a `DeclRefExpr` to a `BindingDecl`, 
force the evaluation of the `BindingDecl` and leave the handling of the 
`DeclRefExpr` as is.

Based on this discussion, I'm inclined to go with the first option. Moreover, 
we could use it *for all* `BindingDecl`s, not just tuple-typed decls and 
thereby entirely drop the custom handling of `BindingDecl`s. WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139544

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


[clang] 3fffe68 - [Serialization] Add -ftime-trace block for reading loaded modules.

2022-12-09 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-12-09T14:36:57+01:00
New Revision: 3fffe6826448ac2daf9c4feb8e48ae8d601aca06

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

LOG: [Serialization] Add -ftime-trace block for reading loaded modules.

The existing ReadAST block only describes the top-level PCM file being
loaded, when in practice most of the time taken is dealing with other
PCM files which are loaded in turn.

Because this work isn't strictly recursive (first all the modules are
discovered, then processsed in several flat loops), we can't have a neat
recursive structure like processing of source files. Instead, slap a
timer on the largest of these boxes: reading the AST block for modules.
In practice this shows where most of the time goes, and in particular
which modules are most expensive.

Added: 


Modified: 
clang/lib/Serialization/ASTReader.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index a775d14c5ac13..f577eba6e04be 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -4295,6 +4295,7 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef 
FileName,
   // hit errors parsing the ASTs at this point.
   for (ImportedModule &M : Loaded) {
 ModuleFile &F = *M.Mod;
+llvm::TimeTraceScope Scope2("Read Loaded AST", F.ModuleName);
 
 // Read the AST block.
 if (llvm::Error Err = ReadASTBlock(F, ClientLoadCapabilities)) {



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


[clang] 1481fcf - [clang] Try to unbreak test/C/drs/dr324.c on Windows

2022-12-09 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2022-12-09T08:57:28-05:00
New Revision: 1481fcf780bde7b115aa395064d71749b1a40889

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

LOG: [clang] Try to unbreak test/C/drs/dr324.c on Windows

The test uses

#pragma GCC dependency "oops\..\dr0xx.c"

to test preprocessor "tokenization obscurities". However, that
pragma also emits a warning if the refered file is newer than the
current file -- and d694e2490af8 edited dr0xx.c, causing this warning
to fire.

As workaround, touch this file, so that it's newer than dr0xx.c again.

Added: 


Modified: 
clang/test/C/drs/dr324.c

Removed: 




diff  --git a/clang/test/C/drs/dr324.c b/clang/test/C/drs/dr324.c
index 870232c2e86ae..9d5264017b3db 100644
--- a/clang/test/C/drs/dr324.c
+++ b/clang/test/C/drs/dr324.c
@@ -21,7 +21,7 @@ char lit_char = '\y';   /* expected-warning {{unknown 
escape sequence '\y'}}
  * The second pragma is a string-literal and so the \d is invalid there.
  */
 #ifdef _WIN32
-/* This test only makes sense on Windows targets where the backslash is a valid
+/* This test only makes sense on Windows targets, where the backslash is a 
valid
  * path separator.
  */
 #pragma GCC dependency "oops\..\dr0xx.c"



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


[PATCH] D139167: [clang][Windows]Ignore Options '/d1nodatetime' and '/d1import_no_registry'

2022-12-09 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

I see this landed in https://github.com/llvm/llvm-project/commit/4178671b2ed3d 
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139167

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


[PATCH] D139713: [Sema] Fix crash when evaluating nested call with value-dependent arg

2022-12-09 Thread Pierre van Houtryve via Phabricator via cfe-commits
Pierre-vh created this revision.
Pierre-vh added reviewers: ahatanak, rsmith.
Herald added a project: All.
Pierre-vh requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix an edge case `ExprConstant.cpp`'s `EvaluateWithSubstitution` when called by 
`CheckEnableIf`

The assertion in `CallStackFrame::getTemporary`
could fail during evaluation of nested calls to a function
using `enable_if` when the second argument was a
value-dependent expression.

This caused a temporary to be created for the second
argument with a given version during the
evaluation of the inner call, but we bailed out
when evaluating the second argument of the
outer call due to the expression being value-dependent.
After bailing out, we tried to clean up the argument's value slot but it
caused an assertion to trigger in `getTemporary` as
a temporary for the second argument existed, but only for the inner call and 
not the outer call.

See the test case for a more complete description of the issue.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139713

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/enable_if-nested-call-with-valuedependent-param.cpp


Index: clang/test/SemaCXX/enable_if-nested-call-with-valuedependent-param.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/enable_if-nested-call-with-valuedependent-param.cpp
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -fsyntax-only %s -std=c++14
+
+// Checks that Clang doesn't crash/assert on the nested call to "kaboom"
+// in "bar()".
+//
+// This is an interesting test case for `ExprConstant.cpp`'s `CallStackFrame`
+// because it triggers the following chain of events:
+// 0. `CheckEnableIf` calls `EvaluateWithSubstitution`.
+//  1. The outer call to "kaboom" gets evaluated.
+//   2. The expr for "a" gets evaluated, it has a version X;
+//  a temporary with the key (a, X) is created.
+// 3. The inner call to "kaboom" gets evaluated.
+//   4. The expr for "a" gets evaluated, it has a version Y;
+//  a temporary with the key (a, Y) is created.
+//   5. The expr for "b" gets evaluated, it has a version Y;
+//  a temporary with the key (b, Y) is created.
+//   6. `EvaluateWithSubstitution` looks at "b" but cannot evaluate it
+//  because it's value-dependent (due to the call to "f.foo()").
+//
+// When `EvaluateWithSubstitution` bails out while evaluating the outer
+// call, it attempts to fetch "b"'s param slot to clean it up.
+//
+// This used to cause an assertion failure in `getTemporary` because
+// a temporary with the key "(b, Y)" (created at step 4) existed but
+// not one for "(b, X)", which is what it was trying to fetch.
+
+template
+__attribute__((enable_if(true, "")))
+T kaboom(T a, T b) {
+  return b;
+}
+
+struct A {
+  double foo();
+};
+
+template 
+struct B {
+  A &f;
+
+  void bar() {
+kaboom(kaboom(0.0, 1.0), f.foo());
+  }
+};
\ No newline at end of file
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -593,11 +593,6 @@
   auto LB = Temporaries.lower_bound(KV);
   if (LB != Temporaries.end() && LB->first == KV)
 return &LB->second;
-  // Pair (Key,Version) wasn't found in the map. Check that no elements
-  // in the map have 'Key' as their key.
-  assert((LB == Temporaries.end() || LB->first.first != Key) &&
- (LB == Temporaries.begin() || std::prev(LB)->first.first != Key) 
&&
- "Element with key 'Key' found in map");
   return nullptr;
 }
 


Index: clang/test/SemaCXX/enable_if-nested-call-with-valuedependent-param.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/enable_if-nested-call-with-valuedependent-param.cpp
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -fsyntax-only %s -std=c++14
+
+// Checks that Clang doesn't crash/assert on the nested call to "kaboom"
+// in "bar()".
+//
+// This is an interesting test case for `ExprConstant.cpp`'s `CallStackFrame`
+// because it triggers the following chain of events:
+// 0. `CheckEnableIf` calls `EvaluateWithSubstitution`.
+//  1. The outer call to "kaboom" gets evaluated.
+//   2. The expr for "a" gets evaluated, it has a version X;
+//  a temporary with the key (a, X) is created.
+// 3. The inner call to "kaboom" gets evaluated.
+//   4. The expr for "a" gets evaluated, it has a version Y;
+//  a temporary with the key (a, Y) is created.
+//   5. The expr for "b" gets evaluated, it has a version Y;
+//  a temporary with the key (b, Y) is created.
+//   6. `EvaluateWithSubstitution` looks at "b" but cannot evaluate it
+//  because it's value-dependent (due to the call to "f.foo()").
+//
+// When `EvaluateWithSubstitution` bails out while evaluating the outer
+// call, it at

[PATCH] D139713: [Sema] Fix crash when evaluating nested call with value-dependent arg

2022-12-09 Thread Pierre van Houtryve via Phabricator via cfe-commits
Pierre-vh updated this revision to Diff 481626.
Pierre-vh added a comment.

Missing newline at EOF


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139713

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/enable_if-nested-call-with-valuedependent-param.cpp


Index: clang/test/SemaCXX/enable_if-nested-call-with-valuedependent-param.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/enable_if-nested-call-with-valuedependent-param.cpp
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -fsyntax-only %s -std=c++14
+
+// Checks that Clang doesn't crash/assert on the nested call to "kaboom"
+// in "bar()".
+//
+// This is an interesting test case for `ExprConstant.cpp`'s `CallStackFrame`
+// because it triggers the following chain of events:
+// 0. `CheckEnableIf` calls `EvaluateWithSubstitution`.
+//  1. The outer call to "kaboom" gets evaluated.
+//   2. The expr for "a" gets evaluated, it has a version X;
+//  a temporary with the key (a, X) is created.
+// 3. The inner call to "kaboom" gets evaluated.
+//   4. The expr for "a" gets evaluated, it has a version Y;
+//  a temporary with the key (a, Y) is created.
+//   5. The expr for "b" gets evaluated, it has a version Y;
+//  a temporary with the key (b, Y) is created.
+//   6. `EvaluateWithSubstitution` looks at "b" but cannot evaluate it
+//  because it's value-dependent (due to the call to "f.foo()").
+//
+// When `EvaluateWithSubstitution` bails out while evaluating the outer
+// call, it attempts to fetch "b"'s param slot to clean it up.
+//
+// This used to cause an assertion failure in `getTemporary` because
+// a temporary with the key "(b, Y)" (created at step 4) existed but
+// not one for "(b, X)", which is what it was trying to fetch.
+
+template
+__attribute__((enable_if(true, "")))
+T kaboom(T a, T b) {
+  return b;
+}
+
+struct A {
+  double foo();
+};
+
+template 
+struct B {
+  A &f;
+
+  void bar() {
+kaboom(kaboom(0.0, 1.0), f.foo());
+  }
+};
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -593,11 +593,6 @@
   auto LB = Temporaries.lower_bound(KV);
   if (LB != Temporaries.end() && LB->first == KV)
 return &LB->second;
-  // Pair (Key,Version) wasn't found in the map. Check that no elements
-  // in the map have 'Key' as their key.
-  assert((LB == Temporaries.end() || LB->first.first != Key) &&
- (LB == Temporaries.begin() || std::prev(LB)->first.first != Key) 
&&
- "Element with key 'Key' found in map");
   return nullptr;
 }
 


Index: clang/test/SemaCXX/enable_if-nested-call-with-valuedependent-param.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/enable_if-nested-call-with-valuedependent-param.cpp
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -fsyntax-only %s -std=c++14
+
+// Checks that Clang doesn't crash/assert on the nested call to "kaboom"
+// in "bar()".
+//
+// This is an interesting test case for `ExprConstant.cpp`'s `CallStackFrame`
+// because it triggers the following chain of events:
+// 0. `CheckEnableIf` calls `EvaluateWithSubstitution`.
+//  1. The outer call to "kaboom" gets evaluated.
+//   2. The expr for "a" gets evaluated, it has a version X;
+//  a temporary with the key (a, X) is created.
+// 3. The inner call to "kaboom" gets evaluated.
+//   4. The expr for "a" gets evaluated, it has a version Y;
+//  a temporary with the key (a, Y) is created.
+//   5. The expr for "b" gets evaluated, it has a version Y;
+//  a temporary with the key (b, Y) is created.
+//   6. `EvaluateWithSubstitution` looks at "b" but cannot evaluate it
+//  because it's value-dependent (due to the call to "f.foo()").
+//
+// When `EvaluateWithSubstitution` bails out while evaluating the outer
+// call, it attempts to fetch "b"'s param slot to clean it up.
+//
+// This used to cause an assertion failure in `getTemporary` because
+// a temporary with the key "(b, Y)" (created at step 4) existed but
+// not one for "(b, X)", which is what it was trying to fetch.
+
+template
+__attribute__((enable_if(true, "")))
+T kaboom(T a, T b) {
+  return b;
+}
+
+struct A {
+  double foo();
+};
+
+template 
+struct B {
+  A &f;
+
+  void bar() {
+kaboom(kaboom(0.0, 1.0), f.foo());
+  }
+};
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -593,11 +593,6 @@
   auto LB = Temporaries.lower_bound(KV);
   if (LB != Temporaries.end() && LB->first == KV)
 return &LB->second;
-  // Pair (Key,Version) wasn't found in the map. Check that no elements
-  // in 

[PATCH] D139713: [Sema] Fix crash when evaluating nested call with value-dependent arg

2022-12-09 Thread Pierre van Houtryve via Phabricator via cfe-commits
Pierre-vh added a comment.

I think the right choice is to remove the assert as it's an invariant that can 
be broken in some cases, so I don't feel like the assert is worth it anymore.
Alternatively I could add something to bypass the assert in that specific call 
to getParamSlot for Value-Dependent expressions, it's a more targeted fix in 
case you think the assertion must be left in.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139713

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


[PATCH] D139715: [include-cleaner] Print the line number of removal #includes.

2022-12-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: clang-tools-extra.

I found that this information is helpful when using this tool.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139715

Files:
  clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp


Index: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
===
--- clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -130,7 +130,7 @@
   switch (Print) {
   case PrintStyle::Changes:
 for (const Include *I : Results.Unused)
-  llvm::outs() << "- " << I->quote() << "\n";
+  llvm::outs() << "- " << I->quote() << " @Line:" << I->Line << "\n";
 for (const auto &I : Results.Missing)
   llvm::outs() << "+ " << I << "\n";
 break;


Index: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
===
--- clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -130,7 +130,7 @@
   switch (Print) {
   case PrintStyle::Changes:
 for (const Include *I : Results.Unused)
-  llvm::outs() << "- " << I->quote() << "\n";
+  llvm::outs() << "- " << I->quote() << " @Line:" << I->Line << "\n";
 for (const auto &I : Results.Missing)
   llvm::outs() << "+ " << I << "\n";
 break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139716: [include-cleaner] Use expansion locations for macros.

2022-12-09 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo created this revision.
Herald added a subscriber: kadircet.
Herald added a project: All.
VitaNuo requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Use expansion locations for target symbol decls when finding headers for macros.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139716

Files:
  clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
  clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
@@ -7,11 +7,16 @@
 //===--===//
 
 #include "AnalysisInternal.h"
+#include "clang-include-cleaner/Analysis.h"
 #include "clang-include-cleaner/Record.h"
+#include "clang-include-cleaner/Types.h"
 #include "clang/Basic/FileEntry.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Testing/TestAST.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
@@ -31,7 +36,7 @@
   std::unique_ptr AST;
   FindHeadersTest() {
 Inputs.MakeAction = [this] {
-  struct Hook : public PreprocessOnlyAction {
+  struct Hook : public SyntaxOnlyAction {
   public:
 Hook(PragmaIncludes *Out) : Out(Out) {}
 bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
@@ -153,5 +158,121 @@
physicalHeader("exporter.h")));
 }
 
+TEST_F(FindHeadersTest, TargetIsArgumentExpandedFromMacroInHeader) {
+  llvm::Annotations MainFile(R"cpp(
+#include "declare.h"
+Foo foo;
+  )cpp");
+  Inputs.Code = MainFile.code();
+  Inputs.ExtraFiles["declare.h"] = R"cpp(
+#include "macro.h"
+DEFINE_CLASS(Foo)
+  )cpp";
+  Inputs.ExtraFiles["macro.h"] = R"cpp(
+#define DEFINE_CLASS(name) class name {};
+  )cpp";
+
+  buildAST();
+  llvm::SmallVector TopLevelDecls;
+  for (Decl *D : AST->context().getTranslationUnitDecl()->decls()) {
+if (!AST->sourceManager().isWrittenInMainFile(
+AST->sourceManager().getExpansionLoc(D->getLocation(
+  continue;
+TopLevelDecls.emplace_back(D);
+  }
+  EXPECT_EQ(TopLevelDecls.size(), 1u);
+
+  std::vector Headers;
+  walkUsed(
+  TopLevelDecls, {}, nullptr, AST->sourceManager(),
+  [&Headers](const SymbolReference &Ref, llvm::ArrayRef Providers) {
+if (!llvm::isa(Ref.Target.declaration()))
+  return;
+for (const Header &Header : Providers)
+  Headers.push_back(Header);
+  });
+
+  EXPECT_EQ(Headers.size(), 1u);
+  EXPECT_THAT(Headers, UnorderedElementsAre(physicalHeader("declare.h")));
+}
+
+TEST_F(FindHeadersTest, TargetIsBodyExpandedFromMacroInHeader) {
+  llvm::Annotations MainFile(R"cpp(
+#include "declare.h"
+void test(Foo foo);
+  )cpp");
+  Inputs.Code = MainFile.code();
+  Inputs.ExtraFiles["declare.h"] = R"cpp(
+#include "macro.h"
+DEFINE_Foo
+  )cpp";
+  Inputs.ExtraFiles["macro.h"] = R"cpp(
+#define DEFINE_Foo class Foo {};
+  )cpp";
+
+  buildAST();
+  llvm::SmallVector TopLevelDecls;
+  for (Decl *D : AST->context().getTranslationUnitDecl()->decls()) {
+if (!AST->sourceManager().isWrittenInMainFile(
+AST->sourceManager().getExpansionLoc(D->getLocation(
+  continue;
+TopLevelDecls.emplace_back(D);
+  }
+  EXPECT_EQ(TopLevelDecls.size(), 1u);
+
+  std::vector Headers;
+  walkUsed(
+  TopLevelDecls, {}, nullptr, AST->sourceManager(),
+  [&Headers](const SymbolReference &Ref, llvm::ArrayRef Providers) {
+if (!llvm::isa(Ref.Target.declaration()))
+  return;
+for (const Header &Header : Providers)
+  Headers.push_back(Header);
+  });
+
+  EXPECT_EQ(Headers.size(), 1u);
+  EXPECT_THAT(Headers, UnorderedElementsAre(physicalHeader("declare.h")));
+}
+
+TEST_F(FindHeadersTest, TargetIsTokenPasted) {
+  llvm::Annotations MainFile(R"cpp(
+#include "declare.h"
+void foo() {
+  FLAG_foo;
+}
+  )cpp");
+  Inputs.Code = MainFile.code();
+  Inputs.ExtraFiles["declare.h"] = R"cpp(
+#include "flag.h"
+DECLARE_FLAGS(foo);
+  )cpp";
+  Inputs.ExtraFiles["flag.h"] = R"cpp(
+#define DECLARE_FLAGS(name) extern int FLAG_##name
+  )cpp";
+
+  buildAST();
+  llvm::SmallVector TopLevelDecls;
+  for (Decl *D : AST->context().getTranslationUnitDecl()->decls()) {
+if (!AST->sourceManager().isWrittenInMainFile(
+AST->sourceManager().getExpansionLoc(D->getLocation(
+  continue;
+TopLevelDecls.emplace_back(D);
+  }
+  EXPECT_EQ(TopLevelDecls.size(), 1u);
+
+  std::vector Headers;
+  walkUsed(
+  TopLevelDecls, {}, nullp

[PATCH] D139716: [include-cleaner] Use expansion locations for macros.

2022-12-09 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 481635.
VitaNuo added a comment.

Remove FIXME.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139716

Files:
  clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
  clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
@@ -7,11 +7,16 @@
 //===--===//
 
 #include "AnalysisInternal.h"
+#include "clang-include-cleaner/Analysis.h"
 #include "clang-include-cleaner/Record.h"
+#include "clang-include-cleaner/Types.h"
 #include "clang/Basic/FileEntry.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Testing/TestAST.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
@@ -31,7 +36,7 @@
   std::unique_ptr AST;
   FindHeadersTest() {
 Inputs.MakeAction = [this] {
-  struct Hook : public PreprocessOnlyAction {
+  struct Hook : public SyntaxOnlyAction {
   public:
 Hook(PragmaIncludes *Out) : Out(Out) {}
 bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
@@ -153,5 +158,121 @@
physicalHeader("exporter.h")));
 }
 
+TEST_F(FindHeadersTest, TargetIsArgumentExpandedFromMacroInHeader) {
+  llvm::Annotations MainFile(R"cpp(
+#include "declare.h"
+Foo foo;
+  )cpp");
+  Inputs.Code = MainFile.code();
+  Inputs.ExtraFiles["declare.h"] = R"cpp(
+#include "macro.h"
+DEFINE_CLASS(Foo)
+  )cpp";
+  Inputs.ExtraFiles["macro.h"] = R"cpp(
+#define DEFINE_CLASS(name) class name {};
+  )cpp";
+
+  buildAST();
+  llvm::SmallVector TopLevelDecls;
+  for (Decl *D : AST->context().getTranslationUnitDecl()->decls()) {
+if (!AST->sourceManager().isWrittenInMainFile(
+AST->sourceManager().getExpansionLoc(D->getLocation(
+  continue;
+TopLevelDecls.emplace_back(D);
+  }
+  EXPECT_EQ(TopLevelDecls.size(), 1u);
+
+  std::vector Headers;
+  walkUsed(
+  TopLevelDecls, {}, nullptr, AST->sourceManager(),
+  [&Headers](const SymbolReference &Ref, llvm::ArrayRef Providers) {
+if (!llvm::isa(Ref.Target.declaration()))
+  return;
+for (const Header &Header : Providers)
+  Headers.push_back(Header);
+  });
+
+  EXPECT_EQ(Headers.size(), 1u);
+  EXPECT_THAT(Headers, UnorderedElementsAre(physicalHeader("declare.h")));
+}
+
+TEST_F(FindHeadersTest, TargetIsBodyExpandedFromMacroInHeader) {
+  llvm::Annotations MainFile(R"cpp(
+#include "declare.h"
+void test(Foo foo);
+  )cpp");
+  Inputs.Code = MainFile.code();
+  Inputs.ExtraFiles["declare.h"] = R"cpp(
+#include "macro.h"
+DEFINE_Foo
+  )cpp";
+  Inputs.ExtraFiles["macro.h"] = R"cpp(
+#define DEFINE_Foo class Foo {};
+  )cpp";
+
+  buildAST();
+  llvm::SmallVector TopLevelDecls;
+  for (Decl *D : AST->context().getTranslationUnitDecl()->decls()) {
+if (!AST->sourceManager().isWrittenInMainFile(
+AST->sourceManager().getExpansionLoc(D->getLocation(
+  continue;
+TopLevelDecls.emplace_back(D);
+  }
+  EXPECT_EQ(TopLevelDecls.size(), 1u);
+
+  std::vector Headers;
+  walkUsed(
+  TopLevelDecls, {}, nullptr, AST->sourceManager(),
+  [&Headers](const SymbolReference &Ref, llvm::ArrayRef Providers) {
+if (!llvm::isa(Ref.Target.declaration()))
+  return;
+for (const Header &Header : Providers)
+  Headers.push_back(Header);
+  });
+
+  EXPECT_EQ(Headers.size(), 1u);
+  EXPECT_THAT(Headers, UnorderedElementsAre(physicalHeader("declare.h")));
+}
+
+TEST_F(FindHeadersTest, TargetIsTokenPasted) {
+  llvm::Annotations MainFile(R"cpp(
+#include "declare.h"
+void foo() {
+  FLAG_foo;
+}
+  )cpp");
+  Inputs.Code = MainFile.code();
+  Inputs.ExtraFiles["declare.h"] = R"cpp(
+#include "flag.h"
+DECLARE_FLAGS(foo);
+  )cpp";
+  Inputs.ExtraFiles["flag.h"] = R"cpp(
+#define DECLARE_FLAGS(name) extern int FLAG_##name
+  )cpp";
+
+  buildAST();
+  llvm::SmallVector TopLevelDecls;
+  for (Decl *D : AST->context().getTranslationUnitDecl()->decls()) {
+if (!AST->sourceManager().isWrittenInMainFile(
+AST->sourceManager().getExpansionLoc(D->getLocation(
+  continue;
+TopLevelDecls.emplace_back(D);
+  }
+  EXPECT_EQ(TopLevelDecls.size(), 1u);
+
+  std::vector Headers;
+  walkUsed(
+  TopLevelDecls, {}, nullptr, AST->sourceManager(),
+  [&Headers](const SymbolReference &Ref, llvm::ArrayRef Providers) {
+if (!llvm::isa(Ref.Target.declaration()))
+

[PATCH] D139544: [clang][dataflow] Add support for structured bindings of tuple-like types.

2022-12-09 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

> Those BindingDecls never appear in the CFG unless one of the is used.

Sorry, I should fix my response above: I *never* see the `BindingDecl`s in the 
CFG, whether or not they are used.  Can you send me an example CFG that 
contains the BindingDecls?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139544

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


[PATCH] D137875: clang/AMDGPU: Drop volatile from builtin_atomic* pointers

2022-12-09 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

ping


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

https://reviews.llvm.org/D137875

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


[PATCH] D139717: Revert "[Driver] Remove Joined -X"

2022-12-09 Thread Roy Sundahl via Phabricator via cfe-commits
rsundahl created this revision.
Herald added a project: All.
rsundahl requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change is breaking internal builds. We use the -Xfoo pattern but can
now no longer manage whether we allow an unused -Xfoo option to pass as a
warning or promote it to an error.

This reverts commit 98615fd376cea15af21e120e0e3ffa5ba68c2b6d 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139717

Files:
  clang/include/clang/Driver/Options.td


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -844,6 +844,7 @@
 def Xpreprocessor : Separate<["-"], "Xpreprocessor">, 
Group,
   HelpText<"Pass  to the preprocessor">, MetaVarName<"">;
 def X_Flag : Flag<["-"], "X">, Group;
+def X_Joined : Joined<["-"], "X">, IgnoredGCCCompat;
 def Z_Flag : Flag<["-"], "Z">, Group;
 def all__load : Flag<["-"], "all_load">;
 def allowable__client : Separate<["-"], "allowable_client">;


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -844,6 +844,7 @@
 def Xpreprocessor : Separate<["-"], "Xpreprocessor">, Group,
   HelpText<"Pass  to the preprocessor">, MetaVarName<"">;
 def X_Flag : Flag<["-"], "X">, Group;
+def X_Joined : Joined<["-"], "X">, IgnoredGCCCompat;
 def Z_Flag : Flag<["-"], "Z">, Group;
 def all__load : Flag<["-"], "all_load">;
 def allowable__client : Separate<["-"], "allowable_client">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139696: [include-cleaner] Add a unique_ptr-style member expr test in WalkASTTest.

2022-12-09 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo accepted this revision.
VitaNuo added a comment.
This revision is now accepted and ready to land.

Thank you!




Comment at: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp:200
+  testWalk(R"cpp(
+  template  struct unique_ptr {
+T *operator->();

Should "struct unique_ptr` go on the next line mayber? At least that's how I 
have seen templates defined until now :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139696

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


[clang] 218b77c - [AArch64][NFC] Move hasFeature fields initiations to the declaration

2022-12-09 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2022-12-09T16:23:26+01:00
New Revision: 218b77c85057e8aae153edcedfe365061270e70c

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

LOG: [AArch64][NFC] Move hasFeature fields initiations to the declaration

hasFeature fields need to be initialised to false. Easy to miss as missed for 
hasPAuth and hasFlagM.
Maybe the code less error prone like this.

Reviewed By: chill

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

Added: 


Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 89ad602b591f5..90a83f62574fc 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -579,37 +579,6 @@ void 
AArch64TargetInfo::setFeatureEnabled(llvm::StringMap &Features,
 
 bool AArch64TargetInfo::handleTargetFeatures(std::vector 
&Features,
  DiagnosticsEngine &Diags) {
-  FPU = FPUMode;
-  HasCRC = false;
-  HasAES = false;
-  HasSHA2 = false;
-  HasSHA3 = false;
-  HasSM4 = false;
-  HasUnaligned = true;
-  HasFullFP16 = false;
-  HasDotProd = false;
-  HasFP16FML = false;
-  HasMTE = false;
-  HasTME = false;
-  HasLS64 = false;
-  HasRandGen = false;
-  HasMatMul = false;
-  HasBFloat16 = false;
-  HasSVE2 = false;
-  HasSVE2AES = false;
-  HasSVE2SHA3 = false;
-  HasSVE2SM4 = false;
-  HasSVE2BitPerm = false;
-  HasMatmulFP64 = false;
-  HasMatmulFP32 = false;
-  HasLSE = false;
-  HasMOPS = false;
-  HasD128 = false;
-  HasRCPC = false;
-  HasPAuth = false;
-
-  ArchKind = llvm::AArch64::ArchKind::INVALID;
-
   for (const auto &Feature : Features) {
 if (Feature == "+neon")
   FPU |= NeonMode;

diff  --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 1791e462139f3..b971c56ec9cda 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -27,36 +27,36 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
 
   enum FPUModeEnum { FPUMode, NeonMode = (1 << 0), SveMode = (1 << 1) };
 
-  unsigned FPU;
-  bool HasCRC;
-  bool HasAES;
-  bool HasSHA2;
-  bool HasSHA3;
-  bool HasSM4;
-  bool HasUnaligned;
-  bool HasFullFP16;
-  bool HasDotProd;
-  bool HasFP16FML;
-  bool HasMTE;
-  bool HasTME;
-  bool HasPAuth;
-  bool HasLS64;
-  bool HasRandGen;
-  bool HasMatMul;
-  bool HasSVE2;
-  bool HasSVE2AES;
-  bool HasSVE2SHA3;
-  bool HasSVE2SM4;
-  bool HasSVE2BitPerm;
-  bool HasMatmulFP64;
-  bool HasMatmulFP32;
-  bool HasLSE;
-  bool HasFlagM;
-  bool HasMOPS;
-  bool HasD128;
-  bool HasRCPC;
-
-  llvm::AArch64::ArchKind ArchKind;
+  unsigned FPU = FPUMode;
+  bool HasCRC = false;
+  bool HasAES = false;
+  bool HasSHA2 = false;
+  bool HasSHA3 = false;
+  bool HasSM4 = false;
+  bool HasUnaligned = true;
+  bool HasFullFP16 = false;
+  bool HasDotProd = false;
+  bool HasFP16FML = false;
+  bool HasMTE = false;
+  bool HasTME = false;
+  bool HasPAuth = false;
+  bool HasLS64 = false;
+  bool HasRandGen = false;
+  bool HasMatMul = false;
+  bool HasSVE2 = false;
+  bool HasSVE2AES = false;
+  bool HasSVE2SHA3 = false;
+  bool HasSVE2SM4 = false;
+  bool HasSVE2BitPerm = false;
+  bool HasMatmulFP64 = false;
+  bool HasMatmulFP32 = false;
+  bool HasLSE = false;
+  bool HasFlagM = false;
+  bool HasMOPS = false;
+  bool HasD128 = false;
+  bool HasRCPC = false;
+
+  llvm::AArch64::ArchKind ArchKind = llvm::AArch64::ArchKind::INVALID;
 
   static const Builtin::Info BuiltinInfo[];
 



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


[PATCH] D139622: [AArch64][NFC] Move hasFeature fields initiations to the declaration

2022-12-09 Thread Daniel Kiss 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 rG218b77c85057: [AArch64][NFC] Move hasFeature fields 
initiations to the declaration (authored by danielkiss).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139622

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h

Index: clang/lib/Basic/Targets/AArch64.h
===
--- clang/lib/Basic/Targets/AArch64.h
+++ clang/lib/Basic/Targets/AArch64.h
@@ -27,36 +27,36 @@
 
   enum FPUModeEnum { FPUMode, NeonMode = (1 << 0), SveMode = (1 << 1) };
 
-  unsigned FPU;
-  bool HasCRC;
-  bool HasAES;
-  bool HasSHA2;
-  bool HasSHA3;
-  bool HasSM4;
-  bool HasUnaligned;
-  bool HasFullFP16;
-  bool HasDotProd;
-  bool HasFP16FML;
-  bool HasMTE;
-  bool HasTME;
-  bool HasPAuth;
-  bool HasLS64;
-  bool HasRandGen;
-  bool HasMatMul;
-  bool HasSVE2;
-  bool HasSVE2AES;
-  bool HasSVE2SHA3;
-  bool HasSVE2SM4;
-  bool HasSVE2BitPerm;
-  bool HasMatmulFP64;
-  bool HasMatmulFP32;
-  bool HasLSE;
-  bool HasFlagM;
-  bool HasMOPS;
-  bool HasD128;
-  bool HasRCPC;
-
-  llvm::AArch64::ArchKind ArchKind;
+  unsigned FPU = FPUMode;
+  bool HasCRC = false;
+  bool HasAES = false;
+  bool HasSHA2 = false;
+  bool HasSHA3 = false;
+  bool HasSM4 = false;
+  bool HasUnaligned = true;
+  bool HasFullFP16 = false;
+  bool HasDotProd = false;
+  bool HasFP16FML = false;
+  bool HasMTE = false;
+  bool HasTME = false;
+  bool HasPAuth = false;
+  bool HasLS64 = false;
+  bool HasRandGen = false;
+  bool HasMatMul = false;
+  bool HasSVE2 = false;
+  bool HasSVE2AES = false;
+  bool HasSVE2SHA3 = false;
+  bool HasSVE2SM4 = false;
+  bool HasSVE2BitPerm = false;
+  bool HasMatmulFP64 = false;
+  bool HasMatmulFP32 = false;
+  bool HasLSE = false;
+  bool HasFlagM = false;
+  bool HasMOPS = false;
+  bool HasD128 = false;
+  bool HasRCPC = false;
+
+  llvm::AArch64::ArchKind ArchKind = llvm::AArch64::ArchKind::INVALID;
 
   static const Builtin::Info BuiltinInfo[];
 
Index: clang/lib/Basic/Targets/AArch64.cpp
===
--- clang/lib/Basic/Targets/AArch64.cpp
+++ clang/lib/Basic/Targets/AArch64.cpp
@@ -579,37 +579,6 @@
 
 bool AArch64TargetInfo::handleTargetFeatures(std::vector &Features,
  DiagnosticsEngine &Diags) {
-  FPU = FPUMode;
-  HasCRC = false;
-  HasAES = false;
-  HasSHA2 = false;
-  HasSHA3 = false;
-  HasSM4 = false;
-  HasUnaligned = true;
-  HasFullFP16 = false;
-  HasDotProd = false;
-  HasFP16FML = false;
-  HasMTE = false;
-  HasTME = false;
-  HasLS64 = false;
-  HasRandGen = false;
-  HasMatMul = false;
-  HasBFloat16 = false;
-  HasSVE2 = false;
-  HasSVE2AES = false;
-  HasSVE2SHA3 = false;
-  HasSVE2SM4 = false;
-  HasSVE2BitPerm = false;
-  HasMatmulFP64 = false;
-  HasMatmulFP32 = false;
-  HasLSE = false;
-  HasMOPS = false;
-  HasD128 = false;
-  HasRCPC = false;
-  HasPAuth = false;
-
-  ArchKind = llvm::AArch64::ArchKind::INVALID;
-
   for (const auto &Feature : Features) {
 if (Feature == "+neon")
   FPU |= NeonMode;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139544: [clang][dataflow] Add support for structured bindings of tuple-like types.

2022-12-09 Thread Domján Dániel via Phabricator via cfe-commits
isuckatcs added a comment.

> Sorry, I should fix my response above: I *never* see the BindingDecls in the 
> CFG, whether or not they are used.

It was my fault, I was wrong with the wording. I meant the `DeclRefExpr`s that 
refer to the `BindingDecl`s. You can 
access the `BindingDecl`s through the `DeclRefExpr`s, they are not present in 
the CFG directly.

That's also how the static analyzer handles the `BindingDecl`s in 
`ExprEngine::VisitCommonDeclRefExpr()`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139544

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


[PATCH] D139652: Add the thread sanitizer support for X86_64 WatchOS simulators

2022-12-09 Thread Roy Sundahl via Phabricator via cfe-commits
rsundahl added a comment.

In D139652#3983079 , @yln wrote:

> @rsundahl: can you keep an eye on this and resolve any potential 
> Apple-internal conflicts?  Thanks!

Will do @yln.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139652

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


[PATCH] D139544: [clang][dataflow] Add support for structured bindings of tuple-like types.

2022-12-09 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 481651.
ymandel added a comment.

Simplifies the implementation and removes mention of any potential CFG problem.

This new version does the work eagerly by forcing a location for the 
synthesized variable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139544

Files:
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -2860,6 +2860,59 @@
   )");
 }
 
+TEST_P(UncheckedOptionalAccessTest, StructuredBindingsFromStruct) {
+  ExpectDiagnosticsFor(R"(
+#include "unchecked_optional_access_test.h"
+
+struct kv { $ns::$optional opt; int x; };
+int target() {
+  auto [contents, x] = Make();
+  return contents ? *contents : x;
+}
+  )");
+
+  ExpectDiagnosticsFor(R"(
+#include "unchecked_optional_access_test.h"
+
+template 
+struct pair { T1 fst;  T2 snd; };
+int target() {
+  auto [contents, x] = Make, int>>();
+  return contents ? *contents : x;
+}
+  )");
+}
+
+TEST_P(UncheckedOptionalAccessTest, StructuredBindingsFromTupleLikeType) {
+  ExpectDiagnosticsFor(R"(
+#include "unchecked_optional_access_test.h"
+
+namespace std {
+template  struct tuple_size;
+template  struct tuple_element;
+template  class tuple;
+
+template 
+struct tuple_size> : integral_constant {};
+
+template 
+struct tuple_element> {
+  using type =  __type_pack_element;
+};
+
+template  class tuple {};
+template 
+typename tuple_element>::type get(tuple);
+} // namespace std
+
+std::tuple<$ns::$optional, int> get_opt();
+void target() {
+  auto [content, ck] = get_opt();
+  content ? *content : "";
+}
+  )");
+}
+
 // FIXME: Add support for:
 // - constructors (copy, move)
 // - assignment operators (default, copy, move)
Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3613,6 +3613,172 @@
   });
 }
 
+TEST(TransferTest, StructuredBindingAssignFromTupleLikeType) {
+  std::string Code = R"(
+namespace std {
+using size_t = int;
+template  struct tuple_size;
+template  struct tuple_element;
+template  class tuple;
+
+namespace {
+template 
+struct size_helper { static const T value = v; };
+} // namespace
+
+template 
+struct tuple_size> : size_helper {};
+
+template 
+struct tuple_element> {
+  using type =  __type_pack_element;
+};
+
+template  class tuple {};
+
+template 
+typename tuple_element>::type get(tuple);
+} // namespace std
+
+std::tuple makeTuple();
+
+void target(bool B) {
+  auto [BoundFoo, BoundBar] = makeTuple();
+  bool Baz;
+  // Include if-then-else to test interaction of `BindingDecl` with join.
+  if (B) {
+Baz = BoundFoo;
+(void)BoundBar;
+// [[p1]]
+  } else {
+Baz = BoundFoo;
+  }
+  (void)0;
+  // [[p2]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results.keys(), UnorderedElementsAre("p1", "p2"));
+const Environment &Env1 = getEnvironmentAtAnnotation(Results, "p1");
+
+const ValueDecl *BoundFooDecl = findValueDecl(ASTCtx, "BoundFoo");
+ASSERT_THAT(BoundFooDecl, NotNull());
+
+const ValueDecl *BoundBarDecl = findValueDecl(ASTCtx, "BoundBar");
+ASSERT_THAT(BoundBarDecl, NotNull());
+
+const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+ASSERT_THAT(BazDecl, NotNull());
+
+const Value *BoundFooValue =
+Env1.getValue(*BoundFooDecl, SkipPast::Reference);
+ASSERT_THAT(BoundFooValue, NotNull());
+EXPECT_TRUE(isa(BoundFooValue));
+
+const Value *BoundBarValue =
+Env1.getValue(*BoundBarDecl, SkipPast::Reference);
+ASSERT_THAT(BoundBarValue, NotNull());
+EXPECT_TRUE(isa(BoundBarValue));
+
+// Test that a `DeclRefExpr` to a `BindingDecl` works as expected.
+EXPECT_EQ(Env1.getValue(*BazDecl, SkipPast::Reference), BoundFooValue);
+
+const Environment &Env2 = getEnvironmentAtAnnotation(Results, "p2");
+
+// Test that `BoundFooDecl` retains the value we expect, after the j

[PATCH] D139544: [clang][dataflow] Add support for structured bindings of tuple-like types.

2022-12-09 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

In D139544#3984532 , @isuckatcs wrote:

>> Sorry, I should fix my response above: I *never* see the BindingDecls in the 
>> CFG, whether or not they are used.
>
> It was my fault, I was wrong with the wording. I meant the `DeclRefExpr`s 
> that refer to the `BindingDecl`s. You can 
> access the `BindingDecl`s through the `DeclRefExpr`s, they are not present in 
> the CFG directly.
>
> That's also how the static analyzer handles the `BindingDecl`s in 
> `ExprEngine::VisitCommonDeclRefExpr()`.

Got it, thanks!

So, I think everything is resolved now, you've been incredibly helpful. Based 
on my now understanding the CFG representation of DecompositionDecls a lot 
better, I found a simpler solution that doesn't even need to involve our 
handling of `DeclRefExpr`s and is therefore consistent with how we already 
handle the struct references.

I think there's a separate discussion we might want to have about whether it 
would be valuable (to the static analyzer and the dataflow framework, among 
others) to update CFG to explicitly represent BindingDecls and the AST nodes in 
their bindings. But, that seems better for a discourse thread. :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139544

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


[PATCH] D139409: [include-cleaner] Handle dependent type members in AST

2022-12-09 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 481659.
VitaNuo marked 3 inline comments as done.
VitaNuo added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139409

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -198,6 +198,24 @@
"Derived& foo(); void fun() { foo().^a; }");
 }
 
+TEST(WalkAST, CXXDependentScopeMemberExprs) {
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k(Base t) { t.^method(); }");
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k(Base& t) { t.^method(); }");
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k(Base* t) { t->^method(); }");
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k() { Base t; t.^method(); }");
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k() { Base* t; t->^method(); }");
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k() { Base().^method(); }");
+  testWalk("template struct Base { void method(); }; "
+   "template struct $explicit^Derived: Base {};",
+   "template void k(Derived t) { t.^method(); }");
+}
+
 TEST(WalkAST, ConstructExprs) {
   testWalk("struct $implicit^S {};", "S ^t;");
   testWalk("struct S { $implicit^S(); };", "S ^t;");
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -11,6 +11,7 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
@@ -47,6 +48,10 @@
   NamedDecl *resolveType(QualType Type) {
 if (Type->isPointerType())
   Type = Type->getPointeeType();
+if (const TemplateSpecializationType *TST =
+Type->getAs()) {
+  return TST->getTemplateName().getAsTemplateDecl();
+}
 return Type->getAsRecordDecl();
   }
 
@@ -62,12 +67,16 @@
 // A member expr implies a usage of the class type
 // (e.g., to prevent inserting a header of base class when using base
 // members from a derived object).
-// FIXME: support dependent types, e.g., "std::vector().size()".
 QualType Type = E->getBase()->IgnoreImpCasts()->getType();
 report(E->getMemberLoc(), resolveType(Type));
 return true;
   }
 
+  bool VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E) {
+report(E->getMemberLoc(), resolveType(E->getBaseType()));
+return true;
+  }
+
   bool VisitCXXConstructExpr(CXXConstructExpr *E) {
 report(E->getLocation(), E->getConstructor(),
E->getParenOrBraceRange().isValid() ? RefType::Explicit


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -198,6 +198,24 @@
"Derived& foo(); void fun() { foo().^a; }");
 }
 
+TEST(WalkAST, CXXDependentScopeMemberExprs) {
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k(Base t) { t.^method(); }");
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k(Base& t) { t.^method(); }");
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k(Base* t) { t->^method(); }");
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k() { Base t; t.^method(); }");
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k() { Base* t; t->^method(); }");
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k() { Base().^method(); }");
+  testWalk("template struct Base { void method(); }; "
+   "template struct $explicit^Derived: Base {};",
+   "template void k(Derived t) { t.^method(); }");
+}
+
 TEST(WalkAST, ConstructExprs) {
   testWalk("struct $implicit^S {};", "S ^t;");
   testWalk("struct S { $implicit^S(); };", "S ^t;");
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- cl

[PATCH] D139409: [include-cleaner] Handle dependent type members in AST

2022-12-09 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo marked an inline comment as done.
VitaNuo added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:79
+
+if (isa(UnqualifiedType)) {
+  const TemplateSpecializationType *TST =

hokein wrote:
> if we just aim to support the `vector().size()` case, we only need this 
> part of code right?
Sure.



Comment at: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp:198
+   "template void k(typename Base::Nested d) { "
+   "d.^method(); }");
+  testWalk("template struct $explicit^Base { struct Nested { void "

hokein wrote:
> Thanks for coming up these cases. IMO a more reasonable behavior would be 
> that the target symbol of the reported reference is `Nested` rather than the 
> outer class `Base`, but implementing it would require some dependent name 
> lookup in the `Base` (in clangd we have a similar thing `HeuristicResolver`, 
> but it is sophisticated).
> 
> I think it is find to ignore these cases (these cases are more tricky, and 
> less interesting to us) right now, this would simplify the implementation.
> 
> Note that the existing behavior of accessing a member expr from a dependent 
> type is that we don't report any reference on `d.^method()`, so the original 
> "include base header via a base-member-access from a derived-class object" 
> issue doesn't exist. We aim to improve this behavior for some critical cases.
> 
> The critical case we want to support is the `vector().size()`, if other 
> cases come up in the furture, we could revisit it.
Thank you for the extended explanation!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139409

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


[PATCH] D137337: Replace LLVM_LIBDIR_SUFFIX by CMAKE_INSTALL_LIBDIR

2022-12-09 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 added inline comments.



Comment at: bolt/lib/RuntimeLibs/RuntimeLibrary.cpp:32
   SmallString<128> LibPath = llvm::sys::path::parent_path(Dir);
-  llvm::sys::path::append(LibPath, "lib" LLVM_LIBDIR_SUFFIX);
+  llvm::sys::path::append(LibPath, CMAKE_INSTALL_LIBDIR);
   if (!llvm::sys::fs::exists(LibPath)) {

compnerd wrote:
> serge-sans-paille wrote:
> > Ericson2314 wrote:
> > > mgorny wrote:
> > > > Well, one thing I immediately notice is that technically 
> > > > `CMAKE_INSTALL_LIBDIR` can be an absolute path, while in many locations 
> > > > you are assuming it will always be relative. Not saying that's a 
> > > > blocker but I think you should add checks for that into 
> > > > `CMakeLists.txt`.
> > > Yes I was working on this, and I intend to use `CMAKE_INSTALL_LIBDIR` 
> > > with an absolute path.
> > > 
> > > OK if this isn't supported initially but we should ovoid regressing where 
> > > possible.
> > Turns out LLVM_LIBDIR_SUFFIX is used in several situations: (a) for the 
> > library install dir or (b) for the location where build artifact as stored 
> > in CMAKE_BINARY_DIR. (a) could accept a path but not (b), unless we derive 
> > it from (a) but I can see a lot of complication there for the testing step. 
> > Would that be ok to choke on CMAKE_INSTALL_LIBDIR being a path and not a 
> > directory component?
> > 
> I think that is absolutely reasonable.  There is the 
> `CMAKE_INSTALL_FULL_LIBDIR` which should be the relatively absolute path (it 
> is relative to `DESTDIR`).  The `CMAKE_INSTALL_LIBDIR` should be the relative 
> component which is added to `CMAKE_INSTALL_PREFIX`.
Please do not do this. In NixOS we uses absolute paths for these which are 
*not* within `CMAKE_INSTALL_PREFIX` and I would very much like that to continue 
to work, and have put a lot of effort into it.

(I am sorry I have been a bit AWAL on LLVM things in general but hopefully will 
have more time as we head into the new year.)


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

https://reviews.llvm.org/D137337

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


[PATCH] D129531: [clang][C++20] P0960R3 and P1975R0: Allow initializing aggregates from a parenthesized list of values

2022-12-09 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang/include/clang/AST/ExprCXX.h:4824
+  const Expr *getArrayFiller() const {
+return const_cast(this)->getArrayFiller();
+  }

NIT: maybe just use `return ArrayFiller`? The code is much simpler and since 
functions are very close it's pretty much impossible that anyone would refactor 
one of those without looking at the other.



Comment at: clang/lib/AST/ExprConstant.cpp:1
 ImplicitValueInitExpr VIE(Field->getType());
-const Expr *InitExpr = E->getNumInits() ? E->getInit(0) : &VIE;
+const Expr *InitExpr = Args.size() ? Args[0] : &VIE;
 

NIT: `!Args.empty() ? Args[0] : &VIE`
`Args.size()` also works, but arguably captures the intent of the code a bit 
less clearly.



Comment at: clang/lib/CodeGen/CGExprAgg.cpp:581
+  Expr *filler = nullptr;
+  if (auto *ILE = dyn_cast(ExprToVisit))
+filler = ILE->getArrayFiller();

ayzhao wrote:
> ayzhao wrote:
> > ilya-biryukov wrote:
> > > ilya-biryukov wrote:
> > > > ayzhao wrote:
> > > > > ilya-biryukov wrote:
> > > > > > - Should we have a filler for `CXXParenInitListExpr` too?
> > > > > >   It seems like an important optimization and could have large 
> > > > > > effect on compile times if we don't 
> > > > > > 
> > > > > > - Same question for semantic and syntactic-form (similar to 
> > > > > > `InitListExpr`): should we have it here?
> > > > > >   I am not sure if it's semantically required (probably not?), but 
> > > > > > that's definitely something that `clang-tidy` and other source 
> > > > > > tools will rely on.
> > > > > > 
> > > > > > We should probably share the code there, I suggest moving it to a 
> > > > > > shared base class and using it where appropriate instead of the 
> > > > > > derived classes.
> > > > > > Should we have a filler for CXXParenInitListExpr too? It seems like 
> > > > > > an important optimization and could have large effect on compile 
> > > > > > times if we don't
> > > > > 
> > > > > This feels like premature optimization - presumably, wouldn't this 
> > > > > only be an issue with extraordinarily large (say, O(1000)) arrays?
> > > > > 
> > > > > > Same question for semantic and syntactic-form (similar to 
> > > > > > InitListExpr): should we have it here? I am not sure if it's 
> > > > > > semantically required (probably not?), but that's definitely 
> > > > > > something that clang-tidy and other source tools will rely on
> > > > > 
> > > > > IIRC this doesn't apply to paren list aggregate expressions, as the 
> > > > > syntatic form would be the enclosing `ParenListExpr`.
> > > > > This feels like premature optimization - presumably, wouldn't this 
> > > > > only be an issue with extraordinarily large (say, O(1000)) arrays?
> > > > Yes, this should only happen with large arrays. Normally I would agree, 
> > > > but it's surprising that changing `{}` to `()` in the compiler would 
> > > > lead to performance degradation.
> > > > In that sense, this premature optimization is already implemented, we 
> > > > are rather degrading performance for a different syntax to do the same 
> > > > thing.
> > > > 
> > > > Although we could also land without it, but in that case could you open 
> > > > a GH issue and add a FIXME to track the implementation of this 
> > > > particular optimization?
> > > > This should increase the chances of users finding the root cause of the 
> > > > issue if they happen to hit it.
> > > > 
> > > > > IIRC this doesn't apply to paren list aggregate expressions, as the 
> > > > > syntatic form would be the enclosing ParenListExpr.
> > > > Do we even have the enclosing `ParenListExpr`? If I dump the AST with 
> > > > `clang -fsyntax-only -Xclang=-ast-dump ...`  for the following code:
> > > > ```
> > > > struct pair { int a; int b = 2; };
> > > > int main() {
> > > >   pair(1); pair p(1);
> > > >   pair b{1}; pair{1};
> > > > }
> > > > ```
> > > > 
> > > > I get 
> > > > ```
> > > > `-FunctionDecl 0x557d79717e98  line:2:5 main 'int 
> > > > ()'
> > > >   `-CompoundStmt 0x557d797369d0 
> > > > |-CXXFunctionalCastExpr 0x557d79718528  
> > > > 'pair':'pair' functional cast to pair 
> > > > | `-CXXParenListInitExpr 0x557d79718500  'pair':'pair'
> > > > |   |-IntegerLiteral 0x557d79718010  'int' 1
> > > > |   `-IntegerLiteral 0x557d79717e18  'int' 2
> > > > |-DeclStmt 0x557d79718650 
> > > > | `-VarDecl 0x557d79718568  col:17 p 'pair':'pair' 
> > > > parenlistinit
> > > > |   `-CXXParenListInitExpr 0x557d79718610  'pair':'pair'
> > > > | |-IntegerLiteral 0x557d797185d0  'int' 1
> > > > | `-IntegerLiteral 0x557d79717e18  'int' 2
> > > > |-DeclStmt 0x557d797187d8 
> > > > | `-VarDecl 0x557d79718680  col:8 b 'pair':'pair' 
> > > > listinit
> > > > |   `-InitListExpr 0x557d79718750  'pair':'pair'
> > > > | |-IntegerLiteral 0x557d797186e8  'int' 1
> > > > | `-CXXDefaultInitExpr 

[PATCH] D131830: [OpenMP] Clang Support for taskwait nowait clause

2022-12-09 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added inline comments.



Comment at: openmp/runtime/src/dllexports:348
 __kmpc_omp_wait_deps243
+__kmpc_omp_taskwait_deps_51 292
 __kmpc_cancel   244

This is missing a similar export of `__kmpc_omp_taskwait_51`, which causes a 
bunch of tests to fail if running them on Windows now. (Also, where do the 
numbers for these exports get assigned?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131830

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


[PATCH] D139717: Revert "[Driver] Remove Joined -X"

2022-12-09 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

This is missing a test, like the original commit mentioned.
Why can you not just use the the split variant, `-X clang ...`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139717

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


[PATCH] D138316: [ASTContext] Avoid duplicating address space map. NFCI

2022-12-09 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson updated this revision to Diff 481664.
arichardson added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138316

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Basic/TargetInfo.cpp

Index: clang/lib/Basic/TargetInfo.cpp
===
--- clang/lib/Basic/TargetInfo.cpp
+++ clang/lib/Basic/TargetInfo.cpp
@@ -24,6 +24,30 @@
 using namespace clang;
 
 static const LangASMap DefaultAddrSpaceMap = {0};
+// The fake address space map must have a distinct entry for each
+// language-specific address space.
+static const LangASMap FakeAddrSpaceMap = {
+0,  // Default
+1,  // opencl_global
+3,  // opencl_local
+2,  // opencl_constant
+0,  // opencl_private
+4,  // opencl_generic
+5,  // opencl_global_device
+6,  // opencl_global_host
+7,  // cuda_device
+8,  // cuda_constant
+9,  // cuda_shared
+1,  // sycl_global
+5,  // sycl_global_device
+6,  // sycl_global_host
+3,  // sycl_local
+0,  // sycl_private
+10, // ptr32_sptr
+11, // ptr32_uptr
+12, // ptr64
+13, // hlsl_groupshared
+};
 
 // TargetInfo Constructor.
 TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
@@ -487,6 +511,9 @@
 
   if (Opts.MaxBitIntWidth)
 MaxBitIntWidth = Opts.MaxBitIntWidth;
+
+  if (Opts.FakeAddressSpaceMap)
+AddrSpaceMap = &FakeAddrSpaceMap;
 }
 
 bool TargetInfo::initFeatureMap(
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -930,39 +930,6 @@
   return *ParentMapCtx.get();
 }
 
-static const LangASMap *getAddressSpaceMap(const TargetInfo &T,
-   const LangOptions &LOpts) {
-  if (LOpts.FakeAddressSpaceMap) {
-// The fake address space map must have a distinct entry for each
-// language-specific address space.
-static const unsigned FakeAddrSpaceMap[] = {
-0,  // Default
-1,  // opencl_global
-3,  // opencl_local
-2,  // opencl_constant
-0,  // opencl_private
-4,  // opencl_generic
-5,  // opencl_global_device
-6,  // opencl_global_host
-7,  // cuda_device
-8,  // cuda_constant
-9,  // cuda_shared
-1,  // sycl_global
-5,  // sycl_global_device
-6,  // sycl_global_host
-3,  // sycl_local
-0,  // sycl_private
-10, // ptr32_sptr
-11, // ptr32_uptr
-12, // ptr64
-13, // hlsl_groupshared
-};
-return &FakeAddrSpaceMap;
-  } else {
-return &T.getAddressSpaceMap();
-  }
-}
-
 static bool isAddrSpaceMapManglingEnabled(const TargetInfo &TI,
   const LangOptions &LangOpts) {
   switch (LangOpts.getAddressSpaceMapMangling()) {
@@ -1293,7 +1260,6 @@
   this->AuxTarget = AuxTarget;
 
   ABI.reset(createCXXABI(Target));
-  AddrSpaceMap = getAddressSpaceMap(Target, LangOpts);
   AddrSpaceMapMangling = isAddrSpaceMapManglingEnabled(Target, LangOpts);
 
   // C99 6.2.5p19.
@@ -12244,10 +12210,7 @@
 }
 
 unsigned ASTContext::getTargetAddressSpace(LangAS AS) const {
-  if (isTargetAddressSpace(AS))
-return toTargetAddressSpace(AS);
-  else
-return (*AddrSpaceMap)[(unsigned)AS];
+  return getTargetInfo().getTargetAddressSpace(AS);
 }
 
 bool ASTContext::hasSameExpr(const Expr *X, const Expr *Y) const {
Index: clang/include/clang/AST/ASTContext.h
===
--- clang/include/clang/AST/ASTContext.h
+++ clang/include/clang/AST/ASTContext.h
@@ -613,9 +613,6 @@
   std::unique_ptr ABI;
   CXXABI *createCXXABI(const TargetInfo &T);
 
-  /// The logical -> physical address space map.
-  const LangASMap *AddrSpaceMap = nullptr;
-
   /// Address space map mangling must be used with language specific
   /// address spaces (e.g. OpenCL/CUDA)
   bool AddrSpaceMapMangling;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139720: [clang][PPC] Checking Unknown Values Passed to -mcpu

2022-12-09 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 created this revision.
qiongsiwu1 added reviewers: nemanjai, amyk.
qiongsiwu1 added a project: clang.
Herald added subscribers: shchenz, kbarton.
Herald added a project: All.
qiongsiwu1 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.

Currently `ppc::getPPCTargetCPU` returns an empty string when it encounters an 
unknown value passed to `-mcpu`. This causes `clang` to ignore unknown `-mcpu` 
values silently.

This patch changes the behaviour of `ppc::getPPCTargetCPU` so that it passes 
the unknown option to the backend, so the backend can actually check if the CPU 
string is supported, and report an error when encountering unknown/unsupported 
CPU string.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139720

Files:
  clang/lib/Driver/ToolChains/Arch/PPC.cpp
  clang/lib/Driver/ToolChains/Arch/PPC.h
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/ppc-cpus.c

Index: clang/test/Driver/ppc-cpus.c
===
--- clang/test/Driver/ppc-cpus.c
+++ clang/test/Driver/ppc-cpus.c
@@ -5,6 +5,11 @@
 // RUN: %clang -### -c -target powerpc64 %s -mcpu=native 2>&1 | FileCheck --check-prefix=MCPU_NATIVE %s
 // MCPU_NATIVE-NOT: "-target-cpu" "native"
 
+/// Check that we are passing unknown mcpu options to the backend so an error
+/// can be triggered.
+// RUN: %clang -### -c -target powerpc64 %s -mcpu=asdf1234 2>&1 | FileCheck --check-prefix=MCPU_UNKNOWN %s
+// MCPU_UNKNOWN: "-target-cpu" "asdf1234"
+
 // RUN: %clang -### -c -target powerpc64 %s -mcpu=7400 2>&1 | FileCheck --check-prefix=MCPU_7400 %s
 // MCPU_7400: "-target-cpu" "7400"
 
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -409,25 +409,9 @@
   case llvm::Triple::ppc:
   case llvm::Triple::ppcle:
   case llvm::Triple::ppc64:
-  case llvm::Triple::ppc64le: {
-std::string TargetCPUName = ppc::getPPCTargetCPU(Args);
-// LLVM may default to generating code for the native CPU,
-// but, like gcc, we default to a more generic option for
-// each architecture. (except on AIX)
-if (!TargetCPUName.empty())
-  return TargetCPUName;
-
-if (T.isOSAIX())
-  TargetCPUName = "pwr7";
-else if (T.getArch() == llvm::Triple::ppc64le)
-  TargetCPUName = "ppc64le";
-else if (T.getArch() == llvm::Triple::ppc64)
-  TargetCPUName = "ppc64";
-else
-  TargetCPUName = "ppc";
+  case llvm::Triple::ppc64le:
+return ppc::getPPCTargetCPU(Args, T);
 
-return TargetCPUName;
-  }
   case llvm::Triple::csky:
 if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
   return A->getValue();
Index: clang/lib/Driver/ToolChains/Arch/PPC.h
===
--- clang/lib/Driver/ToolChains/Arch/PPC.h
+++ clang/lib/Driver/ToolChains/Arch/PPC.h
@@ -35,7 +35,8 @@
 
 FloatABI getPPCFloatABI(const Driver &D, const llvm::opt::ArgList &Args);
 
-std::string getPPCTargetCPU(const llvm::opt::ArgList &Args);
+std::string getPPCTargetCPU(const llvm::opt::ArgList &Args,
+const llvm::Triple &T);
 const char *getPPCAsmModeForCPU(StringRef Name);
 ReadGOTPtrMode getPPCReadGOTPtrMode(const Driver &D, const llvm::Triple &Triple,
 const llvm::opt::ArgList &Args);
Index: clang/lib/Driver/ToolChains/Arch/PPC.cpp
===
--- clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -20,74 +20,64 @@
 using namespace clang;
 using namespace llvm::opt;
 
+static std::string getPPCGenericTargetCPU(const llvm::Triple &T) {
+  // LLVM may default to generating code for the native CPU,
+  // but, like gcc, we default to a more generic option for
+  // each architecture. (except on AIX)
+  if (T.isOSAIX())
+return "pwr7";
+  else if (T.getArch() == llvm::Triple::ppc64le)
+return "ppc64le";
+  else if (T.getArch() == llvm::Triple::ppc64)
+return "ppc64";
+  else
+return "ppc";
+}
+
 /// getPPCTargetCPU - Get the (LLVM) name of the PowerPC cpu we are targeting.
-std::string ppc::getPPCTargetCPU(const ArgList &Args) {
+std::string ppc::getPPCTargetCPU(const ArgList &Args, const llvm::Triple &T) {
   if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
 StringRef CPUName = A->getValue();
 
+if (CPUName == "generic")
+  return getPPCGenericTargetCPU(T);
+
 if (CPUName == "native") {
   std::string CPU = std::string(llvm::sys::getHostCPUName());
   if (!CPU.empty() && CPU != "generic")
 return CPU;
   else
-return "";
+return getPPCGenericTargetCPU(T);
 }
 
-return llvm::StringSwitch(CPUName)
-.Case("common", "generic")
-.Case("440", "440")
-.Case("440

[clang] e52b9bf - [STLExtras] Convert deref_or_none and zip_longest to std::optional

2022-12-09 Thread Krzysztof Parzyszek via cfe-commits

Author: Krzysztof Parzyszek
Date: 2022-12-09T10:27:48-06:00
New Revision: e52b9bf64f0487f6ec5a6a7b24f95f31ab83fb8b

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

LOG: [STLExtras] Convert deref_or_none and zip_longest to std::optional

Added: 


Modified: 
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ASTStructuralEquivalence.cpp
clang/lib/Sema/SemaOverload.cpp
llvm/include/llvm/ADT/STLExtras.h
llvm/include/llvm/Support/Format.h
llvm/unittests/ADT/IteratorTest.cpp
llvm/unittests/Support/raw_ostream_test.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index e6f360fe79533..dd7e0bfecdaeb 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -94,6 +94,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -6493,8 +6494,8 @@ static bool hasSameOverloadableAttrs(const FunctionDecl 
*A,
   auto BEnableIfAttrs = B->specific_attrs();
 
   for (auto Pair : zip_longest(AEnableIfAttrs, BEnableIfAttrs)) {
-Optional Cand1A = std::get<0>(Pair);
-Optional Cand2A = std::get<1>(Pair);
+std::optional Cand1A = std::get<0>(Pair);
+std::optional Cand2A = std::get<1>(Pair);
 
 // Return false if the number of enable_if attributes is 
diff erent.
 if (!Cand1A || !Cand2A)

diff  --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 66846dde85f58..e383170079b1e 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -91,6 +91,7 @@
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include 
+#include 
 #include 
 
 using namespace clang;
@@ -238,8 +239,8 @@ class StmtComparer {
 const GenericSelectionExpr *E2) {
 for (auto Pair : zip_longest(E1->getAssocTypeSourceInfos(),
  E2->getAssocTypeSourceInfos())) {
-  Optional Child1 = std::get<0>(Pair);
-  Optional Child2 = std::get<1>(Pair);
+  std::optional Child1 = std::get<0>(Pair);
+  std::optional Child2 = std::get<1>(Pair);
   // Skip this case if there are a 
diff erent number of associated types.
   if (!Child1 || !Child2)
 return false;
@@ -310,8 +311,8 @@ class StmtComparer {
   return false;
 
 for (auto Pair : zip_longest(E1->getArgs(), E2->getArgs())) {
-  Optional Child1 = std::get<0>(Pair);
-  Optional Child2 = std::get<1>(Pair);
+  std::optional Child1 = std::get<0>(Pair);
+  std::optional Child2 = std::get<1>(Pair);
   // Different number of args.
   if (!Child1 || !Child2)
 return false;
@@ -400,8 +401,8 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
 
   // Iterate over the children of both statements and also compare them.
   for (auto Pair : zip_longest(S1->children(), S2->children())) {
-Optional Child1 = std::get<0>(Pair);
-Optional Child2 = std::get<1>(Pair);
+std::optional Child1 = std::get<0>(Pair);
+std::optional Child2 = std::get<1>(Pair);
 // One of the statements has a 
diff erent amount of children than the other,
 // so the statements can't be equivalent.
 if (!Child1 || !Child2)

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 31298c6cd5175..7f3d400fc67ee 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -40,6 +40,7 @@
 #include "llvm/Support/Casting.h"
 #include 
 #include 
+#include 
 
 using namespace clang;
 using namespace sema;
@@ -9654,8 +9655,8 @@ static Comparison compareEnableIfAttrs(const Sema &S, 
const FunctionDecl *Cand1,
 
   llvm::FoldingSetNodeID Cand1ID, Cand2ID;
   for (auto Pair : zip_longest(Cand1Attrs, Cand2Attrs)) {
-Optional Cand1A = std::get<0>(Pair);
-Optional Cand2A = std::get<1>(Pair);
+std::optional Cand1A = std::get<0>(Pair);
+std::optional Cand2A = std::get<1>(Pair);
 
 // It's impossible for Cand1 to be better than (or equal to) Cand2 if Cand1
 // has fewer enable_if attributes than Cand2, and vice versa.

diff  --git a/llvm/include/llvm/ADT/STLExtras.h 
b/llvm/include/llvm/ADT/STLExtras.h
index 28c13a8390e62..1354268bc2822 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -18,7 +18,6 @@
 #define LLVM_ADT_STLEXTRAS_H
 
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLForwardCompat.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
 #include "llvm/ADT/identity.h"
@@ -921,7 +920,7 @@ Iter next_or_end(const Iter &I, const Iter &End) {
 }
 
 template 
-auto deref_or_none(const Iter &I, const Iter &End) -> llvm::Optional<
+auto deref_or_none(const Iter &I, const Iter &End)

[clang] 707cc06 - Sema: diagnose PMFs passed through registers to inline assembly

2022-12-09 Thread Saleem Abdulrasool via cfe-commits

Author: Saleem Abdulrasool
Date: 2022-12-09T16:58:46Z
New Revision: 707cc06e1570b5966efcd6a9124191c80fa7a754

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

LOG: Sema: diagnose PMFs passed through registers to inline assembly

The itanium ABI represents the PMF as a pair of pointers.  As such the
structure cannot be passed through a single register.  Diagnose such
cases in the frontend rather than trying to generate IR to perform this
operation.

Fixes: 59033

Differential Revision: https://reviews.llvm.org/D13851
Reviewed By: aaron.ballman

Added: 
clang/test/Sema/gnu-asm-pmf.cpp

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaStmtAsm.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 734cffd01c223..0bbd1f6be4e2e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8845,6 +8845,9 @@ def warn_redefine_extname_not_applied : Warning<
 
 // inline asm.
 let CategoryName = "Inline Assembly Issue" in {
+  def err_asm_pmf_through_constraint_not_permitted
+: Error<"cannot pass a pointer-to-member through register-constrained "
+"inline assembly parameter">;
   def err_asm_invalid_lvalue_in_output : Error<"invalid lvalue in asm output">;
   def err_asm_invalid_output_constraint : Error<
 "invalid output constraint '%0' in asm">;

diff  --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index d19f4d6c78356..06fc0ec798660 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -377,6 +377,11 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 
 Expr *InputExpr = Exprs[i];
 
+if (InputExpr->getType()->isMemberPointerType())
+  return StmtError(Diag(InputExpr->getBeginLoc(),
+diag::err_asm_pmf_through_constraint_not_permitted)
+   << InputExpr->getSourceRange());
+
 // Referring to parameters is not allowed in naked functions.
 if (CheckNakedParmReference(InputExpr, *this))
   return StmtError();

diff  --git a/clang/test/Sema/gnu-asm-pmf.cpp b/clang/test/Sema/gnu-asm-pmf.cpp
new file mode 100644
index 0..30677c85696df
--- /dev/null
+++ b/clang/test/Sema/gnu-asm-pmf.cpp
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -std=c++2b 
-fsyntax-only %s -verify
+// RUN: %clang_cc1 -triple x86_64-unknown-windows-itanium -std=c++2b 
-fsyntax-only %s -verify
+
+struct S {
+  void operator()();
+};
+
+struct T {
+  virtual void operator()();
+};
+
+struct U {
+  static void operator()();
+};
+
+struct V: virtual T {
+  virtual void f();
+};
+
+struct W : virtual V {
+  int i;
+};
+
+struct X {
+  __UINTPTR_TYPE__ ptr;
+  __UINTPTR_TYPE__ adj;
+};
+
+auto L = [](){};
+
+void f() {
+  auto pmf = &S::operator();
+
+  __asm__ __volatile__ ("" : : "r"(&decltype(L)::operator()));
+  // expected-error@-1{{cannot pass a pointer-to-member through 
register-constrained inline assembly parameter}}
+  __asm__ __volatile__ ("" : : "r"(&S::operator()));
+  // expected-error@-1{{cannot pass a pointer-to-member through 
register-constrained inline assembly parameter}}
+  __asm__ __volatile__ ("" : : "r"(&T::operator()));
+  // expected-error@-1{{cannot pass a pointer-to-member through 
register-constrained inline assembly parameter}}
+  __asm__ __volatile__ ("" : : "r"(pmf));
+  // expected-error@-1{{cannot pass a pointer-to-member through 
register-constrained inline assembly parameter}}
+  __asm__ __volatile__ ("" : : "r"(&W::f));
+  // expected-error@-1{{cannot pass a pointer-to-member through 
register-constrained inline assembly parameter}}
+  __asm__ __volatile__ ("" : : "r"(&W::i));
+  // expected-error@-1{{cannot pass a pointer-to-member through 
register-constrained inline assembly parameter}}
+
+  __asm__ __volatile__ ("" : : "r"(X{0,0}));
+  __asm__ __volatile__ ("" : : "r"(&U::operator()));
+}



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


[PATCH] D138514: Sema: diagnose PMFs passed through registers to inline assembly

2022-12-09 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd accepted this revision.
compnerd added a comment.
This revision is now accepted and ready to land.

(Accepting Revision for Closing)
I missed the trailing number of the differential revision, and it failed to tie 
it to this.  The commit is at  
https://github.com/llvm/llvm-project/commit/707cc06e1570b5966efcd6a9124191c80fa7a754
@rnk is going to be out for a while, so any concerns can be addressed in a 
follow up.


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

https://reviews.llvm.org/D138514

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


[PATCH] D139723: [OpenMP][AMDGPU] Enable use of abs labs and llabs function in C code

2022-12-09 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 created this revision.
doru1004 added reviewers: jhuber6, arsenm, carlo.bertolli, gregrodgers, ronl.
doru1004 added a project: OpenMP.
Herald added subscribers: kosarev, guansong, tpr, dstuttard, yaxunl, jvesely, 
kzhuravl.
Herald added a project: All.
doru1004 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1, wdng.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.

Enable use of abs labs and llabs math functions in C code. Before this patch 
these math functions could only be used in OpenMP target regions in C++.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139723

Files:
  clang/lib/Headers/__clang_hip_math.h
  clang/test/Headers/Inputs/include/stdlib.h
  clang/test/Headers/amdgcn_openmp_device_math_c.c

Index: clang/test/Headers/amdgcn_openmp_device_math_c.c
===
--- /dev/null
+++ clang/test/Headers/amdgcn_openmp_device_math_c.c
@@ -0,0 +1,131 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs
+// RUN: %clang_cc1 -internal-isystem %S/Inputs/include -x c -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -D__OFFLOAD_ARCH_gfx90a__ -emit-llvm-bc %s -o %t-host.bc
+// RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -x c -fopenmp -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -o - | FileCheck %s --check-prefixes=CHECK
+
+#include 
+#include 
+
+void test_math_int(int x) {
+#pragma omp target
+  {
+int l1 = abs(x);
+  }
+}
+
+void test_math_long(long x) {
+#pragma omp target
+  {
+long l1 = labs(x);
+  }
+}
+
+void test_math_long_long(long long x) {
+#pragma omp target
+  {
+long long l1 = llabs(x);
+  }
+}
+// CHECK-LABEL: define {{[^@]+}}@__omp_offloading_802_abeeaa0_test_math_int_l9
+// CHECK-SAME: (i64 noundef [[X:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RETVAL_I:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[__X_ADDR_I:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[__SGN_I:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[X_ADDR:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-NEXT:[[L1:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[X_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[X_ADDR]] to ptr
+// CHECK-NEXT:[[L1_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[L1]] to ptr
+// CHECK-NEXT:store i64 [[X]], ptr [[X_ADDR_ASCAST]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = call i32 @__kmpc_target_init(ptr addrspacecast (ptr addrspace(1) @[[GLOB1:[0-9]+]] to ptr), i8 1, i1 true, i1 true)
+// CHECK-NEXT:[[EXEC_USER_CODE:%.*]] = icmp eq i32 [[TMP0]], -1
+// CHECK-NEXT:br i1 [[EXEC_USER_CODE]], label [[USER_CODE_ENTRY:%.*]], label [[WORKER_EXIT:%.*]]
+// CHECK:   user_code.entry:
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[X_ADDR_ASCAST]], align 4
+// CHECK-NEXT:[[RETVAL_ASCAST_I:%.*]] = addrspacecast ptr addrspace(5) [[RETVAL_I]] to ptr
+// CHECK-NEXT:[[__X_ADDR_ASCAST_I:%.*]] = addrspacecast ptr addrspace(5) [[__X_ADDR_I]] to ptr
+// CHECK-NEXT:[[__SGN_ASCAST_I:%.*]] = addrspacecast ptr addrspace(5) [[__SGN_I]] to ptr
+// CHECK-NEXT:store i32 [[TMP1]], ptr [[__X_ADDR_ASCAST_I]], align 4
+// CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[__X_ADDR_ASCAST_I]], align 4
+// CHECK-NEXT:[[SHR_I:%.*]] = ashr i32 [[TMP2]], 31
+// CHECK-NEXT:store i32 [[SHR_I]], ptr [[__SGN_ASCAST_I]], align 4
+// CHECK-NEXT:[[TMP3:%.*]] = load i32, ptr [[__X_ADDR_ASCAST_I]], align 4
+// CHECK-NEXT:[[TMP4:%.*]] = load i32, ptr [[__SGN_ASCAST_I]], align 4
+// CHECK-NEXT:[[XOR_I:%.*]] = xor i32 [[TMP3]], [[TMP4]]
+// CHECK-NEXT:[[TMP5:%.*]] = load i32, ptr [[__SGN_ASCAST_I]], align 4
+// CHECK-NEXT:[[SUB_I:%.*]] = sub nsw i32 [[XOR_I]], [[TMP5]]
+// CHECK-NEXT:store i32 [[SUB_I]], ptr [[L1_ASCAST]], align 4
+// CHECK-NEXT:call void @__kmpc_target_deinit(ptr addrspacecast (ptr addrspace(1) @[[GLOB1]] to ptr), i8 1, i1 true)
+// CHECK-NEXT:ret void
+// CHECK:   worker.exit:
+// CHECK-NEXT:ret void
+//
+//
+// CHECK-LABEL: define {{[^@]+}}@__omp_offloading_802_abeeaa0_test_math_long_l16
+// CHECK-SAME: (i64 noundef [[X:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RETVAL_I:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-NEXT:[[__X_ADDR_I:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-NEXT:[[__SGN_I:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-NEXT:[[X_ADDR:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-NEXT:[[L1:%.*]] = alloca i64, align 8, addrspace(5)

[clang] e0fd86d - Revert "[OpenMP] Clang Support for taskwait nowait clause"

2022-12-09 Thread Chi Chun Chen via cfe-commits

Author: Chi Chun Chen
Date: 2022-12-09T11:06:45-06:00
New Revision: e0fd86db09a87f25df0eff6c1c755d86434dea0b

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

LOG: Revert "[OpenMP] Clang Support for taskwait nowait clause"

This reverts commit 100dfe7a8ad3789a98df623482b88d9a3a02e176.

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntime.h
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/test/OpenMP/target_depend_codegen.cpp
clang/test/OpenMP/target_enter_data_depend_codegen.cpp
clang/test/OpenMP/target_exit_data_depend_codegen.cpp
clang/test/OpenMP/target_parallel_depend_codegen.cpp
clang/test/OpenMP/target_parallel_for_depend_codegen.cpp
clang/test/OpenMP/target_parallel_for_simd_depend_codegen.cpp
clang/test/OpenMP/target_simd_depend_codegen.cpp
clang/test/OpenMP/target_teams_depend_codegen.cpp
clang/test/OpenMP/target_teams_distribute_depend_codegen.cpp
clang/test/OpenMP/target_teams_distribute_parallel_for_depend_codegen.cpp

clang/test/OpenMP/target_teams_distribute_parallel_for_simd_depend_codegen.cpp
clang/test/OpenMP/target_teams_distribute_simd_depend_codegen.cpp
clang/test/OpenMP/target_update_depend_codegen.cpp
clang/test/OpenMP/task_codegen.cpp
clang/test/OpenMP/task_if_codegen.cpp
clang/test/OpenMP/taskwait_ast_print.cpp
clang/test/OpenMP/taskwait_codegen.cpp
clang/test/OpenMP/taskwait_depend_codegen.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td
llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
mlir/test/Target/LLVMIR/openmp-llvm.mlir
openmp/runtime/src/dllexports
openmp/runtime/src/kmp.h
openmp/runtime/src/kmp_taskdeps.cpp
openmp/runtime/src/kmp_tasking.cpp

Removed: 
clang/test/OpenMP/taskwait_depend_nowait_codegen.cpp
clang/test/OpenMP/taskwait_nowait_codegen.cpp



diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 396075183102d..a75e31f40e074 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -4756,7 +4756,7 @@ void CGOpenMPRuntime::emitTaskCall(CodeGenFunction &CGF, 
SourceLocation Loc,
   Region->emitUntiedSwitch(CGF);
   };
 
-  llvm::Value *DepWaitTaskArgs[7];
+  llvm::Value *DepWaitTaskArgs[6];
   if (!Data.Dependences.empty()) {
 DepWaitTaskArgs[0] = UpLoc;
 DepWaitTaskArgs[1] = ThreadID;
@@ -4764,8 +4764,6 @@ void CGOpenMPRuntime::emitTaskCall(CodeGenFunction &CGF, 
SourceLocation Loc,
 DepWaitTaskArgs[3] = DependenciesArray.getPointer();
 DepWaitTaskArgs[4] = CGF.Builder.getInt32(0);
 DepWaitTaskArgs[5] = llvm::ConstantPointerNull::get(CGF.VoidPtrTy);
-DepWaitTaskArgs[6] =
-llvm::ConstantInt::get(CGF.Int32Ty, Data.HasNowaitClause);
   }
   auto &M = CGM.getModule();
   auto &&ElseCodeGen = [this, &M, &TaskArgs, ThreadID, NewTaskNewTaskTTy,
@@ -4777,9 +4775,9 @@ void CGOpenMPRuntime::emitTaskCall(CodeGenFunction &CGF, 
SourceLocation Loc,
 // ndeps_noalias, kmp_depend_info_t *noalias_dep_list); if dependence info
 // is specified.
 if (!Data.Dependences.empty())
-  CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction(
-  M, OMPRTL___kmpc_omp_taskwait_deps_51),
-  DepWaitTaskArgs);
+  CGF.EmitRuntimeCall(
+  OMPBuilder.getOrCreateRuntimeFunction(M, 
OMPRTL___kmpc_omp_wait_deps),
+  DepWaitTaskArgs);
 // Call proxy_task_entry(gtid, new_task);
 auto &&CodeGen = [TaskEntry, ThreadID, NewTaskNewTaskTTy,
   Loc](CodeGenFunction &CGF, PrePostActionTy &Action) {
@@ -5818,7 +5816,7 @@ void CGOpenMPRuntime::emitTaskwaitCall(CodeGenFunction 
&CGF, SourceLocation Loc,
 
   if (CGF.CGM.getLangOpts().OpenMPIRBuilder && Data.Dependences.empty()) {
 // TODO: Need to support taskwait with dependences in the OpenMPIRBuilder.
-OMPBuilder.createTaskwait(CGF.Builder, Data.HasNowaitClause);
+OMPBuilder.createTaskwait(CGF.Builder);
   } else {
 llvm::Value *ThreadID = getThreadID(CGF, Loc);
 llvm::Value *UpLoc = emitUpdateLocation(CGF, Loc);
@@ -5827,38 +5825,34 @@ void CGOpenMPRuntime::emitTaskwaitCall(CodeGenFunction 
&CGF, SourceLocation Loc,
 llvm::Value *NumOfElements;
 std::tie(NumOfElements, DependenciesArray) =
 emitDependClause(CGF, Data.Dependences, Loc);
+llvm::Value *DepWaitTaskArgs[6];
 if (!Data.Dependences.empty()) {
-  llvm::Value *DepWaitTaskArgs[7];
   DepWaitTaskArgs[0] = UpLoc;
   DepWaitTaskArgs[1] = ThreadID;
   DepWaitTaskArgs[2] = NumOfElements;
   DepWaitTaskArgs[3] = DependenciesArray.getPointer();
  

Re: [clang] e0fd86d - Revert "[OpenMP] Clang Support for taskwait nowait clause"

2022-12-09 Thread Roman Lebedev via cfe-commits
Reminder to please always mention the reason for the revert in the
commit message.

On Fri, Dec 9, 2022 at 8:07 PM Chi Chun Chen via cfe-commits
 wrote:
>
>
> Author: Chi Chun Chen
> Date: 2022-12-09T11:06:45-06:00
> New Revision: e0fd86db09a87f25df0eff6c1c755d86434dea0b
>
> URL: 
> https://github.com/llvm/llvm-project/commit/e0fd86db09a87f25df0eff6c1c755d86434dea0b
> DIFF: 
> https://github.com/llvm/llvm-project/commit/e0fd86db09a87f25df0eff6c1c755d86434dea0b.diff
>
> LOG: Revert "[OpenMP] Clang Support for taskwait nowait clause"
>
> This reverts commit 100dfe7a8ad3789a98df623482b88d9a3a02e176.
>
> Added:
>
>
> Modified:
> clang/lib/CodeGen/CGOpenMPRuntime.cpp
> clang/lib/CodeGen/CGOpenMPRuntime.h
> clang/lib/CodeGen/CGStmtOpenMP.cpp
> clang/test/OpenMP/target_depend_codegen.cpp
> clang/test/OpenMP/target_enter_data_depend_codegen.cpp
> clang/test/OpenMP/target_exit_data_depend_codegen.cpp
> clang/test/OpenMP/target_parallel_depend_codegen.cpp
> clang/test/OpenMP/target_parallel_for_depend_codegen.cpp
> clang/test/OpenMP/target_parallel_for_simd_depend_codegen.cpp
> clang/test/OpenMP/target_simd_depend_codegen.cpp
> clang/test/OpenMP/target_teams_depend_codegen.cpp
> clang/test/OpenMP/target_teams_distribute_depend_codegen.cpp
> clang/test/OpenMP/target_teams_distribute_parallel_for_depend_codegen.cpp
> 
> clang/test/OpenMP/target_teams_distribute_parallel_for_simd_depend_codegen.cpp
> clang/test/OpenMP/target_teams_distribute_simd_depend_codegen.cpp
> clang/test/OpenMP/target_update_depend_codegen.cpp
> clang/test/OpenMP/task_codegen.cpp
> clang/test/OpenMP/task_if_codegen.cpp
> clang/test/OpenMP/taskwait_ast_print.cpp
> clang/test/OpenMP/taskwait_codegen.cpp
> clang/test/OpenMP/taskwait_depend_codegen.cpp
> llvm/include/llvm/Frontend/OpenMP/OMP.td
> llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
> llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
> llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
> mlir/test/Target/LLVMIR/openmp-llvm.mlir
> openmp/runtime/src/dllexports
> openmp/runtime/src/kmp.h
> openmp/runtime/src/kmp_taskdeps.cpp
> openmp/runtime/src/kmp_tasking.cpp
>
> Removed:
> clang/test/OpenMP/taskwait_depend_nowait_codegen.cpp
> clang/test/OpenMP/taskwait_nowait_codegen.cpp
>
>
> 
> diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
> b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
> index 396075183102d..a75e31f40e074 100644
> --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
> +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
> @@ -4756,7 +4756,7 @@ void CGOpenMPRuntime::emitTaskCall(CodeGenFunction 
> &CGF, SourceLocation Loc,
>Region->emitUntiedSwitch(CGF);
>};
>
> -  llvm::Value *DepWaitTaskArgs[7];
> +  llvm::Value *DepWaitTaskArgs[6];
>if (!Data.Dependences.empty()) {
>  DepWaitTaskArgs[0] = UpLoc;
>  DepWaitTaskArgs[1] = ThreadID;
> @@ -4764,8 +4764,6 @@ void CGOpenMPRuntime::emitTaskCall(CodeGenFunction 
> &CGF, SourceLocation Loc,
>  DepWaitTaskArgs[3] = DependenciesArray.getPointer();
>  DepWaitTaskArgs[4] = CGF.Builder.getInt32(0);
>  DepWaitTaskArgs[5] = llvm::ConstantPointerNull::get(CGF.VoidPtrTy);
> -DepWaitTaskArgs[6] =
> -llvm::ConstantInt::get(CGF.Int32Ty, Data.HasNowaitClause);
>}
>auto &M = CGM.getModule();
>auto &&ElseCodeGen = [this, &M, &TaskArgs, ThreadID, NewTaskNewTaskTTy,
> @@ -4777,9 +4775,9 @@ void CGOpenMPRuntime::emitTaskCall(CodeGenFunction 
> &CGF, SourceLocation Loc,
>  // ndeps_noalias, kmp_depend_info_t *noalias_dep_list); if dependence 
> info
>  // is specified.
>  if (!Data.Dependences.empty())
> -  CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction(
> -  M, OMPRTL___kmpc_omp_taskwait_deps_51),
> -  DepWaitTaskArgs);
> +  CGF.EmitRuntimeCall(
> +  OMPBuilder.getOrCreateRuntimeFunction(M, 
> OMPRTL___kmpc_omp_wait_deps),
> +  DepWaitTaskArgs);
>  // Call proxy_task_entry(gtid, new_task);
>  auto &&CodeGen = [TaskEntry, ThreadID, NewTaskNewTaskTTy,
>Loc](CodeGenFunction &CGF, PrePostActionTy &Action) {
> @@ -5818,7 +5816,7 @@ void CGOpenMPRuntime::emitTaskwaitCall(CodeGenFunction 
> &CGF, SourceLocation Loc,
>
>if (CGF.CGM.getLangOpts().OpenMPIRBuilder && Data.Dependences.empty()) {
>  // TODO: Need to support taskwait with dependences in the 
> OpenMPIRBuilder.
> -OMPBuilder.createTaskwait(CGF.Builder, Data.HasNowaitClause);
> +OMPBuilder.createTaskwait(CGF.Builder);
>} else {
>  llvm::Value *ThreadID = getThreadID(CGF, Loc);
>  llvm::Value *UpLoc = emitUpdateLocation(CGF, Loc);
> @@ -5827,38 +5825,34 @@ void 
> CGOpenMPRuntime::emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc,
>  llvm::Value *NumOfElements;
>  std::tie(NumOfElements, DependenciesAr

[PATCH] D139717: Revert "[Driver] Remove Joined -X"

2022-12-09 Thread Davide Italiano via Phabricator via cfe-commits
davide added a comment.

In D139717#3984648 , @lebedev.ri 
wrote:

> This is missing a test, like the original commit mentioned.
> Why can you not just use the the split variant, `-X clang ...`?

This breaks many projects internally. There's no real complexity to keep this 
around. Removing is more annoying than anything else. 
I agree on the test, that has to be added.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139717

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


[PATCH] D139398: [AMDGPU] Add bf16 storage support

2022-12-09 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:913
+  else
+RegisterVT = (ScalarVT == MVT::bf16 ? MVT::v2bf16 : MVT::v2f16);
   IntermediateVT = RegisterVT;

Pierre-vh wrote:
> arsenm wrote:
> > If you wanted the promote to i32, you could have done it here instead of in 
> > the tablegen cc handling
> Do you mean somewhere else in that function? Changing v2bf16 to i32 here 
> doesn't fix it 
> I also tried changing the function above but I kept running into asserts so I 
> just left the TableGen CC for now
Yes, that should force the bitcast of the argument type



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:5573-5576
+  SDLoc SL(Op);
+  return DAG.getNode(
+  ISD::FP_EXTEND, SL, MVT::f32,
+  DAG.getNode(ISD::BITCAST, SL, MVT::f16, Op->getOperand(0)));

Pierre-vh wrote:
> arsenm wrote:
> > ExpandNode covers lowering BF16_TO_FP. It also has a shift by 16-bits into 
> > the high bits. Is this correct?
> Ah I didn't know that, though as long as we use custom lowering, and our 
> FP_TO_BF16/BF16_TO_FP methods are consistent, it should be fine, no?
bfloat16 has the same number of exponent bits in the same high bits as f32; I 
kind of think the idea is you can just do a bitshift and then operate on f32?  
I think the fp_extend here is wrong



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:4819-4831
+// When we don't have 16 bit instructions, bf16 is illegal and gets
+// softened to i16 for storage, with float being used for arithmetic.
+//
+// After softening, some i16 -> fp32 bf16_to_fp operations can be left 
over.
+// Lower those to (f32 (fp_extend (f16 (bitconvert x
+if (!Op->getValueType(0).isFloatingPoint() ||
+Op->getOperand(0).getValueType() != MVT::i16)

Pierre-vh wrote:
> arsenm wrote:
> > Pierre-vh wrote:
> > > arsenm wrote:
> > > > Pierre-vh wrote:
> > > > > arsenm wrote:
> > > > > > Pierre-vh wrote:
> > > > > > > arsenm wrote:
> > > > > > > > The generic legalizer should have handled this?
> > > > > > > It looks like those operations are not implemented in the generic 
> > > > > > > legalizer, e.g. I get 
> > > > > > > ``` 
> > > > > > > Do not know how to promote this operator's operand!
> > > > > > > ```
> > > > > > Right, this is the code that would go there
> > > > > Do I just copy/paste this code in that PromoteInt function, and keep 
> > > > > a copy here too in LowerOperation? (not really a fan of copy-pasting 
> > > > > code in different files, I'd rather keep it all here)
> > > > > We need to have the lowering too AFAIK, it didn't go well when I 
> > > > > tried to remove it
> > > > I'm not following why you need to handle it here
> > > IIRC:
> > >  - I need to handle FP_TO_BF16 in ReplaceNodeResult because that's what 
> > > the Integer Legalizer calls (through CustomLowerNode)
> > >  - I need to handle both opcodes in LowerOperation because otherwise 
> > > they'll fail selection. They can be left over from expanding/legalizing 
> > > other operations.
> > But why are they custom? We don't have to handle FP16_TO_FP or FP_TO_FP16 
> > there, and they aren't custom lowered. They have the same basic properties. 
> > We have this:
> > 
> > 
> > ```
> > setOperationAction(ISD::FP16_TO_FP, MVT::i16, Promote);
> > AddPromotedToType(ISD::FP16_TO_FP, MVT::i16, MVT::i32);
> > setOperationAction(ISD::FP_TO_FP16, MVT::i16, Promote);
> > AddPromotedToType(ISD::FP_TO_FP16, MVT::i16, MVT::i32);
> > ```
> > 
> > I'd expect the same basic pattern
> PromoteIntegerOperand, PromoteFloatOperand and PromoteIntegerResult don't 
> handle FP_TO_BF16 and BF16_TO_FP, and unless we put a Custom lowering mode 
> it'll assert/unreachable.
> I tried to make it work (for a while) using the default expand but I can't 
> quite get it to work. It feels like there is some legalizer work missing for 
> handling BF16 like we want to.
> Even though it's not ideal I think the custom lowering is easiest
What about Expand? that's where the implemented part is


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139398

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


[PATCH] D139398: [AMDGPU] Add bf16 storage support

2022-12-09 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:5573-5576
+  SDLoc SL(Op);
+  return DAG.getNode(
+  ISD::FP_EXTEND, SL, MVT::f32,
+  DAG.getNode(ISD::BITCAST, SL, MVT::f16, Op->getOperand(0)));

arsenm wrote:
> Pierre-vh wrote:
> > arsenm wrote:
> > > ExpandNode covers lowering BF16_TO_FP. It also has a shift by 16-bits 
> > > into the high bits. Is this correct?
> > Ah I didn't know that, though as long as we use custom lowering, and our 
> > FP_TO_BF16/BF16_TO_FP methods are consistent, it should be fine, no?
> bfloat16 has the same number of exponent bits in the same high bits as f32; I 
> kind of think the idea is you can just do a bitshift and then operate on f32? 
>  I think the fp_extend here is wrong
The default legalization also looks wrong to me. I don't understand why it 
isn't shifting down the mantissa bit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139398

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


[PATCH] D139544: [clang][dataflow] Add support for structured bindings of tuple-like types.

2022-12-09 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

This approach looks good to me. Some context: we kept the CFGs lightweight 
because it looks like we did not need to do any extensions for the Clang Static 
Analyzer. I'm glad the dataflow framework can also work with the current 
representation. On the other hand, I think structured bindings in C++ are 
really limited, e.g., we cannot nest them, and it is nowhere near what pattern 
matching can do in other languages like Rust. I do remember seeing papers about 
extending structured bindings in at least some dimensions like nesting. I 
wonder if making the representation more explicit in the CFG as structured 
bindings get more complex will simplify implementations in the future, but that 
is a problem for tomorrow :)




Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:191
 
+  // void VisitDeclRefExpr(const DeclRefExpr *S) {
+  //   assert(S->getDecl() != nullptr);

Nit commented out code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139544

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


[PATCH] D139723: [OpenMP][AMDGPU] Enable use of abs labs and llabs math functions in C code

2022-12-09 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

I'm not 100% sure if this was excluded on purpose or not. FWIW, in C, these 
functions are not defined in math.h 
(https://en.cppreference.com/w/c/numeric/math/abs), but in C++ they are 
(https://en.cppreference.com/w/cpp/numeric/math/abs).

Once we enable libm_gpu it might not make a difference. For now, I'm OK with 
this if it doesn't break peoples code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139723

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


[PATCH] D137058: [Driver] [Modules] Support -fmodule-output (1/2)

2022-12-09 Thread David Blaikie via Phabricator via cfe-commits
dblaikie requested changes to this revision.
dblaikie added a comment.
This revision now requires changes to proceed.

Please update the patch description/commit message to reflect the new naming.




Comment at: clang/test/Driver/save-std-c++-module-file.cpp:8-9
+//
+// RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output -o %t/output/Hello.o \
+// RUN:   -### 2>&1 | FileCheck %t/Hello.cppm -DPREFIX=%t 
--check-prefix=CHECK-WITH-OUTPUT
+

Not sure I understand the need for two tests here - they both specify an 
absolute path to a .o file & CHECK that the absolute path matches the .pcm 
output file path, so they don't seem to be testing distinct scenarios?



Comment at: clang/test/Driver/save-std-c++-module-file.cpp:14-15
+
+// CHECK: "-o" "[[PREFIX]]/Hello.pcm"
+// CHECK-WITH-OUTPUT: "-o" "[[PREFIX]]/output/Hello.pcm"

Might be worth fleshing out the CHECKs a bit more - 

If this patch implements:
> Support .cppm -> .pcm + .o in one phase.

Then I'd expect the test to demonstrate that - show that there are two commands 
run by the driver and one outputs the .o file (so include checking for the .o 
file output file name, and whatever flags tell the frontend that object code is 
to be emitted) and one that outputs the .pcm file (including checking the .pcm 
file output file name, and whatever flags tell the frontend that a pcm should 
be emitted).



Comment at: clang/test/Driver/save-std-c++-module-file.cpp:1-4
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//

dblaikie wrote:
> Is this needed? Maybe we don't need to split the file, if it's just the one 
> file anyway?
Ping on this ^


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

https://reviews.llvm.org/D137058

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


[PATCH] D131858: [clang] Track the templated entity in type substitution.

2022-12-09 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Ping @mizvekov.

Unfortunately I'm unable to revert this commit now so we won't be able to get 
the bot back to green until it's fixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

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


[PATCH] D139544: [clang][dataflow] Add support for structured bindings of tuple-like types.

2022-12-09 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 481677.
ymandel added a comment.

remove commented out code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139544

Files:
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -2860,6 +2860,59 @@
   )");
 }
 
+TEST_P(UncheckedOptionalAccessTest, StructuredBindingsFromStruct) {
+  ExpectDiagnosticsFor(R"(
+#include "unchecked_optional_access_test.h"
+
+struct kv { $ns::$optional opt; int x; };
+int target() {
+  auto [contents, x] = Make();
+  return contents ? *contents : x;
+}
+  )");
+
+  ExpectDiagnosticsFor(R"(
+#include "unchecked_optional_access_test.h"
+
+template 
+struct pair { T1 fst;  T2 snd; };
+int target() {
+  auto [contents, x] = Make, int>>();
+  return contents ? *contents : x;
+}
+  )");
+}
+
+TEST_P(UncheckedOptionalAccessTest, StructuredBindingsFromTupleLikeType) {
+  ExpectDiagnosticsFor(R"(
+#include "unchecked_optional_access_test.h"
+
+namespace std {
+template  struct tuple_size;
+template  struct tuple_element;
+template  class tuple;
+
+template 
+struct tuple_size> : integral_constant {};
+
+template 
+struct tuple_element> {
+  using type =  __type_pack_element;
+};
+
+template  class tuple {};
+template 
+typename tuple_element>::type get(tuple);
+} // namespace std
+
+std::tuple<$ns::$optional, int> get_opt();
+void target() {
+  auto [content, ck] = get_opt();
+  content ? *content : "";
+}
+  )");
+}
+
 // FIXME: Add support for:
 // - constructors (copy, move)
 // - assignment operators (default, copy, move)
Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3613,6 +3613,172 @@
   });
 }
 
+TEST(TransferTest, StructuredBindingAssignFromTupleLikeType) {
+  std::string Code = R"(
+namespace std {
+using size_t = int;
+template  struct tuple_size;
+template  struct tuple_element;
+template  class tuple;
+
+namespace {
+template 
+struct size_helper { static const T value = v; };
+} // namespace
+
+template 
+struct tuple_size> : size_helper {};
+
+template 
+struct tuple_element> {
+  using type =  __type_pack_element;
+};
+
+template  class tuple {};
+
+template 
+typename tuple_element>::type get(tuple);
+} // namespace std
+
+std::tuple makeTuple();
+
+void target(bool B) {
+  auto [BoundFoo, BoundBar] = makeTuple();
+  bool Baz;
+  // Include if-then-else to test interaction of `BindingDecl` with join.
+  if (B) {
+Baz = BoundFoo;
+(void)BoundBar;
+// [[p1]]
+  } else {
+Baz = BoundFoo;
+  }
+  (void)0;
+  // [[p2]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results.keys(), UnorderedElementsAre("p1", "p2"));
+const Environment &Env1 = getEnvironmentAtAnnotation(Results, "p1");
+
+const ValueDecl *BoundFooDecl = findValueDecl(ASTCtx, "BoundFoo");
+ASSERT_THAT(BoundFooDecl, NotNull());
+
+const ValueDecl *BoundBarDecl = findValueDecl(ASTCtx, "BoundBar");
+ASSERT_THAT(BoundBarDecl, NotNull());
+
+const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+ASSERT_THAT(BazDecl, NotNull());
+
+const Value *BoundFooValue =
+Env1.getValue(*BoundFooDecl, SkipPast::Reference);
+ASSERT_THAT(BoundFooValue, NotNull());
+EXPECT_TRUE(isa(BoundFooValue));
+
+const Value *BoundBarValue =
+Env1.getValue(*BoundBarDecl, SkipPast::Reference);
+ASSERT_THAT(BoundBarValue, NotNull());
+EXPECT_TRUE(isa(BoundBarValue));
+
+// Test that a `DeclRefExpr` to a `BindingDecl` works as expected.
+EXPECT_EQ(Env1.getValue(*BazDecl, SkipPast::Reference), BoundFooValue);
+
+const Environment &Env2 = getEnvironmentAtAnnotation(Results, "p2");
+
+// Test that `BoundFooDecl` retains the value we expect, after the join.
+BoundFooValue = Env2.getValue(*BoundFooDecl, SkipPast::Reference);
+EXPECT_EQ(Env2.getValue(*BazDecl, SkipPast::Reference), B

[PATCH] D139544: [clang][dataflow] Add support for structured bindings of tuple-like types.

2022-12-09 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel marked an inline comment as done.
ymandel added a comment.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139544

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


[PATCH] D139544: [clang][dataflow] Add support for structured bindings of tuple-like types.

2022-12-09 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

In D139544#3984835 , @xazax.hun wrote:

> This approach looks good to me. Some context: we kept the CFGs lightweight 
> because it looks like we did not need to do any extensions for the Clang 
> Static Analyzer. I'm glad the dataflow framework can also work with the 
> current representation. On the other hand, I think structured bindings in C++ 
> are really limited, e.g., we cannot nest them, and it is nowhere near what 
> pattern matching can do in other languages like Rust. I do remember seeing 
> papers about extending structured bindings in at least some dimensions like 
> nesting. I wonder if making the representation more explicit in the CFG as 
> structured bindings get more complex will simplify implementations in the 
> future, but that is a problem for tomorrow :)

Heh. Very much agree.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139544

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


[PATCH] D139652: Add the thread sanitizer support for X86_64 WatchOS simulators

2022-12-09 Thread Yifan Yang via Phabricator via cfe-commits
yfyang updated this revision to Diff 481679.
yfyang added a comment.

Addressing comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139652

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/fsanitize.c


Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -460,6 +460,15 @@
 // RUN: %clang --target=arm64-apple-macos -fsanitize=thread %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-TSAN-ARM64-MACOS
 // CHECK-TSAN-ARM64-MACOS-NOT: unsupported option
 
+// RUN: %clang --target=arm64-apple-ios-simulator -fsanitize=thread %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-IOSSIMULATOR
+// CHECK-TSAN-ARM64-IOSSIMULATOR-NOT: unsupported option
+
+// RUN: %clang --target=arm64-apple-watchos-simulator -fsanitize=thread %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-WATCHOSSIMULATOR
+// CHECK-TSAN-ARM64-WATCHOSSIMULATOR-NOT: unsupported option
+
+// RUN: %clang --target=arm64-apple-tvos-simulator -fsanitize=thread %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-TVOSSIMULATOR
+// CHECK-TSAN-ARM64-TVOSSIMULATOR-NOT: unsupported option
+
 // RUN: %clang --target=x86_64-apple-ios-simulator -fsanitize=thread %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-X86-64-IOSSIMULATOR
 // CHECK-TSAN-X86-64-IOSSIMULATOR-NOT: unsupported option
 
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -3277,12 +3277,10 @@
   !(isTargetIPhoneOS() && isIPhoneOSVersionLT(5, 0)))
 Res |= SanitizerKind::Vptr;
 
-  if ((IsX86_64 || IsAArch64) && isTargetMacOSBased()) {
+  if ((IsX86_64 || IsAArch64) && (isTargetMacOSBased() ||
+isTargetIOSSimulator() || isTargetTvOSSimulator() ||
+isTargetWatchOSSimulator()) {
 Res |= SanitizerKind::Thread;
-  } else if (isTargetIOSSimulator() || isTargetTvOSSimulator() ||
- isTargetWatchOSSimulator()) {
-if (IsX86_64)
-  Res |= SanitizerKind::Thread;
   }
   return Res;
 }


Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -460,6 +460,15 @@
 // RUN: %clang --target=arm64-apple-macos -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-MACOS
 // CHECK-TSAN-ARM64-MACOS-NOT: unsupported option
 
+// RUN: %clang --target=arm64-apple-ios-simulator -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-IOSSIMULATOR
+// CHECK-TSAN-ARM64-IOSSIMULATOR-NOT: unsupported option
+
+// RUN: %clang --target=arm64-apple-watchos-simulator -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-WATCHOSSIMULATOR
+// CHECK-TSAN-ARM64-WATCHOSSIMULATOR-NOT: unsupported option
+
+// RUN: %clang --target=arm64-apple-tvos-simulator -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-TVOSSIMULATOR
+// CHECK-TSAN-ARM64-TVOSSIMULATOR-NOT: unsupported option
+
 // RUN: %clang --target=x86_64-apple-ios-simulator -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-X86-64-IOSSIMULATOR
 // CHECK-TSAN-X86-64-IOSSIMULATOR-NOT: unsupported option
 
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -3277,12 +3277,10 @@
   !(isTargetIPhoneOS() && isIPhoneOSVersionLT(5, 0)))
 Res |= SanitizerKind::Vptr;
 
-  if ((IsX86_64 || IsAArch64) && isTargetMacOSBased()) {
+  if ((IsX86_64 || IsAArch64) && (isTargetMacOSBased() ||
+isTargetIOSSimulator() || isTargetTvOSSimulator() ||
+isTargetWatchOSSimulator()) {
 Res |= SanitizerKind::Thread;
-  } else if (isTargetIOSSimulator() || isTargetTvOSSimulator() ||
- isTargetWatchOSSimulator()) {
-if (IsX86_64)
-  Res |= SanitizerKind::Thread;
   }
   return Res;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139723: [OpenMP][AMDGPU] Enable use of abs labs and llabs math functions in C code

2022-12-09 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D139723#3984846 , @jdoerfert wrote:

> I'm not 100% sure if this was excluded on purpose or not. FWIW, in C, these 
> functions are not defined in math.h 
> (https://en.cppreference.com/w/c/numeric/math/abs), but in C++ they are 
> (https://en.cppreference.com/w/cpp/numeric/math/abs).
>
> Once we enable libm_gpu it might not make a difference. For now, I'm OK with 
> this if it doesn't break peoples code.

Should there be a separate builtin header corresponding to stdlib.h?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139723

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


[PATCH] D139652: Add the thread sanitizer support for X86_64 WatchOS simulators

2022-12-09 Thread Yifan Yang via Phabricator via cfe-commits
yfyang updated this revision to Diff 481682.
yfyang added a comment.

Formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139652

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp


Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -3277,9 +3277,9 @@
   !(isTargetIPhoneOS() && isIPhoneOSVersionLT(5, 0)))
 Res |= SanitizerKind::Vptr;
 
-  if ((IsX86_64 || IsAArch64) && (isTargetMacOSBased() ||
-isTargetIOSSimulator() || isTargetTvOSSimulator() ||
-isTargetWatchOSSimulator()) {
+  if ((IsX86_64 || IsAArch64) &&
+  (isTargetMacOSBased() || isTargetIOSSimulator() ||
+   isTargetTvOSSimulator() || isTargetWatchOSSimulator())) {
 Res |= SanitizerKind::Thread;
   }
   return Res;


Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -3277,9 +3277,9 @@
   !(isTargetIPhoneOS() && isIPhoneOSVersionLT(5, 0)))
 Res |= SanitizerKind::Vptr;
 
-  if ((IsX86_64 || IsAArch64) && (isTargetMacOSBased() ||
-isTargetIOSSimulator() || isTargetTvOSSimulator() ||
-isTargetWatchOSSimulator()) {
+  if ((IsX86_64 || IsAArch64) &&
+  (isTargetMacOSBased() || isTargetIOSSimulator() ||
+   isTargetTvOSSimulator() || isTargetWatchOSSimulator())) {
 Res |= SanitizerKind::Thread;
   }
   return Res;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139652: Add the thread sanitizer support for X86_64 WatchOS simulators

2022-12-09 Thread Yifan Yang via Phabricator via cfe-commits
yfyang updated this revision to Diff 481684.
yfyang added a comment.

- Add TSAN support for Apple arm64 simulators
- Formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139652

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/fsanitize.c


Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -460,9 +460,21 @@
 // RUN: %clang --target=arm64-apple-macos -fsanitize=thread %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-TSAN-ARM64-MACOS
 // CHECK-TSAN-ARM64-MACOS-NOT: unsupported option
 
+// RUN: %clang --target=arm64-apple-ios-simulator -fsanitize=thread %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-IOSSIMULATOR
+// CHECK-TSAN-ARM64-IOSSIMULATOR-NOT: unsupported option
+
+// RUN: %clang --target=arm64-apple-watchos-simulator -fsanitize=thread %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-WATCHOSSIMULATOR
+// CHECK-TSAN-ARM64-WATCHOSSIMULATOR-NOT: unsupported option
+
+// RUN: %clang --target=arm64-apple-tvos-simulator -fsanitize=thread %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-TVOSSIMULATOR
+// CHECK-TSAN-ARM64-TVOSSIMULATOR-NOT: unsupported option
+
 // RUN: %clang --target=x86_64-apple-ios-simulator -fsanitize=thread %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-X86-64-IOSSIMULATOR
 // CHECK-TSAN-X86-64-IOSSIMULATOR-NOT: unsupported option
 
+// RUN: %clang --target=x86_64-apple-watchos-simulator -fsanitize=thread %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-X86-64-WATCHOSSIMULATOR
+// CHECK-TSAN-X86-64-WATCHOSSIMULATOR-NOT: unsupported option
+
 // RUN: %clang --target=x86_64-apple-tvos-simulator -fsanitize=thread %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-X86-64-TVOSSIMULATOR
 // CHECK-TSAN-X86-64-TVOSSIMULATOR-NOT: unsupported option
 
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -3277,11 +3277,10 @@
   !(isTargetIPhoneOS() && isIPhoneOSVersionLT(5, 0)))
 Res |= SanitizerKind::Vptr;
 
-  if ((IsX86_64 || IsAArch64) && isTargetMacOSBased()) {
+  if ((IsX86_64 || IsAArch64) &&
+  (isTargetMacOSBased() || isTargetIOSSimulator() ||
+   isTargetTvOSSimulator() || isTargetWatchOSSimulator())) {
 Res |= SanitizerKind::Thread;
-  } else if (isTargetIOSSimulator() || isTargetTvOSSimulator()) {
-if (IsX86_64)
-  Res |= SanitizerKind::Thread;
   }
   return Res;
 }


Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -460,9 +460,21 @@
 // RUN: %clang --target=arm64-apple-macos -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-MACOS
 // CHECK-TSAN-ARM64-MACOS-NOT: unsupported option
 
+// RUN: %clang --target=arm64-apple-ios-simulator -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-IOSSIMULATOR
+// CHECK-TSAN-ARM64-IOSSIMULATOR-NOT: unsupported option
+
+// RUN: %clang --target=arm64-apple-watchos-simulator -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-WATCHOSSIMULATOR
+// CHECK-TSAN-ARM64-WATCHOSSIMULATOR-NOT: unsupported option
+
+// RUN: %clang --target=arm64-apple-tvos-simulator -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-TVOSSIMULATOR
+// CHECK-TSAN-ARM64-TVOSSIMULATOR-NOT: unsupported option
+
 // RUN: %clang --target=x86_64-apple-ios-simulator -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-X86-64-IOSSIMULATOR
 // CHECK-TSAN-X86-64-IOSSIMULATOR-NOT: unsupported option
 
+// RUN: %clang --target=x86_64-apple-watchos-simulator -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-X86-64-WATCHOSSIMULATOR
+// CHECK-TSAN-X86-64-WATCHOSSIMULATOR-NOT: unsupported option
+
 // RUN: %clang --target=x86_64-apple-tvos-simulator -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-X86-64-TVOSSIMULATOR
 // CHECK-TSAN-X86-64-TVOSSIMULATOR-NOT: unsupported option
 
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -3277,11 +3277,10 @@
   !(isTargetIPhoneOS() && isIPhoneOSVersionLT(5, 0)))
 Res |= SanitizerKind::Vptr;
 
-  if ((IsX86_64 || IsAArch64) && isTargetMacOSBased()) {
+  if ((IsX86_64 || IsAArch64) &&
+  (isTargetMacOSBased() || isTargetIOSSimulator() ||
+   isTargetTvOSSimulator() || isTargetWatchOSSimulator())) {
 Res |= SanitizerKind::Thread;
-  } else if (isTargetIOSSimulator() || isTargetTvOSSimulator()) {
-if (IsX86_64)
-  Res |= San

[PATCH] D139723: [OpenMP][AMDGPU] Enable use of abs labs and llabs math functions in C code

2022-12-09 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

In D139723#3984880 , @arsenm wrote:

> In D139723#3984846 , @jdoerfert 
> wrote:
>
>> I'm not 100% sure if this was excluded on purpose or not. FWIW, in C, these 
>> functions are not defined in math.h 
>> (https://en.cppreference.com/w/c/numeric/math/abs), but in C++ they are 
>> (https://en.cppreference.com/w/cpp/numeric/math/abs).
>>
>> Once we enable libm_gpu it might not make a difference. For now, I'm OK with 
>> this if it doesn't break peoples code.
>
> Should there be a separate builtin header corresponding to stdlib.h?

Probably. And we want to finish the libc_gpu/libm_gpu work to provide the 
definitions late (in LTO mode)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139723

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


[clang] 0073fd8 - Add the thread sanitizer support for X86_64 WatchOS simulators

2022-12-09 Thread Vy Nguyen via cfe-commits

Author: Yifan Yang
Date: 2022-12-09T13:32:56-05:00
New Revision: 0073fd8d0dda533a5acb1c237a37ad270d24b711

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

LOG: Add the thread sanitizer support for X86_64 WatchOS simulators

Allow TSan in clang driver for X86_64 WatchOS simulator.

It was already functional, and Apple's downstream fork of clang allows it, but 
that change had not made it upstream yet.

Reviewed By: jyknight, yln

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/Driver/fsanitize.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index f77a51250c192..eba602529a086 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -3277,11 +3277,10 @@ SanitizerMask Darwin::getSupportedSanitizers() const {
   !(isTargetIPhoneOS() && isIPhoneOSVersionLT(5, 0)))
 Res |= SanitizerKind::Vptr;
 
-  if ((IsX86_64 || IsAArch64) && isTargetMacOSBased()) {
+  if ((IsX86_64 || IsAArch64) &&
+  (isTargetMacOSBased() || isTargetIOSSimulator() ||
+   isTargetTvOSSimulator() || isTargetWatchOSSimulator())) {
 Res |= SanitizerKind::Thread;
-  } else if (isTargetIOSSimulator() || isTargetTvOSSimulator()) {
-if (IsX86_64)
-  Res |= SanitizerKind::Thread;
   }
   return Res;
 }

diff  --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c
index 6cf8bfa9be324..f5f5ceb220847 100644
--- a/clang/test/Driver/fsanitize.c
+++ b/clang/test/Driver/fsanitize.c
@@ -460,9 +460,21 @@
 // RUN: %clang --target=arm64-apple-macos -fsanitize=thread %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-TSAN-ARM64-MACOS
 // CHECK-TSAN-ARM64-MACOS-NOT: unsupported option
 
+// RUN: %clang --target=arm64-apple-ios-simulator -fsanitize=thread %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-IOSSIMULATOR
+// CHECK-TSAN-ARM64-IOSSIMULATOR-NOT: unsupported option
+
+// RUN: %clang --target=arm64-apple-watchos-simulator -fsanitize=thread %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-WATCHOSSIMULATOR
+// CHECK-TSAN-ARM64-WATCHOSSIMULATOR-NOT: unsupported option
+
+// RUN: %clang --target=arm64-apple-tvos-simulator -fsanitize=thread %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-TVOSSIMULATOR
+// CHECK-TSAN-ARM64-TVOSSIMULATOR-NOT: unsupported option
+
 // RUN: %clang --target=x86_64-apple-ios-simulator -fsanitize=thread %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-X86-64-IOSSIMULATOR
 // CHECK-TSAN-X86-64-IOSSIMULATOR-NOT: unsupported option
 
+// RUN: %clang --target=x86_64-apple-watchos-simulator -fsanitize=thread %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-X86-64-WATCHOSSIMULATOR
+// CHECK-TSAN-X86-64-WATCHOSSIMULATOR-NOT: unsupported option
+
 // RUN: %clang --target=x86_64-apple-tvos-simulator -fsanitize=thread %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-X86-64-TVOSSIMULATOR
 // CHECK-TSAN-X86-64-TVOSSIMULATOR-NOT: unsupported option
 



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


[PATCH] D139652: Add the thread sanitizer support for X86_64 WatchOS simulators

2022-12-09 Thread Vy Nguyen 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 rG0073fd8d0dda: Add the thread sanitizer support for X86_64 
WatchOS simulators (authored by yfyang, committed by oontvoo).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139652

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/fsanitize.c


Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -460,9 +460,21 @@
 // RUN: %clang --target=arm64-apple-macos -fsanitize=thread %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-TSAN-ARM64-MACOS
 // CHECK-TSAN-ARM64-MACOS-NOT: unsupported option
 
+// RUN: %clang --target=arm64-apple-ios-simulator -fsanitize=thread %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-IOSSIMULATOR
+// CHECK-TSAN-ARM64-IOSSIMULATOR-NOT: unsupported option
+
+// RUN: %clang --target=arm64-apple-watchos-simulator -fsanitize=thread %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-WATCHOSSIMULATOR
+// CHECK-TSAN-ARM64-WATCHOSSIMULATOR-NOT: unsupported option
+
+// RUN: %clang --target=arm64-apple-tvos-simulator -fsanitize=thread %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-TVOSSIMULATOR
+// CHECK-TSAN-ARM64-TVOSSIMULATOR-NOT: unsupported option
+
 // RUN: %clang --target=x86_64-apple-ios-simulator -fsanitize=thread %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-X86-64-IOSSIMULATOR
 // CHECK-TSAN-X86-64-IOSSIMULATOR-NOT: unsupported option
 
+// RUN: %clang --target=x86_64-apple-watchos-simulator -fsanitize=thread %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-X86-64-WATCHOSSIMULATOR
+// CHECK-TSAN-X86-64-WATCHOSSIMULATOR-NOT: unsupported option
+
 // RUN: %clang --target=x86_64-apple-tvos-simulator -fsanitize=thread %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-X86-64-TVOSSIMULATOR
 // CHECK-TSAN-X86-64-TVOSSIMULATOR-NOT: unsupported option
 
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -3277,11 +3277,10 @@
   !(isTargetIPhoneOS() && isIPhoneOSVersionLT(5, 0)))
 Res |= SanitizerKind::Vptr;
 
-  if ((IsX86_64 || IsAArch64) && isTargetMacOSBased()) {
+  if ((IsX86_64 || IsAArch64) &&
+  (isTargetMacOSBased() || isTargetIOSSimulator() ||
+   isTargetTvOSSimulator() || isTargetWatchOSSimulator())) {
 Res |= SanitizerKind::Thread;
-  } else if (isTargetIOSSimulator() || isTargetTvOSSimulator()) {
-if (IsX86_64)
-  Res |= SanitizerKind::Thread;
   }
   return Res;
 }


Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -460,9 +460,21 @@
 // RUN: %clang --target=arm64-apple-macos -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-MACOS
 // CHECK-TSAN-ARM64-MACOS-NOT: unsupported option
 
+// RUN: %clang --target=arm64-apple-ios-simulator -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-IOSSIMULATOR
+// CHECK-TSAN-ARM64-IOSSIMULATOR-NOT: unsupported option
+
+// RUN: %clang --target=arm64-apple-watchos-simulator -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-WATCHOSSIMULATOR
+// CHECK-TSAN-ARM64-WATCHOSSIMULATOR-NOT: unsupported option
+
+// RUN: %clang --target=arm64-apple-tvos-simulator -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-TVOSSIMULATOR
+// CHECK-TSAN-ARM64-TVOSSIMULATOR-NOT: unsupported option
+
 // RUN: %clang --target=x86_64-apple-ios-simulator -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-X86-64-IOSSIMULATOR
 // CHECK-TSAN-X86-64-IOSSIMULATOR-NOT: unsupported option
 
+// RUN: %clang --target=x86_64-apple-watchos-simulator -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-X86-64-WATCHOSSIMULATOR
+// CHECK-TSAN-X86-64-WATCHOSSIMULATOR-NOT: unsupported option
+
 // RUN: %clang --target=x86_64-apple-tvos-simulator -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-X86-64-TVOSSIMULATOR
 // CHECK-TSAN-X86-64-TVOSSIMULATOR-NOT: unsupported option
 
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -3277,11 +3277,10 @@
   !(isTargetIPhoneOS() && isIPhoneOSVersionLT(5, 0)))
 Res |= SanitizerKind::Vptr;
 
-  if ((IsX86_64 || IsAArch64) && isTargetMacOSBased()) {
+  if ((IsX86_64 || IsAArch64) &&
+  (isTargetMacOSBased() || isTargetIOSSimulator() ||
+   isTargetTvOSSimulator() || isTargetWatchOSSimulator()))

[PATCH] D139287: [WIP][OpenMP] Introduce basic JIT support to OpenMP target offloading

2022-12-09 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 481686.
tianshilei1992 added a comment.
Herald added a subscriber: pcwang-thead.

rebase and refine

It currently crashes in `setupLLVMOptimizationRemarks`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139287

Files:
  openmp/libomptarget/plugins-nextgen/CMakeLists.txt
  openmp/libomptarget/plugins-nextgen/common/PluginInterface/CMakeLists.txt
  openmp/libomptarget/plugins-nextgen/common/PluginInterface/JIT.cpp
  openmp/libomptarget/plugins-nextgen/common/PluginInterface/JIT.h
  openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp
  openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
  openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
  openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp

Index: openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp
===
--- openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp
+++ openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp
@@ -358,6 +358,10 @@
   Expected isImageCompatible(__tgt_image_info *Info) const override {
 return true;
   }
+
+  Triple::ArchType getTripleArch() const override {
+return Triple::LIBOMPTARGET_NEXTGEN_GENERIC_PLUGIN_TRIPLE;
+  }
 };
 
 GenericPluginTy *Plugin::createPlugin() { return new GenELF64PluginTy(); }
Index: openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
===
--- openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
+++ openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
@@ -278,6 +278,14 @@
  GridValues.GV_Warp_Size))
   return Err;
 
+if (auto Err = getDeviceAttr(CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR,
+ ComputeCapability.Major))
+  return Err;
+
+if (auto Err = getDeviceAttr(CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR,
+ ComputeCapability.Minor))
+  return Err;
+
 return Plugin::success();
   }
 
@@ -776,6 +784,8 @@
 return Plugin::check(Res, "Error in cuDeviceGetAttribute: %s");
   }
 
+  std::string getArch() const override { return ComputeCapability.str(); }
+
 private:
   using CUDAStreamManagerTy = GenericDeviceResourceManagerTy;
   using CUDAEventManagerTy = GenericDeviceResourceManagerTy;
@@ -792,6 +802,15 @@
 
   /// The CUDA device handler.
   CUdevice Device = CU_DEVICE_INVALID;
+
+  ///
+  struct ComputeCapabilityTy {
+uint32_t Major;
+uint32_t Minor;
+std::string str() const {
+  return "sm_" + std::to_string(Major * 10 + Minor);
+}
+  } ComputeCapability;
 };
 
 Error CUDAKernelTy::launchImpl(GenericDeviceTy &GenericDevice,
@@ -890,6 +909,11 @@
   /// Get the ELF code for recognizing the compatible image binary.
   uint16_t getMagicElfBits() const override { return ELF::EM_CUDA; }
 
+  Triple::ArchType getTripleArch() const override {
+// TODO: I think we can drop the support for 32-bit NVPTX devices.
+return Triple::nvptx64;
+  }
+
   /// Check whether the image is compatible with the available CUDA devices.
   Expected isImageCompatible(__tgt_image_info *Info) const override {
 for (int32_t DevId = 0; DevId < getNumDevices(); ++DevId) {
Index: openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
===
--- openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
+++ openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
@@ -25,6 +25,7 @@
 #include "omptarget.h"
 
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Triple.h"
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
 #include "llvm/Frontend/OpenMP/OMPGridValues.h"
 #include "llvm/Support/Allocator.h"
@@ -372,6 +373,17 @@
   }
   uint32_t getDynamicMemorySize() const { return OMPX_SharedMemorySize; }
 
+  /// Get target architecture.
+  virtual std::string getArch() const {
+llvm_unreachable("device doesn't support JIT");
+  }
+
+  /// Post processing after jit backend. The ownership of \p MB will be taken.
+  virtual Expected>
+  doJITPostProcessing(std::unique_ptr MB) const {
+return MB;
+  }
+
 private:
   /// Register offload entry for global variable.
   Error registerGlobalOffloadEntry(DeviceImageTy &DeviceImage,
@@ -482,6 +494,11 @@
   /// Get the ELF code to recognize the binary image of this plugin.
   virtual uint16_t getMagicElfBits() const = 0;
 
+  /// Get the target triple of this plugin.
+  virtual Triple::ArchType getTripleArch() const {
+llvm_unreachable("target doesn't support jit");
+  }
+
   /// Allocate a structure using the internal allocator.
   template  Ty *allocate() {
 return reinterpret_cast(Allocator.Allocate(sizeof(Ty), alignof(Ty)));
Index: openmp/libomptarge

  1   2   3   >