[PATCH] D104904: [OpenMP][AMDGCN] Initial math headers support

2021-06-25 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

Really looking forward to this! Thanks a lot!

I left some comments.




Comment at: clang/lib/Headers/__clang_hip_math.h:35
+#ifdef __OPENMP_AMDGCN__
+#define __RETURN_TYPE int
+#else

JonChesterfield wrote:
> I'd expect openmp to match the cplusplus/c distinction here, as openmp works 
> on C source
^ Agreed. Though, we use a different trick because it's unfortunately not as 
straight forward always and can be decided based on the C vs C++.



Comment at: 
clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h:112
+
+#pragma omp end declare variant
+

Can you make the declare variant scope of nvptx and amdgpu smaller and put them 
next to each other.

```

#ifdef __cplusplus
extern "C" {
#endif

#declare variant
#define ...
...
#undef
#end


#declare variant
...
#end

#ifdef __cplusplus
} // extern "C"


```



Comment at: clang/lib/Headers/openmp_wrappers/cmath:83
+#include <__clang_hip_cmath.h>
+#undef __OPENMP_AMDGCN__
+

No match_any needed (here and elsewhere).

Also, don't we want all but the includes to be the same for both GPUs. Maybe we 
have a device(kind(gpu)) variant and inside the nvptx and amdgpu just for the 
respective include?



Comment at: clang/lib/Headers/openmp_wrappers/math.h:59
+#pragma omp end declare variant
+
 #endif

FWIW, This is what I think the begin/end regions should look like. Small and 
next to each other.



Comment at: clang/test/Headers/Inputs/include/cstdlib:15
 
+#ifndef __AMDGCN__
 namespace std

JonChesterfield wrote:
> I think I'd expect builtin_labs et al to work on amdgcn, are we missing 
> lowering for them?
Yeah, looks weird that we cannot compile this mock-up header.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104904

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


[PATCH] D104963: [ODR] Fix using uninitialized FunctionTypeBits.FastTypeQuals in FunctionNoProtoType.

2021-06-25 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Wasn't actually able to make the test fail because Memory Sanitizer isn't 
supported on macOS and on Linux I cannot even build clang with MSAN enabled. 
The test case is reduced from an actual error we've seen internally when clang 
complaints `Handler` has different definitions in different modules. That was 
happening because due to uninitialized FastTypeQuals ODR-hash for different 
modules //sometimes// was different. It is a spurious error and I don't see how 
to create a reliable test case.

Also I don't know if we should keep FastTypeQuals in FunctionTypeBitfields or 
move somewhere else. Looks like it is there for a reason, so I've decided not 
to touch that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104963

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


[PATCH] D104963: [ODR] Fix using uninitialized FunctionTypeBits.FastTypeQuals in FunctionNoProtoType.

2021-06-25 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai created this revision.
vsapsai added reviewers: rsmith, riccibruno.
Herald added a subscriber: ributzka.
vsapsai requested review of this revision.
Herald added a project: clang.

FastTypeQuals are used only by FunctionProtoType and put in
FunctionTypeBitfields in FunctionType to pack with the other bitfields.
So in ODR-hashing they should be used only for FunctionProtoType but not
for FunctionNoProtoType or for common FunctionType.

rdar://65305646


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104963

Files:
  clang/lib/AST/ODRHash.cpp
  clang/test/Modules/odr_hash-record.c


Index: clang/test/Modules/odr_hash-record.c
===
--- clang/test/Modules/odr_hash-record.c
+++ clang/test/Modules/odr_hash-record.c
@@ -381,6 +381,21 @@
 struct TSS1 *tss1;
 #endif
 
+// Function pointer in a struct.
+#if defined(FIRST)
+typedef void (*HandlerProcPtr)();
+struct Handler {
+HandlerProcPtr procPtr;
+};
+#elif defined(SECOND)
+typedef void (*HandlerProcPtr)();
+struct Handler {
+HandlerProcPtr procPtr;
+};
+#else
+struct Handler h;
+#endif
+
 // Keep macros contained to one file.
 #ifdef FIRST
 #undef FIRST
Index: clang/lib/AST/ODRHash.cpp
===
--- clang/lib/AST/ODRHash.cpp
+++ clang/lib/AST/ODRHash.cpp
@@ -910,9 +910,6 @@
   void VisitFunctionType(const FunctionType *T) {
 AddQualType(T->getReturnType());
 T->getExtInfo().Profile(ID);
-Hash.AddBoolean(T->isConst());
-Hash.AddBoolean(T->isVolatile());
-Hash.AddBoolean(T->isRestrict());
 VisitType(T);
   }
 
@@ -921,6 +918,9 @@
   }
 
   void VisitFunctionProtoType(const FunctionProtoType *T) {
+Hash.AddBoolean(T->isConst());
+Hash.AddBoolean(T->isVolatile());
+Hash.AddBoolean(T->isRestrict());
 ID.AddInteger(T->getNumParams());
 for (auto ParamType : T->getParamTypes())
   AddQualType(ParamType);


Index: clang/test/Modules/odr_hash-record.c
===
--- clang/test/Modules/odr_hash-record.c
+++ clang/test/Modules/odr_hash-record.c
@@ -381,6 +381,21 @@
 struct TSS1 *tss1;
 #endif
 
+// Function pointer in a struct.
+#if defined(FIRST)
+typedef void (*HandlerProcPtr)();
+struct Handler {
+HandlerProcPtr procPtr;
+};
+#elif defined(SECOND)
+typedef void (*HandlerProcPtr)();
+struct Handler {
+HandlerProcPtr procPtr;
+};
+#else
+struct Handler h;
+#endif
+
 // Keep macros contained to one file.
 #ifdef FIRST
 #undef FIRST
Index: clang/lib/AST/ODRHash.cpp
===
--- clang/lib/AST/ODRHash.cpp
+++ clang/lib/AST/ODRHash.cpp
@@ -910,9 +910,6 @@
   void VisitFunctionType(const FunctionType *T) {
 AddQualType(T->getReturnType());
 T->getExtInfo().Profile(ID);
-Hash.AddBoolean(T->isConst());
-Hash.AddBoolean(T->isVolatile());
-Hash.AddBoolean(T->isRestrict());
 VisitType(T);
   }
 
@@ -921,6 +918,9 @@
   }
 
   void VisitFunctionProtoType(const FunctionProtoType *T) {
+Hash.AddBoolean(T->isConst());
+Hash.AddBoolean(T->isVolatile());
+Hash.AddBoolean(T->isRestrict());
 ID.AddInteger(T->getNumParams());
 for (auto ParamType : T->getParamTypes())
   AddQualType(ParamType);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104899: [clang][tests] Specify unwindlib in aix-ld tests

2021-06-25 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast accepted this revision.
hubert.reinterpretcast added a comment.
This revision is now accepted and ready to land.

LGTM; thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104899

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


[PATCH] D104896: [DFSan] Change shadow and origin memory layouts to match MSan.

2021-06-25 Thread Andrew via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG45f6d5522f8d: [DFSan] Change shadow and origin memory 
layouts to match MSan. (authored by browneee).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104896

Files:
  clang/docs/DataFlowSanitizerDesign.rst
  compiler-rt/lib/dfsan/dfsan.cpp
  compiler-rt/lib/dfsan/dfsan.h
  compiler-rt/lib/dfsan/dfsan_allocator.cpp
  compiler-rt/lib/dfsan/dfsan_platform.h
  compiler-rt/test/dfsan/origin_invalid.c
  llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
  llvm/test/Instrumentation/DataFlowSanitizer/atomics.ll
  llvm/test/Instrumentation/DataFlowSanitizer/basic.ll
  llvm/test/Instrumentation/DataFlowSanitizer/load.ll
  llvm/test/Instrumentation/DataFlowSanitizer/origin_load.ll
  llvm/test/Instrumentation/DataFlowSanitizer/origin_store.ll
  llvm/test/Instrumentation/DataFlowSanitizer/store.ll

Index: llvm/test/Instrumentation/DataFlowSanitizer/store.ll
===
--- llvm/test/Instrumentation/DataFlowSanitizer/store.ll
+++ llvm/test/Instrumentation/DataFlowSanitizer/store.ll
@@ -22,7 +22,7 @@
   ; COMBINE_PTR_LABEL: load i[[#SBITS]], i[[#SBITS]]* {{.*}} @__dfsan_arg_tls
   ; COMBINE_PTR_LABEL: or i[[#SBITS]]
   ; CHECK: ptrtoint i8* {{.*}} i64
-  ; CHECK-NEXT:and i64
+  ; CHECK-NEXT:xor i64
   ; CHECK-NEXT:inttoptr i64 {{.*}} i[[#SBITS]]*
   ; CHECK-NEXT:getelementptr i[[#SBITS]], i[[#SBITS]]*
   ; CHECK-NEXT:store i[[#SBITS]]
@@ -39,7 +39,7 @@
   ; COMBINE_PTR_LABEL: load i[[#SBITS]], i[[#SBITS]]* {{.*}} @__dfsan_arg_tls
   ; COMBINE_PTR_LABEL: or i[[#SBITS]]
   ; CHECK: ptrtoint i16* {{.*}} i64
-  ; CHECK-NEXT:and i64
+  ; CHECK-NEXT:xor i64
   ; CHECK-NEXT:inttoptr i64 {{.*}} i[[#SBITS]]*
   ; CHECK-NEXT:getelementptr i[[#SBITS]], i[[#SBITS]]*
   ; CHECK-NEXT:store i[[#SBITS]]
@@ -58,7 +58,7 @@
   ; COMBINE_PTR_LABEL: load i[[#SBITS]], i[[#SBITS]]* {{.*}} @__dfsan_arg_tls
   ; COMBINE_PTR_LABEL: or i[[#SBITS]]
   ; CHECK: ptrtoint i32* {{.*}} i64
-  ; CHECK-NEXT:and i64
+  ; CHECK-NEXT:xor i64
   ; CHECK-NEXT:inttoptr i64 {{.*}} i[[#SBITS]]*
   ; CHECK-NEXT:getelementptr i[[#SBITS]], i[[#SBITS]]*
   ; CHECK-NEXT:store i[[#SBITS]]
@@ -81,7 +81,7 @@
   ; COMBINE_PTR_LABEL: load i[[#SBITS]], i[[#SBITS]]* {{.*}} @__dfsan_arg_tls
   ; COMBINE_PTR_LABEL: or i[[#SBITS]]
   ; CHECK: ptrtoint i64* {{.*}} i64
-  ; CHECK-NEXT:and i64
+  ; CHECK-NEXT:xor i64
   ; CHECK-NEXT:inttoptr i64 {{.*}} i[[#SBITS]]*
   ; CHECK-COUNT-8: insertelement {{.*}} i[[#SBITS]]
   ; CHECK-NEXT:bitcast i[[#SBITS]]* {{.*}} <8 x i[[#SBITS]]>*
Index: llvm/test/Instrumentation/DataFlowSanitizer/origin_store.ll
===
--- llvm/test/Instrumentation/DataFlowSanitizer/origin_store.ll
+++ llvm/test/Instrumentation/DataFlowSanitizer/origin_store.ll
@@ -52,9 +52,9 @@
   ; CHECK-NEXT:   %[[#AO:]] = load i32, i32* getelementptr inbounds ([200 x i32], [200 x i32]* @__dfsan_arg_origin_tls, i64 0, i64 0), align 4
   ; CHECK-NEXT:   %[[#AS:]] = load i[[#SBITS]], i[[#SBITS]]* bitcast ([100 x i64]* @__dfsan_arg_tls to i[[#SBITS]]*), align [[ALIGN]]
   ; CHECK:%[[#INTP:]] = ptrtoint i16* %p to i64
-  ; CHECK-NEXT:   %[[#SHADOW_ADDR:]] = and i64 %[[#INTP]], [[#%.10d,MASK:]]
-  ; CHECK-NEXT:   %[[#SHADOW_PTR0:]] = inttoptr i64 %[[#SHADOW_ADDR]] to i[[#SBITS]]*
-  ; CHECK-NEXT:   %[[#ORIGIN_OFFSET:]] = add i64 %[[#INTP+1]], [[#%.10d,ORIGIN_MASK:]]
+  ; CHECK-NEXT:   %[[#SHADOW_OFFSET:]] = xor i64 %[[#INTP]], [[#%.10d,MASK:]]
+  ; CHECK-NEXT:   %[[#SHADOW_PTR0:]] = inttoptr i64 %[[#SHADOW_OFFSET]] to i[[#SBITS]]*
+  ; CHECK-NEXT:   %[[#ORIGIN_OFFSET:]] = add i64 %[[#SHADOW_OFFSET]], [[#%.10d,ORIGIN_BASE:]]
   ; CHECK-NEXT:   %[[#ORIGIN_ADDR:]] = and i64 %[[#ORIGIN_OFFSET]], -4
   ; CHECK-NEXT:   %[[#ORIGIN_PTR:]] = inttoptr i64 %[[#ORIGIN_ADDR]] to i32*
   ; CHECK:%_dfscmp = icmp ne i[[#SBITS]] %[[#AS]], 0
Index: llvm/test/Instrumentation/DataFlowSanitizer/origin_load.ll
===
--- llvm/test/Instrumentation/DataFlowSanitizer/origin_load.ll
+++ llvm/test/Instrumentation/DataFlowSanitizer/origin_load.ll
@@ -35,9 +35,9 @@
 define i16* @load_escaped_alloca() {
   ; CHECK-LABEL:  @load_escaped_alloca.dfsan
   ; CHECK:%[[#INTP:]] = ptrtoint i16* %p to i64
-  ; CHECK-NEXT:   %[[#SHADOW_ADDR:]] = and i64 %[[#INTP]], [[#%.10d,MASK:]]
-  ; CHECK-NEXT:   %[[#SHADOW_PTR0:]] = inttoptr i64 %[[#SHADOW_ADDR]] to i[[#SBITS]]*
-  ; CHECK-NEXT:   %[[#ORIGIN_OFFSET:]] = add i64 %[[#INTP+1]], [[#%.10d,ORIGIN_MASK:]]
+  ; CHECK-NEXT:   %[[#SHADOW_OFFSET:]] = xor i64 %[[#INTP]], [[#%.10d,MASK:]]
+  ; 

[PATCH] D104904: [OpenMP][AMDGCN] Initial math headers support

2021-06-25 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

Those changes in OpenMP headers LGTM, except `#define __device__`.




Comment at: 
clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h:93
+
+#define __device__ __attribute__((device))
+

JonChesterfield wrote:
> i think this should be `#define __device__`
Right because we already have `declare variant`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104904

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


[PATCH] D104883: [CodeGen] Add ParmVarDecls to FunctionDecls that are created to generate ObjC property getter/setter functions

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

In D104883#2841931 , @ahatanak wrote:

> I see `assert(DC && "This decl is not contained in a translation unit!");` 
> fail in `Decl::getTranslationUnitDecl` when `DeclRefExpr` is constructed. 
> That's because the `ImplicitParamDecl` passed to `DeclRefExpr`'s constructor 
> doesn't have a decl context if I delete `FD`. So it looks like `FD` is needed 
> in these cases.

Hmm, OK - I think I'm following enough. I'll leave the rest to you & @aprantl - 
appreciate the work!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104883

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


[PATCH] D94355: [Passes] Add relative lookup table converter pass

2021-06-25 Thread Gulfem Savrun Yeniceri via Phabricator via cfe-commits
gulfem added inline comments.



Comment at: llvm/lib/Transforms/Utils/RelLookupTableConverter.cpp:73
+  return false;
+
+// If an operand in the lookup table is not dso_local,

pcc wrote:
> In the version of the patch that you committed, you have this check here:
> ```
> // If operand is mutable, do not generate a relative lookup table.
> auto *GlovalVarOp = dyn_cast(GVOp);
> if (!GlovalVarOp || !GlovalVarOp->isConstant())
>   return false;
> ```
> 1. Nit: Gloval -> Global
> 2. Why is it important whether the referenced global is mutable? The pointer 
> itself is constant.
1. That's a typo, and I will fix that.
2. This optimization does not do a detailed analysis, and it is being 
conservative.
 In this case, `GlobalVar` points to the switch lookup table and 
`GlobalVarOp` points to the elements in the lookup table like strings.
 To make sure that relative arithmetic works, it just checks whether both 
`GlobalVar` and `GlobalVarOp` pointers are constants.
 Did you see an issue on that?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94355

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


[PATCH] D104883: [CodeGen] Add ParmVarDecls to FunctionDecls that are created to generate ObjC property getter/setter functions

2021-06-25 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

I see `assert(DC && "This decl is not contained in a translation unit!");` fail 
in `Decl::getTranslationUnitDecl` when `DeclRefExpr` is constructed. That's 
because the `ImplicitParamDecl` passed to `DeclRefExpr`'s constructor doesn't 
have a decl context if I delete `FD`. So it looks like `FD` is needed in these 
cases.




Comment at: clang/lib/CodeGen/CGObjC.cpp:3702
+  /*DefArg=*/nullptr);
+  args.push_back(Params[0] = DstDecl);
+  ParmVarDecl *SrcDecl = ParmVarDecl::Create(

aprantl wrote:
> Does this compile without warnings?
Yes, clang compiles this without any warnings. I don't know whether other 
compilers warn.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104883

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


[PATCH] D103461: [clang][deps] NFC: Preserve the original frontend action

2021-06-25 Thread Bardia Mahjour via Phabricator via cfe-commits
bmahjour added a comment.

@jansvoboda11 This change is causing the following LIT tests to fail on AIX:

  Clang :: ClangScanDeps/headerwithdirname.cpp
  Clang :: ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp

The reason seems to be related to the fact that `-fno-integrated-as` is on by 
default on that platform. I get the same failure on Linux if I change the 
"compilation database" file to add `-fno-integrated-as` to the "command" line:

  > ./bin/clang-scan-deps -compilation-database ./headerwithdirname.cpp.tmp.cdb 
-j 1
  > Error while scanning dependencies for 
/build_llvm/tools/clang/test/ClangScanDeps/Output/headerwithdirname.cpp.tmp.dir/headerwithdirname_input.cpp:
  error: unable to handle compilation, expected exactly one compiler job in ' 
"clang" "-cc1" "-triple" "powerpc64le-unknown-linux-gnu" "-S" ...;  
"/usr/bin/as" "-a64" "-mppc64" "-mlittle-endian" "-mpower8" "-I" 
"/build_llvm/tools/clang/test/ClangScanDeps/Output/headerwithdirname.cpp.tmp.dir"
 "-I" 
"/build_llvm/tools/clang/test/ClangScanDeps/Output/headerwithdirname.cpp.tmp.dir/foodir"
 "-I" "Inputs" "-o" "headerwithdirname_input.o" 
"/tmp/headerwithdirname_input-2e0050.s"; '


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103461

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


[PATCH] D104952: [hexagon] Add {hvx,}hexagon_{protos,circ_brev...}

2021-06-25 Thread Brian Cain via Phabricator via cfe-commits
bcain added a comment.

It occurs to me now that some of these are not very useful in the absence of 
`hexagon_types.h`.  So I will add that one too and change the tests to use 
those definitions instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104952

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


[PATCH] D104871: [Docs] use -fprofile-generate for IR PGO and -fprofile-instr-generate for code coverage

2021-06-25 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 354615.
zequanwu marked an inline comment as done.
zequanwu added a comment.

Update wording.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104871

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/docs/UsersManual.rst


Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -1876,14 +1876,14 @@
 Although both techniques are used for similar purposes, there are important
 differences between the two:
 
-1. Profile data generated with one cannot be used by the other, and there is no
-   conversion tool that can convert one to the other. So, a profile generated
-   via ``-fprofile-instr-generate`` must be used with ``-fprofile-instr-use``.
-   Similarly, sampling profiles generated by external profilers must be
+1. For profile guided optimizations, we recommend using IR PGO, aka using 
+   ``-fprofile-generate`` with ``-fprofile-use``.
+   Sampling profiles generated by external profilers must be
converted and used with ``-fprofile-sample-use``.
 
-2. Instrumentation profile data can be used for code coverage analysis and
-   optimization.
+2. Instrumentation profile data generated via ``-fprofile-generate`` can be 
used 
+   for optimization and data generated via 
+   ``-fprofile-instr-generate`` can be used for code coverage analysis.
 
 3. Sampling profiles can only be used for optimization. They cannot be used for
code coverage analysis. Although it would be technically possible to use
@@ -2114,26 +2114,35 @@
 Profiling with Instrumentation
 ^^
 
-Clang also supports profiling via instrumentation. This requires building a
-special instrumented version of the code and has some runtime
+Two types of instrumentations
+""
+
+1. ``-fprofile-generate`` is the LLVM IR-based instrumentation, which aims for 
+performance.
+
+2. ``-fprofile-instr-generate`` is the AST-based instrumentation used for code
+coverage analysis (:doc:`source based code coverage 
`).
+
+This section forcuses on LLVM IR instrumentation. This requires 
+building a special instrumented version of the code and has some runtime
 overhead during the profiling, but it provides more detailed results than a
 sampling profiler. It also provides reproducible results, at least to the
 extent that the code behaves consistently across runs.
 
-Here are the steps for using profile guided optimization with
+Here are the steps for using profile guided optimization with LLVM IR
 instrumentation:
 
 1. Build an instrumented version of the code by compiling and linking with the
-   ``-fprofile-instr-generate`` option.
+   ``-fprofile-generate`` option.
 
.. code-block:: console
 
- $ clang++ -O2 -fprofile-instr-generate code.cc -o code
+ $ clang++ -O2 -fprofile-generate code.cc -o code
 
 2. Run the instrumented executable with inputs that reflect the typical usage.
By default, the profile data will be written to a ``default.profraw`` file
in the current directory. You can override that default by using option
-   ``-fprofile-instr-generate=`` or by setting the ``LLVM_PROFILE_FILE`` 
+   ``-fprofile-generate=`` or by setting the ``LLVM_PROFILE_FILE`` 
environment variable to specify an alternate file. If non-default file name
is specified by both the environment variable and the command line option,
the environment variable takes precedence. The file name pattern specified
Index: clang/docs/ClangCommandLineReference.rst
===
--- clang/docs/ClangCommandLineReference.rst
+++ clang/docs/ClangCommandLineReference.rst
@@ -2141,7 +2141,7 @@
 
 .. option:: -fprofile-generate, -fno-profile-generate
 
-Generate instrumented code to collect execution counts into default.profraw 
(overridden by LLVM\_PROFILE\_FILE env var)
+Generate instrumented code to collect execution counts into default.profraw 
(overridden by LLVM\_PROFILE\_FILE env var), used for IR PGO.
 
 .. program:: clang1
 .. option:: -fprofile-generate=
@@ -2151,7 +2151,7 @@
 
 .. option:: -fprofile-instr-generate, -fno-profile-instr-generate
 
-Generate instrumented code to collect execution counts into default.profraw 
file (overridden by '=' form of option or LLVM\_PROFILE\_FILE env var)
+Generate instrumented code to collect execution counts into default.profraw 
file (overridden by '=' form of option or LLVM\_PROFILE\_FILE env var), used 
for code coverage analysis.
 
 .. program:: clang1
 .. option:: -fprofile-instr-generate=


Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -1876,14 +1876,14 @@
 Although both techniques are used for similar purposes, there are important
 differences 

[clang] ad14b5b - [clang] Stop providing builtin overload candidate for relational function pointer comparisons

2021-06-25 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-06-26T00:08:02+02:00
New Revision: ad14b5b008e2f643cb989ec645f12bf26a8659bb

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

LOG: [clang] Stop providing builtin overload candidate for relational function 
pointer comparisons

Word on the grapevine was that the committee had some discussion that
ended with unanimous agreement on eliminating relational function pointer 
comparisons.

We wanted to be bold and just ban all of them cold turkey.
But then we chickened out at the last second and are going for
eliminating just the spaceship overload candidate instead, for now.

See D104680 for reference.

This should be fine and "safe", because the only possible semantic change this
would cause is that overload resolution could possibly be ambiguous if
there was another viable candidate equally as good.

But to save face a little we are going to:
* Issue an "error" for three-way comparisons on function pointers.
  But all this is doing really is changing one vague error message,
  from an "invalid operands to binary expression" into an
  "ordered comparison of function pointers", which sounds more like we mean 
business.
* Otherwise "warn" that comparing function pointers like that is totally
  not cool (unless we are told to keep quiet about this).

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 
clang/test/SemaCXX/compare-function-pointer.cpp

Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaOverload.cpp
clang/test/CXX/class/class.compare/class.spaceship/p2.cpp
clang/test/CXX/drs/dr15xx.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/CXX/expr/expr.const/p2-0x.cpp
clang/test/FixIt/fixit.cpp
clang/test/Parser/cxx-template-argument.cpp
clang/test/Sema/compare.c
clang/test/SemaCXX/compare-cxx2a.cpp
clang/test/SemaTemplate/resolve-single-template-id.cpp
compiler-rt/test/asan/TestCases/Posix/coverage-module-unloaded.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index ca8e05f27fc5..f35c105964a3 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -525,6 +525,7 @@ def OpenCLUnsupportedRGBA: 
DiagGroup<"opencl-unsupported-rgba">;
 def UnderalignedExceptionObject : DiagGroup<"underaligned-exception-object">;
 def DeprecatedObjCIsaUsage : DiagGroup<"deprecated-objc-isa-usage">;
 def ExplicitInitializeCall : DiagGroup<"explicit-initialize-call">;
+def OrderedCompareFunctionPointers : 
DiagGroup<"ordered-compare-function-pointers">;
 def Packed : DiagGroup<"packed">;
 def Padded : DiagGroup<"padded">;
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b114cdff1d94..b5b8bc6aa3c5 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6794,9 +6794,14 @@ def ext_typecheck_compare_complete_incomplete_pointers : 
Extension<
   "%0 is %select{|in}2complete and "
   "%1 is %select{|in}3complete">,
   InGroup;
+def warn_typecheck_ordered_comparison_of_function_pointers : Warning<
+  "ordered comparison of function pointers (%0 and %1)">,
+  InGroup;
 def ext_typecheck_ordered_comparison_of_function_pointers : ExtWarn<
   "ordered comparison of function pointers (%0 and %1)">,
-  InGroup>;
+  InGroup;
+def err_typecheck_ordered_comparison_of_function_pointers : Error<
+  "ordered comparison of function pointers (%0 and %1)">;
 def ext_typecheck_comparison_of_fptr_to_void : Extension<
   "equality comparison between function pointer and void pointer (%0 and %1)">;
 def err_typecheck_comparison_of_fptr_to_void : Error<
@@ -9143,9 +9148,6 @@ def 
note_defaulted_comparison_cannot_deduce_undeduced_auto : Note<
   "%select{|member|base class}0 %1 declared here">;
 def note_defaulted_comparison_cannot_deduce_callee : Note<
   "selected 'operator<=>' for %select{|member|base class}0 %1 declared here">;
-def note_defaulted_comparison_selected_invalid : Note<
-  "would compare %select{|member|base class}0 %1 "
-  "as %2, which does not support relational comparisons">;
 def err_incorrect_defaulted_comparison_constexpr : Error<
   "defaulted definition of %select{%sub{select_defaulted_comparison_kind}1|"
   "three-way comparison operator}0 "

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index a68a06eb4d27..83c97626ff7e 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7869,15 +7869,6 

[PATCH] D104892: [clang] Stop providing builtin overload candidate for relational function pointer comparisons

2021-06-25 Thread Matheus Izvekov 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 rGad14b5b008e2: [clang] Stop providing builtin overload 
candidate for relational function… (authored by mizvekov).

Changed prior to commit:
  https://reviews.llvm.org/D104892?vs=354607=354612#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104892

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/class/class.compare/class.spaceship/p2.cpp
  clang/test/CXX/drs/dr15xx.cpp
  clang/test/CXX/drs/dr3xx.cpp
  clang/test/CXX/expr/expr.const/p2-0x.cpp
  clang/test/FixIt/fixit.cpp
  clang/test/Parser/cxx-template-argument.cpp
  clang/test/Sema/compare.c
  clang/test/SemaCXX/compare-cxx2a.cpp
  clang/test/SemaCXX/compare-function-pointer.cpp
  clang/test/SemaTemplate/resolve-single-template-id.cpp
  compiler-rt/test/asan/TestCases/Posix/coverage-module-unloaded.cpp

Index: compiler-rt/test/asan/TestCases/Posix/coverage-module-unloaded.cpp
===
--- compiler-rt/test/asan/TestCases/Posix/coverage-module-unloaded.cpp
+++ compiler-rt/test/asan/TestCases/Posix/coverage-module-unloaded.cpp
@@ -13,6 +13,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -38,10 +39,11 @@
 
   // It matters whether the unloaded module has a higher or lower address range
   // than the remaining one. Make sure to test both cases.
+  bool lt = reinterpret_cast(bar1) < reinterpret_cast(bar2);
   if (argc < 2)
-dlclose(bar1 < bar2 ? handle1 : handle2);
+dlclose(lt ? handle1 : handle2);
   else
-dlclose(bar1 < bar2 ? handle2 : handle1);
+dlclose(lt ? handle2 : handle1);
   return 0;
 }
 #endif
Index: clang/test/SemaTemplate/resolve-single-template-id.cpp
===
--- clang/test/SemaTemplate/resolve-single-template-id.cpp
+++ clang/test/SemaTemplate/resolve-single-template-id.cpp
@@ -65,12 +65,14 @@
   void (*u)(int) = oneT;
 
   b = (void (*)()) twoT;
-  
-  one < one; //expected-warning {{self-comparison always evaluates to false}} \
- //expected-warning {{relational comparison result unused}} 
 
-  oneT < oneT;  //expected-warning {{self-comparison always evaluates to false}} \
-  //expected-warning {{relational comparison result unused}}
+  one < one; // expected-warning {{self-comparison always evaluates to false}} \
+ // expected-warning {{relational comparison result unused}}   \
+ // expected-warning {{ordered comparison of function pointers}}
+
+  oneT < oneT; // expected-warning {{self-comparison always evaluates to false}} \
+ // expected-warning {{relational comparison result unused}}   \
+ // expected-warning {{ordered comparison of function pointers}}
 
   two < two; //expected-error 2 {{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} expected-error {{invalid operands to binary expression ('void' and 'void')}}
   twoT < twoT; //expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} {{cannot resolve overloaded function 'twoT' from context}}
Index: clang/test/SemaCXX/compare-function-pointer.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/compare-function-pointer.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+
+using fp0_t = void (*)();
+using fp1_t = int (*)();
+
+extern fp0_t a, b;
+extern fp1_t c;
+
+bool eq0 = a == b;
+bool ne0 = a != b;
+bool lt0 = a < b;   // expected-warning {{ordered comparison of function pointers ('fp0_t' (aka 'void (*)()') and 'fp0_t')}}
+bool le0 = a <= b;  // expected-warning {{ordered comparison of function pointers}}
+bool gt0 = a > b;   // expected-warning {{ordered comparison of function pointers}}
+bool ge0 = a >= b;  // expected-warning {{ordered comparison of function pointers}}
+auto tw0 = a <=> b; // expected-error {{ordered comparison of function pointers}}
+
+bool eq1 = a == c;  // expected-error {{comparison of distinct pointer types}}
+bool ne1 = a != c;  // expected-error {{comparison of distinct pointer types}}
+bool lt1 = a < c;   // expected-warning {{ordered comparison of function pointers ('fp0_t' (aka 'void (*)()') and 'fp1_t' (aka 'int (*)()'))}}
+// expected-error@-1 {{comparison of distinct pointer types}}
+bool le1 = a <= c;  // expected-warning {{ordered comparison of function pointers}}
+// expected-error@-1 {{comparison of distinct pointer types}}
+bool gt1 = a > c;   // 

[PATCH] D104892: [clang] Stop providing builtin overload candidate for relational function pointer comparisons

2021-06-25 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 354607.
mizvekov added a comment.

- Restore tests.
- Reimplement fixit in terms of variable template (needs -Wno-c++14-extensions).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104892

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/class/class.compare/class.spaceship/p2.cpp
  clang/test/CXX/drs/dr15xx.cpp
  clang/test/CXX/drs/dr3xx.cpp
  clang/test/CXX/expr/expr.const/p2-0x.cpp
  clang/test/FixIt/fixit.cpp
  clang/test/Parser/cxx-template-argument.cpp
  clang/test/Sema/compare.c
  clang/test/SemaCXX/compare-cxx2a.cpp
  clang/test/SemaCXX/compare-function-pointer.cpp
  clang/test/SemaTemplate/resolve-single-template-id.cpp
  compiler-rt/test/asan/TestCases/Posix/coverage-module-unloaded.cpp

Index: compiler-rt/test/asan/TestCases/Posix/coverage-module-unloaded.cpp
===
--- compiler-rt/test/asan/TestCases/Posix/coverage-module-unloaded.cpp
+++ compiler-rt/test/asan/TestCases/Posix/coverage-module-unloaded.cpp
@@ -13,6 +13,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -38,10 +39,11 @@
 
   // It matters whether the unloaded module has a higher or lower address range
   // than the remaining one. Make sure to test both cases.
+  bool lt = reinterpret_cast(bar1) < reinterpret_cast(bar2);
   if (argc < 2)
-dlclose(bar1 < bar2 ? handle1 : handle2);
+dlclose(lt ? handle1 : handle2);
   else
-dlclose(bar1 < bar2 ? handle2 : handle1);
+dlclose(lt ? handle2 : handle1);
   return 0;
 }
 #endif
Index: clang/test/SemaTemplate/resolve-single-template-id.cpp
===
--- clang/test/SemaTemplate/resolve-single-template-id.cpp
+++ clang/test/SemaTemplate/resolve-single-template-id.cpp
@@ -65,12 +65,14 @@
   void (*u)(int) = oneT;
 
   b = (void (*)()) twoT;
-  
-  one < one; //expected-warning {{self-comparison always evaluates to false}} \
- //expected-warning {{relational comparison result unused}} 
 
-  oneT < oneT;  //expected-warning {{self-comparison always evaluates to false}} \
-  //expected-warning {{relational comparison result unused}}
+  one < one; // expected-warning {{self-comparison always evaluates to false}} \
+ // expected-warning {{relational comparison result unused}}   \
+ // expected-warning {{ordered comparison of function pointers}}
+
+  oneT < oneT; // expected-warning {{self-comparison always evaluates to false}} \
+ // expected-warning {{relational comparison result unused}}   \
+ // expected-warning {{ordered comparison of function pointers}}
 
   two < two; //expected-error 2 {{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} expected-error {{invalid operands to binary expression ('void' and 'void')}}
   twoT < twoT; //expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} {{cannot resolve overloaded function 'twoT' from context}}
Index: clang/test/SemaCXX/compare-function-pointer.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/compare-function-pointer.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+
+using fp0_t = void (*)();
+using fp1_t = int (*)();
+
+extern fp0_t a, b;
+extern fp1_t c;
+
+bool eq0 = a == b;
+bool ne0 = a != b;
+bool lt0 = a < b;   // expected-warning {{ordered comparison of function pointers ('fp0_t' (aka 'void (*)()') and 'fp0_t')}}
+bool le0 = a <= b;  // expected-warning {{ordered comparison of function pointers}}
+bool gt0 = a > b;   // expected-warning {{ordered comparison of function pointers}}
+bool ge0 = a >= b;  // expected-warning {{ordered comparison of function pointers}}
+auto tw0 = a <=> b; // expected-error {{ordered comparison of function pointers}}
+
+bool eq1 = a == c;  // expected-error {{comparison of distinct pointer types}}
+bool ne1 = a != c;  // expected-error {{comparison of distinct pointer types}}
+bool lt1 = a < c;   // expected-warning {{ordered comparison of function pointers ('fp0_t' (aka 'void (*)()') and 'fp1_t' (aka 'int (*)()'))}}
+// expected-error@-1 {{comparison of distinct pointer types}}
+bool le1 = a <= c;  // expected-warning {{ordered comparison of function pointers}}
+// expected-error@-1 {{comparison of distinct pointer types}}
+bool gt1 = a > c;   // expected-warning {{ordered comparison of function pointers}}
+// expected-error@-1 {{comparison of distinct pointer types}}
+bool ge1 = a >= c;  // 

[PATCH] D104952: [hexagon] Add {hvx,}hexagon_{protos,circ_brev...}

2021-06-25 Thread Brian Cain via Phabricator via cfe-commits
bcain created this revision.
bcain added a reviewer: kparzysz.
Herald added a subscriber: mgorny.
bcain requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add definitions for Hexagon, Hexagon circular/bit-reverse and HVX
intrinsics.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104952

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/hexagon_circ_brev_intrinsics.h
  clang/lib/Headers/hexagon_protos.h
  clang/lib/Headers/hvx_hexagon_protos.h
  clang/test/Headers/hexagon-headers.c
  clang/test/Headers/hexagon-hvx-headers.c

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


[PATCH] D104892: [clang] Stop providing builtin overload candidate for relational function pointer comparisons

2021-06-25 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

A couple of comments on test coverage but otherwise this looks great, thanks! 
It'll be instructive to see if people ask for the warning to not be on by 
default...




Comment at: clang/test/CXX/expr/expr.const/p2-0x.cpp:517
   constexpr void (*pf)() = , (*pg)() = 
-  constexpr bool u13 = pf < pg; // expected-error {{constant expression}} 
expected-note {{comparison has unspecified value}}
-  constexpr bool u14 = pf == pg;

Can you undo this change now? We should retain some test coverage ensuring that 
we fail constant evaluation in this case.



Comment at: clang/test/FixIt/fixit.cpp:298-303
 (void)(==p); // expected-error {{use '> ='}}
-(void)(>=p); // expected-error {{use '> >'}}
 #if __cplusplus < 201103L
-(void)(>>=p); // expected-error {{use '> >'}}
 (Shr)>>>=p; // expected-error {{use '> >'}}
 #endif

We should retain some test coverage that we produce a proper fixit when 
splitting `>>=` into `>` `>=`. If you want to move this test away from function 
pointer comparison, we can test the same thing with variable templates these 
days.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104892

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


[PATCH] D104892: [clang] Stop providing builtin overload candidate for relational function pointer comparisons

2021-06-25 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 354595.
mizvekov added a comment.

- Make it a regular warning.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104892

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/class/class.compare/class.spaceship/p2.cpp
  clang/test/CXX/drs/dr15xx.cpp
  clang/test/CXX/drs/dr3xx.cpp
  clang/test/CXX/expr/expr.const/p2-0x.cpp
  clang/test/FixIt/fixit.cpp
  clang/test/Parser/cxx-template-argument.cpp
  clang/test/Sema/compare.c
  clang/test/SemaCXX/compare-cxx2a.cpp
  clang/test/SemaCXX/compare-function-pointer.cpp
  clang/test/SemaTemplate/resolve-single-template-id.cpp
  compiler-rt/test/asan/TestCases/Posix/coverage-module-unloaded.cpp

Index: compiler-rt/test/asan/TestCases/Posix/coverage-module-unloaded.cpp
===
--- compiler-rt/test/asan/TestCases/Posix/coverage-module-unloaded.cpp
+++ compiler-rt/test/asan/TestCases/Posix/coverage-module-unloaded.cpp
@@ -13,6 +13,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -38,10 +39,11 @@
 
   // It matters whether the unloaded module has a higher or lower address range
   // than the remaining one. Make sure to test both cases.
+  bool lt = reinterpret_cast(bar1) < reinterpret_cast(bar2);
   if (argc < 2)
-dlclose(bar1 < bar2 ? handle1 : handle2);
+dlclose(lt ? handle1 : handle2);
   else
-dlclose(bar1 < bar2 ? handle2 : handle1);
+dlclose(lt ? handle2 : handle1);
   return 0;
 }
 #endif
Index: clang/test/SemaTemplate/resolve-single-template-id.cpp
===
--- clang/test/SemaTemplate/resolve-single-template-id.cpp
+++ clang/test/SemaTemplate/resolve-single-template-id.cpp
@@ -65,12 +65,14 @@
   void (*u)(int) = oneT;
 
   b = (void (*)()) twoT;
-  
-  one < one; //expected-warning {{self-comparison always evaluates to false}} \
- //expected-warning {{relational comparison result unused}} 
 
-  oneT < oneT;  //expected-warning {{self-comparison always evaluates to false}} \
-  //expected-warning {{relational comparison result unused}}
+  one < one; // expected-warning {{self-comparison always evaluates to false}} \
+ // expected-warning {{relational comparison result unused}}   \
+ // expected-warning {{ordered comparison of function pointers}}
+
+  oneT < oneT; // expected-warning {{self-comparison always evaluates to false}} \
+ // expected-warning {{relational comparison result unused}}   \
+ // expected-warning {{ordered comparison of function pointers}}
 
   two < two; //expected-error 2 {{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} expected-error {{invalid operands to binary expression ('void' and 'void')}}
   twoT < twoT; //expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} {{cannot resolve overloaded function 'twoT' from context}}
Index: clang/test/SemaCXX/compare-function-pointer.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/compare-function-pointer.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+
+using fp0_t = void (*)();
+using fp1_t = int (*)();
+
+extern fp0_t a, b;
+extern fp1_t c;
+
+bool eq0 = a == b;
+bool ne0 = a != b;
+bool lt0 = a < b;   // expected-warning {{ordered comparison of function pointers ('fp0_t' (aka 'void (*)()') and 'fp0_t')}}
+bool le0 = a <= b;  // expected-warning {{ordered comparison of function pointers}}
+bool gt0 = a > b;   // expected-warning {{ordered comparison of function pointers}}
+bool ge0 = a >= b;  // expected-warning {{ordered comparison of function pointers}}
+auto tw0 = a <=> b; // expected-error {{ordered comparison of function pointers}}
+
+bool eq1 = a == c;  // expected-error {{comparison of distinct pointer types}}
+bool ne1 = a != c;  // expected-error {{comparison of distinct pointer types}}
+bool lt1 = a < c;   // expected-warning {{ordered comparison of function pointers ('fp0_t' (aka 'void (*)()') and 'fp1_t' (aka 'int (*)()'))}}
+// expected-error@-1 {{comparison of distinct pointer types}}
+bool le1 = a <= c;  // expected-warning {{ordered comparison of function pointers}}
+// expected-error@-1 {{comparison of distinct pointer types}}
+bool gt1 = a > c;   // expected-warning {{ordered comparison of function pointers}}
+// expected-error@-1 {{comparison of distinct pointer types}}
+bool ge1 = a >= c;  // expected-warning {{ordered comparison of function pointers}}
+// 

[PATCH] D102361: [OpenMP] Add Module metadata for OpenMP compilation

2021-06-25 Thread Joseph Huber 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 rG9ce02ea8c941: [OpenMP] Add Module metadata for OpenMP 
compilation (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102361

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/OpenMP/cancel_codegen.cpp
  clang/test/OpenMP/cancellation_point_codegen.cpp
  clang/test/OpenMP/distribute_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_reduction_task_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/distribute_simd_codegen.cpp
  clang/test/OpenMP/for_reduction_codegen_UDR.cpp
  clang/test/OpenMP/for_reduction_task_codegen.cpp
  clang/test/OpenMP/master_taskloop_in_reduction_codegen.cpp
  clang/test/OpenMP/master_taskloop_simd_in_reduction_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
  clang/test/OpenMP/ordered_codegen.cpp
  clang/test/OpenMP/parallel_for_codegen.cpp
  clang/test/OpenMP/parallel_for_reduction_task_codegen.cpp
  clang/test/OpenMP/parallel_master_reduction_task_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_lastprivate_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_simd_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/parallel_reduction_task_codegen.cpp
  clang/test/OpenMP/parallel_sections_reduction_task_codegen.cpp
  clang/test/OpenMP/sections_reduction_task_codegen.cpp
  clang/test/OpenMP/target_parallel_codegen.cpp
  clang/test/OpenMP/target_parallel_for_codegen.cpp
  clang/test/OpenMP/target_parallel_for_reduction_task_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/target_parallel_reduction_task_codegen.cpp
  clang/test/OpenMP/target_teams_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_dist_schedule_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_order_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_reduction_task_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_schedule_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_simd_if_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_schedule_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_dist_schedule_codegen.cpp
  clang/test/OpenMP/task_codegen.cpp
  clang/test/OpenMP/task_if_codegen.cpp
  clang/test/OpenMP/task_in_reduction_codegen.cpp
  clang/test/OpenMP/taskloop_in_reduction_codegen.cpp
  clang/test/OpenMP/taskloop_simd_in_reduction_codegen.cpp
  clang/test/OpenMP/teams_distribute_dist_schedule_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_reduction_task_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_schedule_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_schedule_codegen.cpp
  clang/test/OpenMP/teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/teams_distribute_simd_dist_schedule_codegen.cpp

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


[PATCH] D104946: [AMDGPU] Add builtin functions image_bvh_intersect_ray

2021-06-25 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsAMDGPU.def:221-224
+TARGET_BUILTIN(__builtin_amdgcn_image_bvh_intersect_ray, 
"V4UiUifV4fV4fV4fV4Ui", "nc", "gfx10-insts")
+TARGET_BUILTIN(__builtin_amdgcn_image_bvh_intersect_ray_h, 
"V4UiUifV4fV4hV4hV4Ui", "nc", "gfx10-insts")
+TARGET_BUILTIN(__builtin_amdgcn_image_bvh_intersect_ray_l, 
"V4UiWUifV4fV4fV4fV4Ui", "nc", "gfx10-insts")
+TARGET_BUILTIN(__builtin_amdgcn_image_bvh_intersect_ray_lh, 
"V4UiWUifV4fV4hV4hV4Ui", "nc", "gfx10-insts")

The intrinsic signature suggests the 1st and 4th/5th arguments are 
overloadable. How does this handle the various supported types?


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

https://reviews.llvm.org/D104946

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


[PATCH] D104716: [analyzer] Fix assertion failure on code with transparent unions

2021-06-25 Thread Valeriy Savchenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd646157146cc: [analyzer] Fix assertion failure on code with 
transparent unions (authored by vsavchenko).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104716

Files:
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/test/Analysis/transparent_union_bug.c

Index: clang/test/Analysis/transparent_union_bug.c
===
--- /dev/null
+++ clang/test/Analysis/transparent_union_bug.c
@@ -0,0 +1,40 @@
+// RUN: %clang_analyze_cc1 -analyze -triple x86_64-apple-darwin10 \
+// RUN:  -analyzer-checker=core,debug.ExprInspection -verify %s
+
+void clang_analyzer_warnIfReached();
+
+typedef struct {
+  int value;
+} Struct;
+
+typedef union {
+  Struct *ptr;
+  long num;
+} __attribute__((transparent_union)) Alias;
+
+void foo(Struct *x);
+void foo(Alias y) {
+  if (y.ptr == 0) {
+// no-crash
+  }
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+void foobar(long z);
+void foobar(Alias z) {
+  if (z.num != 42) {
+// no-crash
+  }
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+
+void foobaz(Alias x) {
+  if (x.ptr == 0) {
+// no-crash
+  }
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+void bar(Struct arg) {
+  foo();
+  foobar(42);
+  foobaz();
+}
Index: clang/lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -47,6 +47,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/ImmutableList.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/PointerIntPair.h"
@@ -466,6 +467,42 @@
   llvm_unreachable("unknown callable kind");
 }
 
+static bool isTransparentUnion(QualType T) {
+  const RecordType *UT = T->getAsUnionType();
+  return UT && UT->getDecl()->hasAttr();
+}
+
+// In some cases, symbolic cases should be transformed before we associate
+// them with parameters.  This function incapsulates such cases.
+static SVal processArgument(SVal Value, const Expr *ArgumentExpr,
+const ParmVarDecl *Parameter, SValBuilder ) {
+  QualType ParamType = Parameter->getType();
+  QualType ArgumentType = ArgumentExpr->getType();
+
+  // Transparent unions allow users to easily convert values of union field
+  // types into union-typed objects.
+  //
+  // Also, more importantly, they allow users to define functions with different
+  // different parameter types, substituting types matching transparent union
+  // field types with the union type itself.
+  //
+  // Here, we check specifically for latter cases and prevent binding
+  // field-typed values to union-typed regions.
+  if (isTransparentUnion(ParamType) &&
+  // Let's check that we indeed trying to bind different types.
+  !isTransparentUnion(ArgumentType)) {
+BasicValueFactory  = SVB.getBasicValueFactory();
+
+llvm::ImmutableList CompoundSVals = BVF.getEmptySValList();
+CompoundSVals = BVF.prependSVal(Value, CompoundSVals);
+
+// Wrap it with compound value.
+return SVB.makeCompoundVal(ParamType, CompoundSVals);
+  }
+
+  return Value;
+}
+
 static void addParameterValuesToBindings(const StackFrameContext *CalleeCtx,
  CallEvent::BindingsTy ,
  SValBuilder ,
@@ -490,10 +527,12 @@
 // determined in compile-time but not represented as arg-expressions,
 // which makes getArgSVal() fail and return UnknownVal.
 SVal ArgVal = Call.getArgSVal(Idx);
+const Expr *ArgExpr = Call.getArgExpr(Idx);
 if (!ArgVal.isUnknown()) {
   Loc ParamLoc = SVB.makeLoc(
   MRMgr.getParamVarRegion(Call.getOriginExpr(), Idx, CalleeCtx));
-  Bindings.push_back(std::make_pair(ParamLoc, ArgVal));
+  Bindings.push_back(
+  std::make_pair(ParamLoc, processArgument(ArgVal, ArgExpr, *I, SVB)));
 }
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d646157 - [analyzer] Fix assertion failure on code with transparent unions

2021-06-25 Thread Valeriy Savchenko via cfe-commits

Author: Valeriy Savchenko
Date: 2021-06-25T23:09:16+03:00
New Revision: d646157146ccda93cd72dcbaff4a554c61ed9586

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

LOG: [analyzer] Fix assertion failure on code with transparent unions

rdar://76948312

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

Added: 
clang/test/Analysis/transparent_union_bug.c

Modified: 
clang/lib/StaticAnalyzer/Core/CallEvent.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp 
b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
index ecf1d1b5f0688..3785f498414f9 100644
--- a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -47,6 +47,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/ImmutableList.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/PointerIntPair.h"
@@ -466,6 +467,42 @@ bool CallEvent::isVariadic(const Decl *D) {
   llvm_unreachable("unknown callable kind");
 }
 
+static bool isTransparentUnion(QualType T) {
+  const RecordType *UT = T->getAsUnionType();
+  return UT && UT->getDecl()->hasAttr();
+}
+
+// In some cases, symbolic cases should be transformed before we associate
+// them with parameters.  This function incapsulates such cases.
+static SVal processArgument(SVal Value, const Expr *ArgumentExpr,
+const ParmVarDecl *Parameter, SValBuilder ) {
+  QualType ParamType = Parameter->getType();
+  QualType ArgumentType = ArgumentExpr->getType();
+
+  // Transparent unions allow users to easily convert values of union field
+  // types into union-typed objects.
+  //
+  // Also, more importantly, they allow users to define functions with 
diff erent
+  // 
diff erent parameter types, substituting types matching transparent union
+  // field types with the union type itself.
+  //
+  // Here, we check specifically for latter cases and prevent binding
+  // field-typed values to union-typed regions.
+  if (isTransparentUnion(ParamType) &&
+  // Let's check that we indeed trying to bind 
diff erent types.
+  !isTransparentUnion(ArgumentType)) {
+BasicValueFactory  = SVB.getBasicValueFactory();
+
+llvm::ImmutableList CompoundSVals = BVF.getEmptySValList();
+CompoundSVals = BVF.prependSVal(Value, CompoundSVals);
+
+// Wrap it with compound value.
+return SVB.makeCompoundVal(ParamType, CompoundSVals);
+  }
+
+  return Value;
+}
+
 static void addParameterValuesToBindings(const StackFrameContext *CalleeCtx,
  CallEvent::BindingsTy ,
  SValBuilder ,
@@ -490,10 +527,12 @@ static void addParameterValuesToBindings(const 
StackFrameContext *CalleeCtx,
 // determined in compile-time but not represented as arg-expressions,
 // which makes getArgSVal() fail and return UnknownVal.
 SVal ArgVal = Call.getArgSVal(Idx);
+const Expr *ArgExpr = Call.getArgExpr(Idx);
 if (!ArgVal.isUnknown()) {
   Loc ParamLoc = SVB.makeLoc(
   MRMgr.getParamVarRegion(Call.getOriginExpr(), Idx, CalleeCtx));
-  Bindings.push_back(std::make_pair(ParamLoc, ArgVal));
+  Bindings.push_back(
+  std::make_pair(ParamLoc, processArgument(ArgVal, ArgExpr, *I, SVB)));
 }
   }
 

diff  --git a/clang/test/Analysis/transparent_union_bug.c 
b/clang/test/Analysis/transparent_union_bug.c
new file mode 100644
index 0..b6069c6a59b19
--- /dev/null
+++ b/clang/test/Analysis/transparent_union_bug.c
@@ -0,0 +1,40 @@
+// RUN: %clang_analyze_cc1 -analyze -triple x86_64-apple-darwin10 \
+// RUN:  -analyzer-checker=core,debug.ExprInspection -verify %s
+
+void clang_analyzer_warnIfReached();
+
+typedef struct {
+  int value;
+} Struct;
+
+typedef union {
+  Struct *ptr;
+  long num;
+} __attribute__((transparent_union)) Alias;
+
+void foo(Struct *x);
+void foo(Alias y) {
+  if (y.ptr == 0) {
+// no-crash
+  }
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+void foobar(long z);
+void foobar(Alias z) {
+  if (z.num != 42) {
+// no-crash
+  }
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+
+void foobaz(Alias x) {
+  if (x.ptr == 0) {
+// no-crash
+  }
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+void bar(Struct arg) {
+  foo();
+  foobar(42);
+  foobaz();
+}



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


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

2021-06-25 Thread Chris Hamilton via Phabricator via cfe-commits
chrish_ericsson_atx added a comment.

While this patch resolves the issue captured in 
https://bugs.llvm.org/show_bug.cgi?id=50604, it actually introduces a *new* 
bug.  Perhaps this is what you were alluding to?  Here's a reproducer which 
doesn't fail on main (with or without the problematic b30521c28a4d 
 commit), 
but it *does* fail with this proposed patch:

  eahcmrh@seroius03977[21:50][repo/eahcmrh/ltebb]$ cat ~/pr50604-newbug.c 
  static float const dt[12] =
  {
0., 0.0235, 0.0470, 0.0706, 0.0941, 0.1176,
0.1411, 0.1646, 0.1881, 0.2117, 0.2352, 0.2587
  };
  void foo(float s)
  {
(void)( s + dt[0]) ;
  }
  eahcmrh@seroius03977[21:57][repo/eahcmrh/ltebb]$ 
/proj/bbi/eahcmrh/arcpatch-D104285/compiler-clang/bin/clang -Xanalyzer 
-analyzer-werror --analyze ~/pr50604-newbug.c 
  /home/eahcmrh/pr50604-newbug.c:8:13: error: The right operand of '+' is a 
garbage value [core.UndefinedBinaryOperatorResult]
(void)( s + dt[0]) ;
  ^ ~
  1 error generated.

I'll upload this reproducer to the bug report as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104285

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


[PATCH] D104946: [AMDGPU] Add builtin functions image_bvh_intersect_ray

2021-06-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: arsenm, b-sumner, rampitec.
Herald added subscribers: kerbowa, t-tye, tpr, dstuttard, nhaehnle, jvesely, 
kzhuravl.
yaxunl requested review of this revision.
Herald added a subscriber: wdng.

https://reviews.llvm.org/D104946

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGenOpenCL/builtins-amdgcn-raytracing.cl


Index: clang/test/CodeGenOpenCL/builtins-amdgcn-raytracing.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/builtins-amdgcn-raytracing.cl
@@ -0,0 +1,46 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx1030 -S \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+
+typedef unsigned int uint;
+typedef unsigned long ulong;
+typedef float float4 __attribute__((ext_vector_type(4)));
+typedef half half4 __attribute__((ext_vector_type(4)));
+typedef uint uint4 __attribute__((ext_vector_type(4)));
+
+// CHECK: call <4 x i32> @llvm.amdgcn.image.bvh.intersect.ray.i32.v4f32
+void test_image_bvh_intersect_ray(global uint4* out, uint node_ptr,
+  float ray_extent, float4 ray_origin, float4 ray_dir, float4 ray_inv_dir,
+  uint4 texture_descr)
+{
+  *out = __builtin_amdgcn_image_bvh_intersect_ray(node_ptr, ray_extent,
+   ray_origin, ray_dir, ray_inv_dir, texture_descr);
+}
+
+// CHECK: call <4 x i32> @llvm.amdgcn.image.bvh.intersect.ray.i32.v4f16
+void test_image_bvh_intersect_ray_h(global uint4* out, uint node_ptr,
+  float ray_extent, float4 ray_origin, half4 ray_dir, half4 ray_inv_dir,
+  uint4 texture_descr)
+{
+  *out = __builtin_amdgcn_image_bvh_intersect_ray_h(node_ptr, ray_extent,
+   ray_origin, ray_dir, ray_inv_dir, texture_descr);
+}
+
+// CHECK: call <4 x i32> @llvm.amdgcn.image.bvh.intersect.ray.i64.v4f32
+void test_image_bvh_intersect_ray_l(global uint4* out, ulong node_ptr,
+  float ray_extent, float4 ray_origin, float4 ray_dir, float4 ray_inv_dir,
+  uint4 texture_descr)
+{
+  *out = __builtin_amdgcn_image_bvh_intersect_ray_l(node_ptr, ray_extent,
+   ray_origin, ray_dir, ray_inv_dir, texture_descr);
+}
+
+// CHECK: call <4 x i32> @llvm.amdgcn.image.bvh.intersect.ray.i64.v4f16
+void test_image_bvh_intersect_ray_lh(global uint4* out, ulong node_ptr,
+  float ray_extent, float4 ray_origin, half4 ray_dir, half4 ray_inv_dir,
+  uint4 texture_descr)
+{
+  *out = __builtin_amdgcn_image_bvh_intersect_ray_lh(node_ptr, ray_extent,
+   ray_origin, ray_dir, ray_inv_dir, texture_descr);
+}
+
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -15745,6 +15745,23 @@
 CI->setConvergent();
 return CI;
   }
+  case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray:
+  case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_h:
+  case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_l:
+  case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_lh: {
+llvm::Value *NodePtr = EmitScalarExpr(E->getArg(0));
+llvm::Value *RayExtent = EmitScalarExpr(E->getArg(1));
+llvm::Value *RayOrigin = EmitScalarExpr(E->getArg(2));
+llvm::Value *RayDir = EmitScalarExpr(E->getArg(3));
+llvm::Value *RayInverseDir = EmitScalarExpr(E->getArg(4));
+llvm::Value *TextureDescr = EmitScalarExpr(E->getArg(5));
+
+Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_image_bvh_intersect_ray,
+   {NodePtr->getType(), RayDir->getType()});
+return Builder.CreateCall(F, {NodePtr, RayExtent, RayOrigin, RayDir,
+  RayInverseDir, TextureDescr});
+  }
+
   // amdgcn workitem
   case AMDGPU::BI__builtin_amdgcn_workitem_id_x:
 return emitRangedBuiltin(*this, Intrinsic::amdgcn_workitem_id_x, 0, 1024);
Index: clang/include/clang/Basic/BuiltinsAMDGPU.def
===
--- clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -215,6 +215,14 @@
 TARGET_BUILTIN(__builtin_amdgcn_permlanex16, "UiUiUiUiUiIbIb", "nc", 
"gfx10-insts")
 TARGET_BUILTIN(__builtin_amdgcn_mov_dpp8, "UiUiIUi", "nc", "gfx10-insts")
 
+//===--===//
+// Raytracing builtins.
+//===--===//
+TARGET_BUILTIN(__builtin_amdgcn_image_bvh_intersect_ray, 
"V4UiUifV4fV4fV4fV4Ui", "nc", "gfx10-insts")
+TARGET_BUILTIN(__builtin_amdgcn_image_bvh_intersect_ray_h, 
"V4UiUifV4fV4hV4hV4Ui", "nc", "gfx10-insts")
+TARGET_BUILTIN(__builtin_amdgcn_image_bvh_intersect_ray_l, 
"V4UiWUifV4fV4fV4fV4Ui", "nc", "gfx10-insts")
+TARGET_BUILTIN(__builtin_amdgcn_image_bvh_intersect_ray_lh, 
"V4UiWUifV4fV4hV4hV4Ui", "nc", "gfx10-insts")
+
 

[PATCH] D81886: [AMDGPU] Add gfx1030 target

2021-06-25 Thread Stanislav Mekhanoshin via Phabricator via cfe-commits
rampitec added inline comments.



Comment at: llvm/lib/Target/AMDGPU/AMDGPU.td:1245
+
+def HasDsSrc2Insts : Predicate<"!Subtarget->hasDsSrc2Insts()">,
+  AssemblerPredicate<(all_of FeatureDsSrc2Insts)>;

foad wrote:
> The `!` is obviously wrong in this definition, but if I remove it, all the 
> tests still pass. So does this predicate actually control anything?
We don't select these, so only AssemblerPredicate is actually used. This is an 
obvious typo to fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81886

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


[PATCH] D104854: Introduce intrinsic llvm.isnan

2021-06-25 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

A few of the AArch64 sequences don't look ideal, but that's not the fault of 
your patch.

I'd like to see some test coverage for all the floating-point types (half, 
bfloat16, ppc_fp128).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104854

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


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

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

In D104714#2841457 , @thakis wrote:

> Another thing: https://reviews.llvm.org/harbormaster/unit/view/789318/
>
>   # command stderr:
>   
> /var/lib/buildkite-agent/builds/llvm-project/clang/test/utils/update_cc_test_checks/check-globals.test:83:10:
>  error: LIT-RUN: expected string not found in input
>   LIT-RUN: PASS: {{.*}} norm.c
>   
>   Input was:
>   <<
>   1: lit.py: 
> /var/lib/buildkite-agent/builds/llvm-project/llvm/utils/lit/lit/llvm/config.py:436:
>  note: using clang: 
> /var/lib/buildkite-agent/builds/llvm-project/build/bin/clang 
>   2: -- Testing: 2 tests, 1 workers -- 
>   3: PASS: update_cc_test_checks.py example :: norm.c (1 of 2) 
>   4: PASS: update_cc_test_checks.py example :: igf.c (2 of 2) 
>
> Looks like the test expects order igf.c, norm.c while the output is the other 
> way round. Should this just use `LIT-RUN-DAG` so that the order doesn't 
> matter, or should we add a `sorted()` somewhere that the output is 
> deterministic?

I pushed cc60fa2685bd 
 to fix 
that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104714

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


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

2021-06-25 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Another thing: https://reviews.llvm.org/harbormaster/unit/view/789318/

  # command stderr:
  
/var/lib/buildkite-agent/builds/llvm-project/clang/test/utils/update_cc_test_checks/check-globals.test:83:10:
 error: LIT-RUN: expected string not found in input
  LIT-RUN: PASS: {{.*}} norm.c
  
  Input was:
  <<
  1: lit.py: 
/var/lib/buildkite-agent/builds/llvm-project/llvm/utils/lit/lit/llvm/config.py:436:
 note: using clang: 
/var/lib/buildkite-agent/builds/llvm-project/build/bin/clang 
  2: -- Testing: 2 tests, 1 workers -- 
  3: PASS: update_cc_test_checks.py example :: norm.c (1 of 2) 
  4: PASS: update_cc_test_checks.py example :: igf.c (2 of 2) 

Looks like the test expects order igf.c, norm.c while the output is the other 
way round. Should this just use `LIT-RUN-DAG` so that the order doesn't matter, 
or should we add a `sorted()` somewhere that the output is deterministic?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104714

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


[PATCH] D104854: Introduce intrinsic llvm.isnan

2021-06-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/X86/X86ISelLowering.cpp:22039
+  // Move FPSW to AX.
+  SDValue FPSW = DAG.getCopyToReg(DAG.getEntryNode(), DL, X86::FPSW, Test,
+  SDValue());

The code you copied this form was overly complicated. You can output Glue 
instead of MVT::i16 from XAM node and then pass that directly to FNSTSW16r in 
place of `FPSW, FPSW.getValue(1)`.  I have made this change to 
X86ISelDAGToDAG.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104854

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


[clang] cc60fa2 - [UpdateCCTestChecks] Fix new test from 9eaf0d120d32

2021-06-25 Thread Joel E. Denny via cfe-commits

Author: Joel E. Denny
Date: 2021-06-25T14:29:58-04:00
New Revision: cc60fa2685bdbff889df826a1bfd5e52ffd163c8

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

LOG: [UpdateCCTestChecks] Fix new test from 9eaf0d120d32

`clang/test/utils/update_cc_test_checks/check-globals.test` from
9eaf0d120d32 broke at:

* 
* 

The problem is non-deterministic test order because the
`.lit_test_times.txt` from one run of a sample test suite affects the
other.

Added: 


Modified: 
clang/test/utils/update_cc_test_checks/check-globals.test

Removed: 




diff  --git a/clang/test/utils/update_cc_test_checks/check-globals.test 
b/clang/test/utils/update_cc_test_checks/check-globals.test
index 2af041b5ec7c..def1a8e93672 100644
--- a/clang/test/utils/update_cc_test_checks/check-globals.test
+++ b/clang/test/utils/update_cc_test_checks/check-globals.test
@@ -31,7 +31,8 @@ RUN: rm %t/igf-again.c
 RUN: cp %S/Inputs/lit.cfg.example %t/lit.cfg
 # Show lit failures while avoiding confusing FileCheck input dump nesting.
 RUN: %lit %t
-# Lit was successful.  Sanity-check the results.
+# Lit was successful.  Sanity-check the results with deterministic test order.
+RUN: rm %t/.lit_test_times.txt
 RUN: %lit %t 2>&1 | FileCheck -check-prefix=LIT-RUN %s
 
 END.



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


[PATCH] D104887: [clang] Evaluate strlen of strcpy argument for -Wfortify-source.

2021-06-25 Thread Michael Benfield via Phabricator via cfe-commits
mbenfield updated this revision to Diff 354563.
mbenfield added a comment.

Accommodate the fact that APSInt::toString(unsigned) was removed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104887

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Analysis/security-syntax-checks.m
  clang/test/Sema/warn-fortify-source.c

Index: clang/test/Sema/warn-fortify-source.c
===
--- clang/test/Sema/warn-fortify-source.c
+++ clang/test/Sema/warn-fortify-source.c
@@ -58,6 +58,12 @@
   __builtin_stpncpy(s1, s2, 20); // expected-warning {{'stpncpy' size argument is too large; destination buffer has size 10, but size argument is 20}}
 }
 
+void call_strcpy() {
+  const char *const src = "abcdef";
+  char dst[4];
+  __builtin_strcpy(dst, src); // expected-warning {{'strcpy' will always overflow; destination buffer has size 4, but the source string has length 7 (including null byte)}}
+}
+
 void call_memmove() {
   char s1[10], s2[20];
   __builtin_memmove(s2, s1, 20);
Index: clang/test/Analysis/security-syntax-checks.m
===
--- clang/test/Analysis/security-syntax-checks.m
+++ clang/test/Analysis/security-syntax-checks.m
@@ -1,37 +1,37 @@
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 %s -verify \
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 %s -verify -Wno-fortify-source \
 // RUN:   -analyzer-checker=security.insecureAPI \
 // RUN:   -analyzer-checker=security.FloatLoopCounter
 
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 %s -verify \
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 %s -verify -Wno-fortify-source \
 // RUN:   -DUSE_BUILTINS \
 // RUN:   -analyzer-checker=security.insecureAPI \
 // RUN:   -analyzer-checker=security.FloatLoopCounter
 
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 %s -verify \
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 %s -verify -Wno-fortify-source \
 // RUN:   -DVARIANT \
 // RUN:   -analyzer-checker=security.insecureAPI \
 // RUN:   -analyzer-checker=security.FloatLoopCounter
 
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 %s -verify \
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 %s -verify -Wno-fortify-source \
 // RUN:   -DUSE_BUILTINS -DVARIANT \
 // RUN:   -analyzer-checker=security.insecureAPI \
 // RUN:   -analyzer-checker=security.FloatLoopCounter
 
-// RUN: %clang_analyze_cc1 -triple x86_64-unknown-cloudabi %s -verify \
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-cloudabi %s -verify -Wno-fortify-source \
 // RUN:   -analyzer-checker=security.insecureAPI \
 // RUN:   -analyzer-checker=security.FloatLoopCounter
 
-// RUN: %clang_analyze_cc1 -triple x86_64-unknown-cloudabi %s -verify \
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-cloudabi %s -verify -Wno-fortify-source \
 // RUN:   -DUSE_BUILTINS \
 // RUN:   -analyzer-checker=security.insecureAPI \
 // RUN:   -analyzer-checker=security.FloatLoopCounter
 
-// RUN: %clang_analyze_cc1 -triple x86_64-unknown-cloudabi %s -verify \
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-cloudabi %s -verify -Wno-fortify-source \
 // RUN:   -DVARIANT \
 // RUN:   -analyzer-checker=security.insecureAPI \
 // RUN:   -analyzer-checker=security.FloatLoopCounter
 
-// RUN: %clang_analyze_cc1 -triple x86_64-unknown-cloudabi %s -verify \
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-cloudabi %s -verify -Wno-fortify-source \
 // RUN:   -DUSE_BUILTINS -DVARIANT \
 // RUN:   -analyzer-checker=security.insecureAPI \
 // RUN:   -analyzer-checker=security.FloatLoopCounter
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -588,14 +588,8 @@
 
 } // namespace
 
-/// Check a call to BuiltinID for buffer overflows. If BuiltinID is a
-/// __builtin_*_chk function, then use the object size argument specified in the
-/// source. Otherwise, infer the object size using __builtin_object_size.
 void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
CallExpr *TheCall) {
-  // FIXME: There are some more useful checks we could be doing here:
-  //  - Evaluate strlen of strcpy arguments, use as object size.
-
   if (TheCall->isValueDependent() || TheCall->isTypeDependent() ||
   isConstantEvaluated())
 return;
@@ -607,13 +601,65 @@
   const TargetInfo  = getASTContext().getTargetInfo();
   unsigned SizeTypeWidth = TI.getTypeWidth(TI.getSizeType());
 
+  auto ComputeCheckVariantSize = [&](unsigned Index) -> Optional {
+Expr::EvalResult Result;
+Expr *SizeArg = TheCall->getArg(Index);
+if (!SizeArg->EvaluateAsInt(Result, getASTContext()))
+  

[PATCH] D104649: Thread safety analysis: Rename parameters of ThreadSafetyAnalyzer::intersectAndWarn (NFC)

2021-06-25 Thread Delesley Hutchins via Phabricator via cfe-commits
delesley accepted this revision.
delesley added a comment.

Looks good.  Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104649

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


[PATCH] D104261: Thread safety analysis: Always warn when dropping locks on back edges

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

This looks good to me.  Thanks for the patch!  Since you're adding a new 
warning, this may break some code somewhere, but since it's restricted to 
relockable managed locks, I'm not too worried...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104261

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


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

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

In D104714#2841304 , @thakis wrote:

> I landed a fix attempt for my thing in 
> fda790fbfa0cba426d5e3787429a51e09ec64c6d 
>  .

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104714

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


[PATCH] D104904: [OpenMP][AMDGCN] Initial math headers support

2021-06-25 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added inline comments.



Comment at: clang/lib/Headers/__clang_hip_cmath.h:29
+#ifdef __OPENMP_AMDGCN__
+#define __DEVICE__ static constexpr __attribute__((always_inline, nothrow))
+#define __constant__ __attribute__((constant))

scchan wrote:
> `__DEVICE__` should not imply constexpr.  It should be added to each function 
> separately.
iirc rocm does that with a macro called __DEVICE_NOCE__, perhaps we could go 
with __DEVICE_CONSTEXPR__. There's some interaction with overloading rules and 
different glibc versions, so it would be nice to tag exactly the same functions 
as constexpr on nvptx and amdgcn



Comment at: clang/lib/Headers/__clang_hip_math.h:29
+#else
 #define __DEVICE__ static __device__ inline __attribute__((always_inline))
+#endif

wonder if HIP would benefit from nothrow here



Comment at: clang/lib/Headers/__clang_hip_math.h:35
+#ifdef __OPENMP_AMDGCN__
+#define __RETURN_TYPE int
+#else

I'd expect openmp to match the cplusplus/c distinction here, as openmp works on 
C source



Comment at: 
clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h:93
+
+#define __device__ __attribute__((device))
+

i think this should be `#define __device__`



Comment at: clang/test/Headers/Inputs/include/cstdlib:15
 
+#ifndef __AMDGCN__
 namespace std

I think I'd expect builtin_labs et al to work on amdgcn, are we missing 
lowering for them?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104904

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


[PATCH] D104896: [DFSan] Change shadow and origin memory layouts to match MSan.

2021-06-25 Thread Andrew via Phabricator via cfe-commits
browneee updated this revision to Diff 354558.
browneee marked 8 inline comments as done.
browneee added a comment.

Addressed comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104896

Files:
  clang/docs/DataFlowSanitizerDesign.rst
  compiler-rt/lib/dfsan/dfsan.cpp
  compiler-rt/lib/dfsan/dfsan.h
  compiler-rt/lib/dfsan/dfsan_allocator.cpp
  compiler-rt/lib/dfsan/dfsan_platform.h
  compiler-rt/test/dfsan/origin_invalid.c
  llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
  llvm/test/Instrumentation/DataFlowSanitizer/atomics.ll
  llvm/test/Instrumentation/DataFlowSanitizer/basic.ll
  llvm/test/Instrumentation/DataFlowSanitizer/load.ll
  llvm/test/Instrumentation/DataFlowSanitizer/origin_load.ll
  llvm/test/Instrumentation/DataFlowSanitizer/origin_store.ll
  llvm/test/Instrumentation/DataFlowSanitizer/store.ll

Index: llvm/test/Instrumentation/DataFlowSanitizer/store.ll
===
--- llvm/test/Instrumentation/DataFlowSanitizer/store.ll
+++ llvm/test/Instrumentation/DataFlowSanitizer/store.ll
@@ -22,7 +22,7 @@
   ; COMBINE_PTR_LABEL: load i[[#SBITS]], i[[#SBITS]]* {{.*}} @__dfsan_arg_tls
   ; COMBINE_PTR_LABEL: or i[[#SBITS]]
   ; CHECK: ptrtoint i8* {{.*}} i64
-  ; CHECK-NEXT:and i64
+  ; CHECK-NEXT:xor i64
   ; CHECK-NEXT:inttoptr i64 {{.*}} i[[#SBITS]]*
   ; CHECK-NEXT:getelementptr i[[#SBITS]], i[[#SBITS]]*
   ; CHECK-NEXT:store i[[#SBITS]]
@@ -39,7 +39,7 @@
   ; COMBINE_PTR_LABEL: load i[[#SBITS]], i[[#SBITS]]* {{.*}} @__dfsan_arg_tls
   ; COMBINE_PTR_LABEL: or i[[#SBITS]]
   ; CHECK: ptrtoint i16* {{.*}} i64
-  ; CHECK-NEXT:and i64
+  ; CHECK-NEXT:xor i64
   ; CHECK-NEXT:inttoptr i64 {{.*}} i[[#SBITS]]*
   ; CHECK-NEXT:getelementptr i[[#SBITS]], i[[#SBITS]]*
   ; CHECK-NEXT:store i[[#SBITS]]
@@ -58,7 +58,7 @@
   ; COMBINE_PTR_LABEL: load i[[#SBITS]], i[[#SBITS]]* {{.*}} @__dfsan_arg_tls
   ; COMBINE_PTR_LABEL: or i[[#SBITS]]
   ; CHECK: ptrtoint i32* {{.*}} i64
-  ; CHECK-NEXT:and i64
+  ; CHECK-NEXT:xor i64
   ; CHECK-NEXT:inttoptr i64 {{.*}} i[[#SBITS]]*
   ; CHECK-NEXT:getelementptr i[[#SBITS]], i[[#SBITS]]*
   ; CHECK-NEXT:store i[[#SBITS]]
@@ -81,7 +81,7 @@
   ; COMBINE_PTR_LABEL: load i[[#SBITS]], i[[#SBITS]]* {{.*}} @__dfsan_arg_tls
   ; COMBINE_PTR_LABEL: or i[[#SBITS]]
   ; CHECK: ptrtoint i64* {{.*}} i64
-  ; CHECK-NEXT:and i64
+  ; CHECK-NEXT:xor i64
   ; CHECK-NEXT:inttoptr i64 {{.*}} i[[#SBITS]]*
   ; CHECK-COUNT-8: insertelement {{.*}} i[[#SBITS]]
   ; CHECK-NEXT:bitcast i[[#SBITS]]* {{.*}} <8 x i[[#SBITS]]>*
Index: llvm/test/Instrumentation/DataFlowSanitizer/origin_store.ll
===
--- llvm/test/Instrumentation/DataFlowSanitizer/origin_store.ll
+++ llvm/test/Instrumentation/DataFlowSanitizer/origin_store.ll
@@ -52,9 +52,9 @@
   ; CHECK-NEXT:   %[[#AO:]] = load i32, i32* getelementptr inbounds ([200 x i32], [200 x i32]* @__dfsan_arg_origin_tls, i64 0, i64 0), align 4
   ; CHECK-NEXT:   %[[#AS:]] = load i[[#SBITS]], i[[#SBITS]]* bitcast ([100 x i64]* @__dfsan_arg_tls to i[[#SBITS]]*), align [[ALIGN]]
   ; CHECK:%[[#INTP:]] = ptrtoint i16* %p to i64
-  ; CHECK-NEXT:   %[[#SHADOW_ADDR:]] = and i64 %[[#INTP]], [[#%.10d,MASK:]]
-  ; CHECK-NEXT:   %[[#SHADOW_PTR0:]] = inttoptr i64 %[[#SHADOW_ADDR]] to i[[#SBITS]]*
-  ; CHECK-NEXT:   %[[#ORIGIN_OFFSET:]] = add i64 %[[#INTP+1]], [[#%.10d,ORIGIN_MASK:]]
+  ; CHECK-NEXT:   %[[#SHADOW_OFFSET:]] = xor i64 %[[#INTP]], [[#%.10d,MASK:]]
+  ; CHECK-NEXT:   %[[#SHADOW_PTR0:]] = inttoptr i64 %[[#SHADOW_OFFSET]] to i[[#SBITS]]*
+  ; CHECK-NEXT:   %[[#ORIGIN_OFFSET:]] = add i64 %[[#SHADOW_OFFSET]], [[#%.10d,ORIGIN_BASE:]]
   ; CHECK-NEXT:   %[[#ORIGIN_ADDR:]] = and i64 %[[#ORIGIN_OFFSET]], -4
   ; CHECK-NEXT:   %[[#ORIGIN_PTR:]] = inttoptr i64 %[[#ORIGIN_ADDR]] to i32*
   ; CHECK:%_dfscmp = icmp ne i[[#SBITS]] %[[#AS]], 0
Index: llvm/test/Instrumentation/DataFlowSanitizer/origin_load.ll
===
--- llvm/test/Instrumentation/DataFlowSanitizer/origin_load.ll
+++ llvm/test/Instrumentation/DataFlowSanitizer/origin_load.ll
@@ -35,9 +35,9 @@
 define i16* @load_escaped_alloca() {
   ; CHECK-LABEL:  @load_escaped_alloca.dfsan
   ; CHECK:%[[#INTP:]] = ptrtoint i16* %p to i64
-  ; CHECK-NEXT:   %[[#SHADOW_ADDR:]] = and i64 %[[#INTP]], [[#%.10d,MASK:]]
-  ; CHECK-NEXT:   %[[#SHADOW_PTR0:]] = inttoptr i64 %[[#SHADOW_ADDR]] to i[[#SBITS]]*
-  ; CHECK-NEXT:   %[[#ORIGIN_OFFSET:]] = add i64 %[[#INTP+1]], [[#%.10d,ORIGIN_MASK:]]
+  ; CHECK-NEXT:   %[[#SHADOW_OFFSET:]] = xor i64 %[[#INTP]], [[#%.10d,MASK:]]
+  ; CHECK-NEXT:   %[[#SHADOW_PTR0:]] = inttoptr i64 

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

2021-06-25 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

I landed a fix attempt for my thing in fda790fbfa0cba426d5e3787429a51e09ec64c6d 
 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104714

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


[clang] fda790f - [clang] Make fewer assumptions about path to lit.site.cfg after 9eaf0d120d32

2021-06-25 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2021-06-25T14:01:29-04:00
New Revision: fda790fbfa0cba426d5e3787429a51e09ec64c6d

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

LOG: [clang] Make fewer assumptions about path to lit.site.cfg after 
9eaf0d120d32

Added: 


Modified: 
clang/test/lit.site.cfg.py.in
clang/test/utils/update_cc_test_checks/Inputs/lit.cfg.example
clang/test/utils/update_cc_test_checks/lit.local.cfg

Removed: 




diff  --git a/clang/test/lit.site.cfg.py.in b/clang/test/lit.site.cfg.py.in
index 85526b9d30d6a..f31ede2c39575 100644
--- a/clang/test/lit.site.cfg.py.in
+++ b/clang/test/lit.site.cfg.py.in
@@ -10,6 +10,7 @@ config.llvm_shlib_dir = path(r"@SHLIBDIR@")
 config.llvm_plugin_ext = "@LLVM_PLUGIN_EXT@"
 config.lit_tools_dir = path(r"@LLVM_LIT_TOOLS_DIR@")
 config.errc_messages = "@LLVM_LIT_ERRC_MESSAGES@"
+config.clang_lit_site_cfg = __file__
 config.clang_obj_root = path(r"@CLANG_BINARY_DIR@")
 config.clang_src_dir = path(r"@CLANG_SOURCE_DIR@")
 config.clang_tools_dir = path(r"@CLANG_TOOLS_DIR@")

diff  --git a/clang/test/utils/update_cc_test_checks/Inputs/lit.cfg.example 
b/clang/test/utils/update_cc_test_checks/Inputs/lit.cfg.example
index c1afdc47956a3..4e221c70b62f7 100644
--- a/clang/test/utils/update_cc_test_checks/Inputs/lit.cfg.example
+++ b/clang/test/utils/update_cc_test_checks/Inputs/lit.cfg.example
@@ -1,7 +1,6 @@
 import lit
 lit_config.load_config(
-config, os.path.join(lit_config.params.get('clang_obj_root'),
- "test/lit.site.cfg.py"))
+config, os.path.join(lit_config.params.get('clang_lit_site_cfg')))
 config.name = 'update_cc_test_checks.py example'
 config.suffixes = ['.c', '.cpp']
 config.test_format = lit.formats.ShTest(execute_external=False)

diff  --git a/clang/test/utils/update_cc_test_checks/lit.local.cfg 
b/clang/test/utils/update_cc_test_checks/lit.local.cfg
index b61309fdf0f3c..cbcc05dff4ca7 100644
--- a/clang/test/utils/update_cc_test_checks/lit.local.cfg
+++ b/clang/test/utils/update_cc_test_checks/lit.local.cfg
@@ -27,5 +27,5 @@ config.substitutions.append(
 config.substitutions.append(
 ('%clang_tools_dir', shell_quote(config.clang_tools_dir)))
 config.substitutions.append(
-('%lit', "%s %s -Dclang_obj_root=%s -j1 -vv" % (
-python, lit, shell_quote(config.clang_obj_root
+('%lit', "%s %s -Dclang_lit_site_cfg=%s -j1 -vv" % (
+python, lit, shell_quote(config.clang_lit_site_cfg



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


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

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

In D104714#2841229 , @thakis wrote:

> Oh I see this assumes that lit.site.cfg.py is below clang_obj_root. I guess 
> that's my problem, looking…

Let me know if the patch isn't general enough, or if I can help in some other 
way.

Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104714

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


[PATCH] D104931: [AArch64] Wire up ILP32 ABI support in Clang

2021-06-25 Thread Amanieu d'Antras via Phabricator via cfe-commits
Amanieu created this revision.
Amanieu added reviewers: t.p.northover, aemerson, kristof.beyls.
Herald added a subscriber: danielkiss.
Amanieu requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a follow-up to D94143  which added the 
necessary support in LLVM.

ILP32 mode is enabled by specifying an ILP32 target (aarch64[_be]-*-gnu_ilp32) 
with -target.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104931

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


Index: clang/lib/Basic/Targets/AArch64.cpp
===
--- clang/lib/Basic/Targets/AArch64.cpp
+++ clang/lib/Basic/Targets/AArch64.cpp
@@ -43,7 +43,8 @@
 AArch64TargetInfo::AArch64TargetInfo(const llvm::Triple ,
  const TargetOptions )
 : TargetInfo(Triple), ABI("aapcs") {
-  if (getTriple().isOSOpenBSD()) {
+  if (getTriple().isOSOpenBSD() ||
+  getTriple().getEnvironment() == llvm::Triple::GNUILP32) {
 Int64Type = SignedLongLong;
 IntMaxType = SignedLongLong;
   } else {
@@ -58,7 +59,8 @@
   HasLegalHalfType = true;
   HasFloat16 = true;
 
-  if (Triple.isArch64Bit())
+  if (Triple.isArch64Bit() &&
+  getTriple().getEnvironment() != llvm::Triple::GNUILP32)
 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
   else
 LongWidth = LongAlign = PointerWidth = PointerAlign = 32;
@@ -213,10 +215,15 @@
 Builder.defineMacro("__ELF__");
 
   // Target properties.
-  if (!getTriple().isOSWindows() && getTriple().isArch64Bit()) {
+  if (!getTriple().isOSWindows() && getTriple().isArch64Bit() &&
+  getTriple().getEnvironment() != llvm::Triple::GNUILP32) {
 Builder.defineMacro("_LP64");
 Builder.defineMacro("__LP64__");
   }
+  if (getTriple().getEnvironment() == llvm::Triple::GNUILP32) {
+Builder.defineMacro("_ILP32");
+Builder.defineMacro("__ILP32__");
+  }
 
   std::string CodeModel = getTargetOpts().CodeModel;
   if (CodeModel == "default")
@@ -780,8 +787,13 @@
   resetDataLayout("e-m:o-p:32:32-i64:64-i128:128-n32:64-S128", "_");
 else
   resetDataLayout("e-m:o-i64:64-i128:128-n32:64-S128", "_");
-  } else
-resetDataLayout("e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128");
+  } else {
+if (getTriple().getEnvironment() == llvm::Triple::GNUILP32)
+  resetDataLayout(
+  "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128");
+else
+  resetDataLayout("e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128");
+  }
 }
 
 void AArch64leTargetInfo::getTargetDefines(const LangOptions ,
@@ -804,7 +816,11 @@
 
 void AArch64beTargetInfo::setDataLayout() {
   assert(!getTriple().isOSBinFormatMachO());
-  resetDataLayout("E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128");
+  if (getTriple().getEnvironment() == llvm::Triple::GNUILP32)
+resetDataLayout(
+"E-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128");
+  else
+resetDataLayout("E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128");
 }
 
 WindowsARM64TargetInfo::WindowsARM64TargetInfo(const llvm::Triple ,


Index: clang/lib/Basic/Targets/AArch64.cpp
===
--- clang/lib/Basic/Targets/AArch64.cpp
+++ clang/lib/Basic/Targets/AArch64.cpp
@@ -43,7 +43,8 @@
 AArch64TargetInfo::AArch64TargetInfo(const llvm::Triple ,
  const TargetOptions )
 : TargetInfo(Triple), ABI("aapcs") {
-  if (getTriple().isOSOpenBSD()) {
+  if (getTriple().isOSOpenBSD() ||
+  getTriple().getEnvironment() == llvm::Triple::GNUILP32) {
 Int64Type = SignedLongLong;
 IntMaxType = SignedLongLong;
   } else {
@@ -58,7 +59,8 @@
   HasLegalHalfType = true;
   HasFloat16 = true;
 
-  if (Triple.isArch64Bit())
+  if (Triple.isArch64Bit() &&
+  getTriple().getEnvironment() != llvm::Triple::GNUILP32)
 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
   else
 LongWidth = LongAlign = PointerWidth = PointerAlign = 32;
@@ -213,10 +215,15 @@
 Builder.defineMacro("__ELF__");
 
   // Target properties.
-  if (!getTriple().isOSWindows() && getTriple().isArch64Bit()) {
+  if (!getTriple().isOSWindows() && getTriple().isArch64Bit() &&
+  getTriple().getEnvironment() != llvm::Triple::GNUILP32) {
 Builder.defineMacro("_LP64");
 Builder.defineMacro("__LP64__");
   }
+  if (getTriple().getEnvironment() == llvm::Triple::GNUILP32) {
+Builder.defineMacro("_ILP32");
+Builder.defineMacro("__ILP32__");
+  }
 
   std::string CodeModel = getTargetOpts().CodeModel;
   if (CodeModel == "default")
@@ -780,8 +787,13 @@
   resetDataLayout("e-m:o-p:32:32-i64:64-i128:128-n32:64-S128", "_");
 else
   resetDataLayout("e-m:o-i64:64-i128:128-n32:64-S128", "_");
-  } else
-resetDataLayout("e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128");
+  } else {
+if 

[PATCH] D104847: [Clang][NVPTX] Add NVPTX intrinsics and builtins for CUDA PTX 6.5 and 7.0 WMMA and MMA instructions

2021-06-25 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.

LGTM. Would you like me to land the patch on your behalf?




Comment at: clang/lib/CodeGen/CGBuiltin.cpp:16397
   unsigned NumEltsD;
   std::array Variants;
 

A comment here describing expected arrangement of the variants here would be 
helpful.
E.g. `ordered by layout-A/layout-B/satf, where 'row' has priority over 'col' 
for layout. The index of non-satf variants is expected to match the 
undocumented layout constants used by CUDA's mma.hpp`.

It could be cleaner if we could use designated initializer, but we can't use 
them yet until LLVM switches to c++20.



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

https://reviews.llvm.org/D104847

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


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

2021-06-25 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Oh I see this assumes that lit.site.cfg.py is below clang_obj_root. I guess 
that's my problem, looking…


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104714

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


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

2021-06-25 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

This seems to break tests: http://45.33.8.238/linux/49790/step_7.txt


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104714

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


[PATCH] D104854: Introduce intrinsic llvm.isnan

2021-06-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp:662
+  EVT NewResultVT = TLI.getTypeToTransformTo(*DAG.getContext(), ResultVT);
+  return DAG.getNode(N->getOpcode(), DL, NewResultVT, N->getOperand(0));
+}

Don't you net to preserve the NoFPExcept flag? Same with all the other type 
legalization functions



Comment at: llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp:600
+
+  SDValue Res = DAG.getNode(ISD::ISNAN, DL, ResultVT, Arg);
+  // Vectors may have a different boolean contents to scalars.  Promote the

If this is ResultVT then the Extend created next is always a NOP. Should this 
be MVT::i1?



Comment at: llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp:4727
+
+  if (TLI.isTypeLegal(WideResultVT)) {
+SDValue WideNode = DAG.getNode(ISD::ISNAN, DL, WideResultVT, WideArg);

I wonder if we should be using getSetCCResultType here like WidenVecOp_SETCC?



Comment at: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:6371
+DAG.getNode(ISD::ISNAN, sdl, DestVT, getValue(I.getArgOperand(0)));
+V->setFlags(Flags);
+// If ISD::ISNAN should be expanded, do it right now, because the expansion

Why not pass flags to getNode?



Comment at: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:6375
+// types prior to selection.
+if (!TLI.isOperationLegalOrCustom(ISD::ISNAN, ArgVT)) {
+  SDValue Result = TLI.expandISNAN(V.getNode(), DAG);

This breaks if we add constant folding for ISD::ISNAN to getNode.



Comment at: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:6981
+  // V = sign bit (Sub) <=> V = (Sub < 0)
+  SDValue SignBitV = DAG.getNode(ISD::SRL, DL, IntVT, Sub,
+ DAG.getConstant(BitSize - 1, DL, IntVT));

Why can't we just check < 0 here? Why do we need to shift?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104854

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


[PATCH] D104896: [DFSan] Change shadow and origin memory layouts to match MSan.

2021-06-25 Thread stephan.yichao.zhao via Phabricator via cfe-commits
stephan.yichao.zhao added a comment.

Thank you for making this work!




Comment at: compiler-rt/lib/dfsan/dfsan.cpp:871
+
+static void CheckMemoryLayoutSanity() {
+  uptr prev_end = 0;

Please add a comment about that these CheckMemoryLayoutSanity, ... and 
InitShadow are possible to be shared with MSan (like the TODO in 
dfsan_platform.h), by moving them and those platform mapping definitions/macros 
compiler-rt/lib/msan/msan.h to sanitizer_common because it is highly likely 
that MSan and DFSan always have the same layouts...
Since the change does not branch from MSan's code, w/o comments, it is not easy 
for others to know they are similar.



Comment at: compiler-rt/lib/dfsan/dfsan.cpp:902
+
+static bool CheckMemoryRangeAvailability(uptr beg, uptr size) {
+  if (size > 0) {

I suggest moving CheckMemoryRangeAvailability and ProtectMemoryRange to 
sanitizer_common (if this does not break any sanitizer convention).
They are checking some general things and also some corner cases like "protect 
address 0...".
If shared, it is more likely that others can help DFSan to improve them.



Comment at: llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp:257
+// x86_64 Linux
+static const MemoryMapParams Linux_X86_64_MemoryMapParams = {
+0,  // AndMask (not used)

Does this suggest LinuxX8664MemoryMapParams? Not sure if there is a workaround 
to suppress this warning.



Comment at: llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp:460
 
+  /// Memory map parameters used in application-to-shadow calculation.
+  const MemoryMapParams *MapParams;

in mapping application to shadow and origin


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104896

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


[PATCH] D103615: [Clang] Add option to handle behaviour of vector bool/vector pixel.

2021-06-25 Thread Bardia Mahjour via Phabricator via cfe-commits
bmahjour accepted this revision.
bmahjour added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103615

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


[clang] 9eaf0d1 - [UpdateCCTestChecks] Support --check-globals

2021-06-25 Thread Joel E. Denny via cfe-commits

Author: Joel E. Denny
Date: 2021-06-25T13:17:56-04:00
New Revision: 9eaf0d120d3255c43789213c499513ba1be9dde7

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

LOG: [UpdateCCTestChecks] Support --check-globals

This option is already supported by update_test_checks.py, but it can
also be useful in update_cc_test_checks.py.  For example, I'd like to
use it in OpenMP offload codegen tests to check global variables like
`.offload_maptypes*`.

Reviewed By: jdoerfert, arichardson, ggeorgakoudis

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

Added: 
clang/test/utils/update_cc_test_checks/Inputs/check-globals.c
clang/test/utils/update_cc_test_checks/Inputs/lit.cfg.example
clang/test/utils/update_cc_test_checks/check-globals.test

Modified: 
clang/test/utils/update_cc_test_checks/lit.local.cfg
llvm/utils/UpdateTestChecks/common.py
llvm/utils/update_cc_test_checks.py

Removed: 




diff  --git a/clang/test/utils/update_cc_test_checks/Inputs/check-globals.c 
b/clang/test/utils/update_cc_test_checks/Inputs/check-globals.c
new file mode 100644
index 0..a63cec246e468
--- /dev/null
+++ b/clang/test/utils/update_cc_test_checks/Inputs/check-globals.c
@@ -0,0 +1,10 @@
+// First, make sure --check-globals doesn't crash on a non-FileChecked command.
+// RUN: true
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -o - %s | FileCheck 
%s
+
+void foo() {
+  static int i, j;
+}
+void bar() {
+  static int i, j;
+}

diff  --git a/clang/test/utils/update_cc_test_checks/Inputs/lit.cfg.example 
b/clang/test/utils/update_cc_test_checks/Inputs/lit.cfg.example
new file mode 100644
index 0..c1afdc47956a3
--- /dev/null
+++ b/clang/test/utils/update_cc_test_checks/Inputs/lit.cfg.example
@@ -0,0 +1,9 @@
+import lit
+lit_config.load_config(
+config, os.path.join(lit_config.params.get('clang_obj_root'),
+ "test/lit.site.cfg.py"))
+config.name = 'update_cc_test_checks.py example'
+config.suffixes = ['.c', '.cpp']
+config.test_format = lit.formats.ShTest(execute_external=False)
+config.test_source_root = os.path.dirname(__file__)
+config.test_exec_root = os.path.dirname(__file__)

diff  --git a/clang/test/utils/update_cc_test_checks/check-globals.test 
b/clang/test/utils/update_cc_test_checks/check-globals.test
new file mode 100644
index 0..2af041b5ec7c4
--- /dev/null
+++ b/clang/test/utils/update_cc_test_checks/check-globals.test
@@ -0,0 +1,83 @@
+RUN: rm -rf %t && mkdir %t
+
+# Check --check-globals in normal mode and in --include-generated-funcs mode.
+
+RUN: cp %S/Inputs/check-globals.c %t/norm.c
+RUN: %update_cc_test_checks %t/norm.c --check-globals
+RUN: FileCheck %s --input-file=%t/norm.c --match-full-lines -strict-whitespace 
\
+RUN:   -check-prefixes=BOTH,NRM
+
+RUN: cp %S/Inputs/check-globals.c %t/igf.c
+RUN: %update_cc_test_checks %t/igf.c --check-globals --include-generated-funcs
+RUN: FileCheck %s --input-file=%t/igf.c --match-full-lines -strict-whitespace \
+RUN:   -check-prefixes=BOTH,IGF
+
+# Check that repeating doesn't change it, such as duplicating '//.' 
occurrences.
+
+RUN: cp %t/norm.c %t/norm-again.c
+RUN: %update_cc_test_checks %t/norm-again.c --check-globals
+RUN: 
diff  -u %t/norm.c %t/norm-again.c
+RUN: rm %t/norm-again.c
+
+RUN: cp %t/igf.c %t/igf-again.c
+RUN: %update_cc_test_checks %t/igf-again.c --check-globals \
+RUN: --include-generated-funcs
+RUN: 
diff  -u %t/igf.c %t/igf-again.c
+RUN: rm %t/igf-again.c
+
+# Check that the generated directives actually work correctly.  For example,
+# they're not in the wrong order.
+
+RUN: cp %S/Inputs/lit.cfg.example %t/lit.cfg
+# Show lit failures while avoiding confusing FileCheck input dump nesting.
+RUN: %lit %t
+# Lit was successful.  Sanity-check the results.
+RUN: %lit %t 2>&1 | FileCheck -check-prefix=LIT-RUN %s
+
+END.
+
+  BOTH-NOT:{{.}}
+   NRM:// NOTE: Assertions have been autogenerated by 
utils/update_cc_test_checks.py UTC_ARGS: --check-globals
+   IGF:// NOTE: Assertions have been autogenerated by 
utils/update_cc_test_checks.py UTC_ARGS: --check-globals 
--include-generated-funcs
+ BOTH-NEXT:// {{.*}}
+ BOTH-NEXT:// RUN: true
+ BOTH-NEXT:// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -o - %s | 
FileCheck %s
+BOTH-EMPTY:
+  IGF-NEXT:void foo() {
+  IGF-NEXT:  static int i, j;
+  IGF-NEXT:}
+  IGF-NEXT:void bar() {
+  IGF-NEXT:  static int i, j;
+  IGF-NEXT:}
+ BOTH-NEXT://.
+ BOTH-NEXT:// CHECK: @foo.i = internal global i32 0, align 4
+ BOTH-NEXT:// CHECK: @foo.j = internal global i32 0, align 4
+ BOTH-NEXT:// CHECK: @bar.i = internal global i32 0, align 4
+ BOTH-NEXT:// CHECK: @bar.j = internal global i32 0, align 4
+ BOTH-NEXT://.
+ BOTH-NEXT:// CHECK-LABEL: @foo(
+ BOTH-NEXT:// CHECK-NEXT:  entry:
+ 

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

2021-06-25 Thread Joel E. Denny 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 rG9eaf0d120d32: [UpdateCCTestChecks] Support --check-globals 
(authored by jdenny).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104714

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

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

[PATCH] D104716: [analyzer] Fix assertion failure on code with transparent unions

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

Thanks again!~


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104716

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


[PATCH] D20689: [clang-tidy] Add 'readability-suspicious-call-argument' check

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



Comment at: 
clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp:185
+for (std::size_t J = 0; J < Param.size(); ++J) {
+  if (Arg[I] == Param[J]) {
+if (I == 0 || J == 0)

Should this be a case insensitive comparison?



Comment at: 
clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp:207
+  double Dist = Arg.edit_distance(Param);
+  Dist = (1 - Dist / LongerLength) * 100;
+  return Dist > Threshold;





Comment at: 
clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp:268
+  // Jaro-Winkler distance.
+  Dist = (Dist + (L * 0.1 * (1 - Dist))) * 100;
+  return Dist > Threshold;





Comment at: 
clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp:299
+
+/// Checks if ArgType binds to ParamType ragerding reference-ness and
+/// cv-qualifiers.





Comment at: 
clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp:371
+
+// Check whether cv-qualifiers premit compatibility on
+// current level.





Comment at: 
clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp:403
+
+  // Reference-ness has already been checked ad should be removed
+  // before further checking.





Comment at: 
clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp:408-409
+
+  bool IsParamContinuouslyConst =
+  !IsParamReference || ParamType.getNonReferenceType().isConstQualified();
+

Should this move down closer to where it's used?



Comment at: 
clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp:425-427
+  // Check if the argument and the param are both function types (the parameter
+  // decayed to
+  // a function pointer).





Comment at: 
clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp:437
+
+  // When ParamType is an array reference, ArgType has to be of the same sized,
+  // array type with cv-compatible elements.





Comment at: 
clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp:453
+
+  // At this point, all possible C language implicit conversion were checked
+  if (!Ctx.getLangOpts().CPlusPlus)





Comment at: 
clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp:467
+
+return ArgDecl->isDerivedFrom(ParamDecl);
+  }

It would be good to have a test case involving private inheritance.



Comment at: 
clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp:579
+bool SuspiciousCallArgumentCheck::isHeuristicEnabled(Heuristic H) const {
+  return llvm::find(AppliedHeuristics, H) != AppliedHeuristics.end();
+}





Comment at: 
clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp:588
+  if (!Defaults[Idx].hasBounds())
+return {};
+





Comment at: 
clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp:694-695
+
+  for (std::size_t I = 0, E = CalleeFuncDecl->getNumParams(); I != E; ++I) {
+if (const auto *Param = CalleeFuncDecl->getParamDecl(I)) {
+  ParamTypes.push_back(Param->getType());

Range-based for loop over `CalledFuncDecl->params()`?



Comment at: 
clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp:801
+  }
+  llvm_unreachable("Unhandled heuristic kind");
+}

This looks pretty reachable to me in the case where there's no bound.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D20689

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


[PATCH] D104871: [Docs] use -fprofile-generate for IR PGO and -fprofile-instr-generate for code coverage

2021-06-25 Thread David Li via Phabricator via cfe-commits
davidxl added inline comments.



Comment at: clang/docs/UsersManual.rst:1881
conversion tool that can convert one to the other. So, a profile generated
-   via ``-fprofile-instr-generate`` must be used with ``-fprofile-instr-use``.
+   via ``-fprofile-generate`` must be used with ``-fprofile-instr-use``.
Similarly, sampling profiles generated by external profilers must be

This is not correct.   As of today,  -fprofile-use can be used with both 
-fprofile-generate and -fprofile-instr-generate. It does this by looking at the 
flag in the profile data.

The better way to document:

For profile guided optimizations, we recommend using IRPGO, aka  
using-fprofile-generate with -fprofile-use


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104871

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


[PATCH] D104896: [DFSan] Change shadow and origin memory layouts to match MSan.

2021-06-25 Thread stephan.yichao.zhao via Phabricator via cfe-commits
stephan.yichao.zhao added inline comments.



Comment at: compiler-rt/lib/dfsan/dfsan.cpp:169
+// TODO(browneee): Removed this after testing and not hit.
+CHECK(MEM_IS_SHADOW(s));
+// if (!MEM_IS_SHADOW(s)) {

Based on the recent issue about using a replaced memmove.
It seems safe to always keep this CHECK and update the comments to reflect this.




Comment at: compiler-rt/lib/dfsan/dfsan.cpp:170
+CHECK(MEM_IS_SHADOW(s));
+// if (!MEM_IS_SHADOW(s)) {
+//   // The current DFSan memory layout is not always correct. For example,

Please remove the commented code.



Comment at: compiler-rt/lib/dfsan/dfsan.cpp:177
+
+if (*s) {
+  uptr aligned_addr = OriginAlignDown(SHADOW_TO_ORIGIN(s));

This branch seems redundant with the one below.



Comment at: compiler-rt/lib/dfsan/dfsan.cpp:332
StackTrace *stack) {
-  if (!has_valid_shadow_addr(dst) ||
-  !has_valid_shadow_addr((void *)((uptr)dst + size)) ||
-  !has_valid_shadow_addr(src) ||
-  !has_valid_shadow_addr((void *)((uptr)src + size))) {
+  // TODO(browneee): Removed this after testing and not hit.
+  if (!MEM_IS_SHADOW(shadow_for(dst)) ||

Please update the comments to be consistent with other MEM_IS_SHADOW checks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104896

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


[PATCH] D81886: [AMDGPU] Add gfx1030 target

2021-06-25 Thread Jay Foad via Phabricator via cfe-commits
foad added inline comments.
Herald added a subscriber: dexonsmith.



Comment at: llvm/lib/Target/AMDGPU/AMDGPU.td:1245
+
+def HasDsSrc2Insts : Predicate<"!Subtarget->hasDsSrc2Insts()">,
+  AssemblerPredicate<(all_of FeatureDsSrc2Insts)>;

The `!` is obviously wrong in this definition, but if I remove it, all the 
tests still pass. So does this predicate actually control anything?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81886

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


[PATCH] D104261: Thread safety analysis: Always warn when dropping locks on back edges

2021-06-25 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added inline comments.



Comment at: clang/lib/Analysis/ThreadSafety.cpp:868
 ThreadSafetyHandler ) const override {
-if (!managed() && !asserted() && !negative() && !isUniversal()) {
+if (!asserted() && !negative() && !isUniversal()) {
   Handler.handleMutexHeldEndOfScope("mutex", toString(), loc(), JoinLoc,

aaronpuchert wrote:
> One might ask: what about asserted capabilities? I plan to introduce a 
> warning when they are released, because that can't be consistent, and then 
> they can't disappear on back edges without warning.
> 
> For negative capabilities we'd presumably see a warning for the "positive" 
> capability instead.
> 
> Not sure how universal capabilities are typically used. Presumably one could 
> release such a capability in a loop? Then on the other hand, code using such 
> capabilities is probably not very interested in false negatives.
> For negative capabilities we'd presumably see a warning for the "positive" 
> capability instead.

No, because a back edge is missing a positive capability when I'm unlocking in 
a loop, whereas it would be missing a negative capability when I'm locking in a 
loop.

But we probably want to warn about this only when `-Wthread-safety-negative` is 
active.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104261

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


[PATCH] D103612: [flang][driver] Add `-fno-analyzed-objects-for-unparse`

2021-06-25 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

I pushed a fix without a review: 
https://reviews.llvm.org/rGc3ebb53eabb7f851687f66ada88aa16f768d76ce. Please let 
me know if you prefer such changes to go through a regular review in the future!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103612

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


[PATCH] D104925: [Analyzer] Improve report of file read at end-of-file condition.

2021-06-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: manas, steakhal, ASDenysPetrov, martong, gamesh411, 
dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, 
baloghadamsoftware, xazax.hun, whisperity.
Herald added a reviewer: Szelethus.
balazske requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The checker warns if a stream is read that is already in EOF state.
The commit adds indication of locations where the EOF flag is set
on the stream and where it is discovered by the program.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104925

Files:
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  clang/test/Analysis/stream-note.c

Index: clang/test/Analysis/stream-note.c
===
--- clang/test/Analysis/stream-note.c
+++ clang/test/Analysis/stream-note.c
@@ -88,3 +88,60 @@
   fclose(F); // expected-warning {{Stream pointer might be NULL}}
   // expected-note@-1 {{Stream pointer might be NULL}}
 }
+
+void check_eof_notes_1() {
+  FILE *F;
+  char Buf[10];
+  F = fopen("foo1.c", "r");
+  if (F == NULL) { // expected-note {{Taking false branch}} expected-note {{'F' is not equal to NULL}}
+return;
+  }
+  fread(Buf, 1, 1, F);
+  if (feof(F)) { // expected-note {{Taking true branch}}
+clearerr(F);
+fread(Buf, 1, 1, F);   // expected-note {{Assuming that stream reaches end-of-file here}}
+if (feof(F)) { // expected-note {{End-of-file status is discovered here}} expected-note {{Taking true branch}}
+  fread(Buf, 1, 1, F); // expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
+  // expected-note@-1 {{Read function called when stream is in EOF state. Function has no effect}}
+}
+  }
+  fclose(F);
+}
+
+void check_eof_notes_2() {
+  FILE *F;
+  char Buf[10];
+  F = fopen("foo1.c", "r");
+  if (F == NULL) { // expected-note {{Taking false branch}} expected-note {{'F' is not equal to NULL}}
+return;
+  }
+  fread(Buf, 1, 1, F);
+  if (feof(F)) { // expected-note {{Taking false branch}}
+fclose(F);
+return;
+  } else if (ferror(F)) { // expected-note {{Taking false branch}}
+fclose(F);
+return;
+  }
+  fread(Buf, 1, 1, F);   // expected-note {{Assuming that stream reaches end-of-file here}}
+  if (feof(F)) { // expected-note {{End-of-file status is discovered here}} expected-note {{Taking true branch}}
+fread(Buf, 1, 1, F); // expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
+// expected-note@-1 {{Read function called when stream is in EOF state. Function has no effect}}
+  }
+  fclose(F);
+}
+
+void check_eof_notes_3() {
+  FILE *F;
+  char Buf[10];
+  F = fopen("foo1.c", "r");
+  if (F == NULL) // expected-note {{Taking false branch}} expected-note {{'F' is not equal to NULL}}
+return;
+  int RRet = fread(Buf, 1, 1, F); // expected-note {{Assuming that stream reaches end-of-file here}}
+  if (ferror(F)) {// expected-note {{End-of-file status is discovered here}} expected-note {{Taking false branch}}
+  } else {
+fread(Buf, 1, 1, F); // expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
+// expected-note@-1 {{Read function called when stream is in EOF state. Function has no effect}}
+  }
+  fclose(F);
+}
Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -25,6 +25,10 @@
 using namespace ento;
 using namespace std::placeholders;
 
+//===--===//
+// Definition of state data structures.
+//===--===//
+
 namespace {
 
 struct FnDescription;
@@ -146,6 +150,14 @@
   }
 };
 
+} // namespace
+
+//===--===//
+// StreamChecker class and utility functions.
+//===--===//
+
+namespace {
+
 class StreamChecker;
 using FnCheck = std::function;
@@ -337,7 +349,8 @@
   /// There will be always a state transition into the passed State,
   /// by the new non-fatal error node or (if failed) a normal transition,
   /// to ensure uniform handling.
-  void reportFEofWarning(CheckerContext , ProgramStateRef State) const;
+  void reportFEofWarning(SymbolRef StreamSym, CheckerContext ,
+ ProgramStateRef State) const;
 
   /// Emit resource leak warnings for the given symbols.
   /// Createn a non-fatal error node for these, and returns it (if any warnings
@@ -389,10 +402,62 @@
 CheckerContext );
 };
 
+class StreamBugVisitor final : 

[PATCH] D104261: Thread safety analysis: Always warn when dropping locks on back edges

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

In D104261#2832892 , @aaron.ballman 
wrote:

> I think the CI failure (libarcher.races::lock-unrelated.c) is not related to 
> this patch but is a tsan thing, but you may want to double-check that just in 
> case.

Seems that an expected race didn't materialize, perhaps it's a bit flaky. I'd 
be surprised if it was related.

> I'd like to hear from @delesley before landing.

Me too. Generally about treating back edges differently, as we can't modify the 
lockset anymore. (I have a similar change that's going to take back some of 
relaxations in D102026 , namely for an 
exclusive lock coming back as a shared lock on the back edge.)




Comment at: clang/test/SemaCXX/warn-thread-safety-analysis.cpp:2806-2816
+void loopReleaseContinue() {
+  RelockableMutexLock scope(, ExclusiveTraits{}); // expected-note {{mutex 
acquired here}}
+  // We have to warn on this join point despite the lock being managed ...
+  for (unsigned i = 1; i < 10; ++i) {
+x = 1; // ... because we might miss that this doesn't always happen under 
lock.
+if (i == 5) {
+  scope.Unlock();

aaron.ballman wrote:
> How about a test like:
> ```
> void foo() {
>   RelockableMutexLock scope(, ExclusiveTraits{});
>   for (unsigned i = 1; i < 10; ++i) {
> if (i > 0) // Always true
>   scope.Lock(); // So we always lock
> x = 1; // So I'd assume we don't warn
>   }
> }
The CFG isn't that clever, it would only consider `i > 0` always true if `i` 
was a compile-time constant. It doesn't even consider type limits, so for `i >= 
0` the else-branch would still be considered reachable:

```
 [B2]
   1: x
   2: [B2.1] (ImplicitCastExpr, LValueToRValue, unsigned int)
   3: 0
   4: [B2.3] (ImplicitCastExpr, IntegralCast, unsigned int)
   5: [B2.2] >= [B2.4]
   T: if [B2.5]
   Preds (1): B3
   Succs (2): B1 B0
```

versus the same with `true`:

```
 [B2]
   1: true
   T: if [B2.1]
   Preds (1): B3
   Succs (2): B1 B0(Unreachable)
```

But let's say we use a compile-time constant, then it's equivalent to not 
having the `Lock` call conditional at all, and there is no warning. Actually I 
might just change `loopAcquire` into this, because as that test is written 
right now it doesn't affect the back edge at all. (The lock will be removed 
from the lockset when the if joins with the else, before we loop back.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104261

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


[PATCH] D103612: [flang][driver] Add `-fno-analyzed-objects-for-unparse`

2021-06-25 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

In D103612#2840886 , @klausler wrote:

> This patch may have broken the shared library buildbots.

Sorry about that. A fix is on its way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103612

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


[PATCH] D86671: [clang-tidy] Add new case type to check variables with Hungarian notation

2021-06-25 Thread Douglas Chen via Phabricator via cfe-commits
dougpuob added a comment.

In D86671#2837818 , @gnossier wrote:

> Is this ready to merge soon?

Hi  @gnossier:
I'm waiting for feedbacks from reviewer.

Hi @aaron.ballman:
Nathan is helping me to review this patch, but seems he is not here recently. 
Do you have any suggestion about how to keep the ball rolling in this 
situation? If it was done, can I apply the right to land it by self?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86671

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


[PATCH] D103612: [flang][driver] Add `-fno-analyzed-objects-for-unparse`

2021-06-25 Thread Peter Klausler via Phabricator via cfe-commits
klausler added a comment.

This patch may have broken the shared library buildbots.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103612

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


[PATCH] D104616: [analyzer][WIP] Model comparision methods of std::unique_ptr

2021-06-25 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:336
+  BinaryOperatorKind BOK;
+  switch (OOK) {
+  case OO_EqualEqual:

Btw, if we do not have a helper yet to translate between these enums in the 
analyer, we should create one. Could you look for some other places in the 
analyzer code base to double check? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104616

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


[PATCH] D104843: [clangd] Introduce a log-prefix flag to remote-index-server

2021-06-25 Thread Kadir Cetinkaya 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 rG8f2bf93b5bd6: [clangd] Introduce a log-prefix flag to 
remote-index-server (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104843

Files:
  clang-tools-extra/clangd/index/remote/server/Server.cpp
  clang-tools-extra/clangd/test/remote-index/log-prefix.test

Index: clang-tools-extra/clangd/test/remote-index/log-prefix.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/remote-index/log-prefix.test
@@ -0,0 +1,18 @@
+# RUN: rm -rf %t
+# RUN: clangd-indexer %S/Inputs/Source.cpp > %t.idx
+# RUN: %python %S/pipeline_helper.py --input-file-name=%s --server-arg=--log=verbose --server-arg=-log-prefix=test-prefix --server-log=%t.log --project-root=%S --index-file=%t.idx > /dev/null
+# RUN: FileCheck %s < %t.log
+# REQUIRES: clangd-remote-index
+
+# CHECK: [test-prefix] Server listening on
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+---
+{"jsonrpc":"2.0","id":1,"method":"workspace/symbol","params":{"query":"gFoo"}}
+# CHECK: [test-prefix] <<< FuzzyFindRequest
+# CHECK: [test-prefix] >>> FuzzyFindReply
+# CHECK: [test-prefix] [public] request v1/FuzzyFind
+---
+{"jsonrpc":"2.0","id":4,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
+
Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -37,7 +37,9 @@
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
 
 #if ENABLE_GRPC_REFLECTION
 #include 
@@ -78,6 +80,12 @@
 llvm::cl::init(false),
 };
 
+llvm::cl::opt LogPrefix{
+"log-prefix",
+llvm::cl::desc("A string that'll be prepended to all log statements. "
+   "Useful when running multiple instances on same host."),
+};
+
 llvm::cl::opt TraceFile(
 "trace-file",
 llvm::cl::desc("Path to the file where tracer logs will be stored"));
@@ -427,27 +435,48 @@
   ServerShutdownWatcher.join();
 }
 
-std::unique_ptr makeLogger(llvm::raw_ostream ) {
-  if (!LogPublic)
-return std::make_unique(OS, LogLevel);
-  // Redacted mode:
-  //  - messages outside the scope of a request: log fully
-  //  - messages tagged [public]: log fully
-  //  - errors: log the format string
-  //  - others: drop
-  class RedactedLogger : public StreamLogger {
+std::unique_ptr makeLogger(llvm::StringRef LogPrefix,
+   llvm::raw_ostream ) {
+  std::unique_ptr Base;
+  if (LogPublic) {
+// Redacted mode:
+//  - messages outside the scope of a request: log fully
+//  - messages tagged [public]: log fully
+//  - errors: log the format string
+//  - others: drop
+class RedactedLogger : public StreamLogger {
+public:
+  using StreamLogger::StreamLogger;
+  void log(Level L, const char *Fmt,
+   const llvm::formatv_object_base ) override {
+if (Context::current().get(CurrentRequest) == nullptr ||
+llvm::StringRef(Fmt).startswith("[public]"))
+  return StreamLogger::log(L, Fmt, Message);
+if (L >= Error)
+  return StreamLogger::log(L, Fmt,
+   llvm::formatv("[redacted] {0}", Fmt));
+  }
+};
+Base = std::make_unique(OS, LogLevel);
+  } else {
+Base = std::make_unique(OS, LogLevel);
+  }
+
+  if (LogPrefix.empty())
+return Base;
+  class PrefixedLogger : public Logger {
+std::string LogPrefix;
+std::unique_ptr Base;
+
   public:
-using StreamLogger::StreamLogger;
+PrefixedLogger(llvm::StringRef LogPrefix, std::unique_ptr Base)
+: LogPrefix(LogPrefix.str()), Base(std::move(Base)) {}
 void log(Level L, const char *Fmt,
  const llvm::formatv_object_base ) override {
-  if (Context::current().get(CurrentRequest) == nullptr ||
-  llvm::StringRef(Fmt).startswith("[public]"))
-return StreamLogger::log(L, Fmt, Message);
-  if (L >= Error)
-return StreamLogger::log(L, Fmt, llvm::formatv("[redacted] {0}", Fmt));
+  Base->log(L, Fmt, llvm::formatv("[{0}] {1}", LogPrefix, Message));
 }
   };
-  return std::make_unique(OS, LogLevel);
+  return std::make_unique(LogPrefix, std::move(Base));
 }
 
 } // namespace
@@ -471,7 +500,7 @@
   llvm::errs().SetBuffered();
   // Don't flush stdout when logging for thread safety.
   llvm::errs().tie(nullptr);
-  auto Logger = makeLogger(llvm::errs());
+  auto Logger = makeLogger(LogPrefix.getValue(), llvm::errs());
   clang::clangd::LoggingSession LoggingSession(*Logger);
 
   llvm::Optional TracerStream;

[clang-tools-extra] 8f2bf93 - [clangd] Introduce a log-prefix flag to remote-index-server

2021-06-25 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-06-25T16:51:29+02:00
New Revision: 8f2bf93b5bd6a1d31e28e4144827b3f6c413ac85

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

LOG: [clangd] Introduce a log-prefix flag to remote-index-server

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

Added: 
clang-tools-extra/clangd/test/remote-index/log-prefix.test

Modified: 
clang-tools-extra/clangd/index/remote/server/Server.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/remote/server/Server.cpp 
b/clang-tools-extra/clangd/index/remote/server/Server.cpp
index 4f4e80b8a4d74..04ad0b2a1936f 100644
--- a/clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ b/clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -37,7 +37,9 @@
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
 
 #if ENABLE_GRPC_REFLECTION
 #include 
@@ -78,6 +80,12 @@ llvm::cl::opt LogPublic{
 llvm::cl::init(false),
 };
 
+llvm::cl::opt LogPrefix{
+"log-prefix",
+llvm::cl::desc("A string that'll be prepended to all log statements. "
+   "Useful when running multiple instances on same host."),
+};
+
 llvm::cl::opt TraceFile(
 "trace-file",
 llvm::cl::desc("Path to the file where tracer logs will be stored"));
@@ -427,27 +435,48 @@ void runServerAndWait(clangd::SymbolIndex , 
llvm::StringRef ServerAddress,
   ServerShutdownWatcher.join();
 }
 
-std::unique_ptr makeLogger(llvm::raw_ostream ) {
-  if (!LogPublic)
-return std::make_unique(OS, LogLevel);
-  // Redacted mode:
-  //  - messages outside the scope of a request: log fully
-  //  - messages tagged [public]: log fully
-  //  - errors: log the format string
-  //  - others: drop
-  class RedactedLogger : public StreamLogger {
+std::unique_ptr makeLogger(llvm::StringRef LogPrefix,
+   llvm::raw_ostream ) {
+  std::unique_ptr Base;
+  if (LogPublic) {
+// Redacted mode:
+//  - messages outside the scope of a request: log fully
+//  - messages tagged [public]: log fully
+//  - errors: log the format string
+//  - others: drop
+class RedactedLogger : public StreamLogger {
+public:
+  using StreamLogger::StreamLogger;
+  void log(Level L, const char *Fmt,
+   const llvm::formatv_object_base ) override {
+if (Context::current().get(CurrentRequest) == nullptr ||
+llvm::StringRef(Fmt).startswith("[public]"))
+  return StreamLogger::log(L, Fmt, Message);
+if (L >= Error)
+  return StreamLogger::log(L, Fmt,
+   llvm::formatv("[redacted] {0}", Fmt));
+  }
+};
+Base = std::make_unique(OS, LogLevel);
+  } else {
+Base = std::make_unique(OS, LogLevel);
+  }
+
+  if (LogPrefix.empty())
+return Base;
+  class PrefixedLogger : public Logger {
+std::string LogPrefix;
+std::unique_ptr Base;
+
   public:
-using StreamLogger::StreamLogger;
+PrefixedLogger(llvm::StringRef LogPrefix, std::unique_ptr Base)
+: LogPrefix(LogPrefix.str()), Base(std::move(Base)) {}
 void log(Level L, const char *Fmt,
  const llvm::formatv_object_base ) override {
-  if (Context::current().get(CurrentRequest) == nullptr ||
-  llvm::StringRef(Fmt).startswith("[public]"))
-return StreamLogger::log(L, Fmt, Message);
-  if (L >= Error)
-return StreamLogger::log(L, Fmt, llvm::formatv("[redacted] {0}", Fmt));
+  Base->log(L, Fmt, llvm::formatv("[{0}] {1}", LogPrefix, Message));
 }
   };
-  return std::make_unique(OS, LogLevel);
+  return std::make_unique(LogPrefix, std::move(Base));
 }
 
 } // namespace
@@ -471,7 +500,7 @@ int main(int argc, char *argv[]) {
   llvm::errs().SetBuffered();
   // Don't flush stdout when logging for thread safety.
   llvm::errs().tie(nullptr);
-  auto Logger = makeLogger(llvm::errs());
+  auto Logger = makeLogger(LogPrefix.getValue(), llvm::errs());
   clang::clangd::LoggingSession LoggingSession(*Logger);
 
   llvm::Optional TracerStream;

diff  --git a/clang-tools-extra/clangd/test/remote-index/log-prefix.test 
b/clang-tools-extra/clangd/test/remote-index/log-prefix.test
new file mode 100644
index 0..fb00576bbd5c4
--- /dev/null
+++ b/clang-tools-extra/clangd/test/remote-index/log-prefix.test
@@ -0,0 +1,18 @@
+# RUN: rm -rf %t
+# RUN: clangd-indexer %S/Inputs/Source.cpp > %t.idx
+# RUN: %python %S/pipeline_helper.py --input-file-name=%s 
--server-arg=--log=verbose --server-arg=-log-prefix=test-prefix 
--server-log=%t.log --project-root=%S --index-file=%t.idx > /dev/null
+# RUN: FileCheck %s < %t.log
+# REQUIRES: clangd-remote-index
+
+# CHECK: [test-prefix] Server listening on

[PATCH] D104841: [clangd] Call malloc_trim in clangd-index-server periodically

2021-06-25 Thread Kadir Cetinkaya 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 rG3aa6ca8def51: [clangd] Call malloc_trim in 
clangd-index-server periodically (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104841

Files:
  clang-tools-extra/clangd/index/remote/server/Server.cpp


Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -43,6 +43,10 @@
 #include 
 #endif
 
+#ifdef __GLIBC__
+#include 
+#endif
+
 namespace clang {
 namespace clangd {
 namespace remote {
@@ -354,12 +358,25 @@
   std::atomic> IndexBuildTime;
 };
 
+void maybeTrimMemory() {
+#if defined(__GLIBC__) && CLANGD_MALLOC_TRIM
+  malloc_trim(0);
+#endif
+}
+
 // Detect changes in \p IndexPath file and load new versions of the index
 // whenever they become available.
 void hotReload(clangd::SwapIndex , llvm::StringRef IndexPath,
llvm::vfs::Status ,
llvm::IntrusiveRefCntPtr ,
Monitor ) {
+  // glibc malloc doesn't shrink an arena if there are items living at the end,
+  // which might happen since we destroy the old index after building new one.
+  // Trim more aggresively to keep memory usage of the server low.
+  // Note that we do it deliberately here rather than after Index.reset(),
+  // because old index might still be kept alive after the reset call if we are
+  // serving requests.
+  maybeTrimMemory();
   auto Status = FS->status(IndexPath);
   // Requested file is same as loaded index: no reload is needed.
   if (!Status || (Status->getLastModificationTime() ==


Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -43,6 +43,10 @@
 #include 
 #endif
 
+#ifdef __GLIBC__
+#include 
+#endif
+
 namespace clang {
 namespace clangd {
 namespace remote {
@@ -354,12 +358,25 @@
   std::atomic> IndexBuildTime;
 };
 
+void maybeTrimMemory() {
+#if defined(__GLIBC__) && CLANGD_MALLOC_TRIM
+  malloc_trim(0);
+#endif
+}
+
 // Detect changes in \p IndexPath file and load new versions of the index
 // whenever they become available.
 void hotReload(clangd::SwapIndex , llvm::StringRef IndexPath,
llvm::vfs::Status ,
llvm::IntrusiveRefCntPtr ,
Monitor ) {
+  // glibc malloc doesn't shrink an arena if there are items living at the end,
+  // which might happen since we destroy the old index after building new one.
+  // Trim more aggresively to keep memory usage of the server low.
+  // Note that we do it deliberately here rather than after Index.reset(),
+  // because old index might still be kept alive after the reset call if we are
+  // serving requests.
+  maybeTrimMemory();
   auto Status = FS->status(IndexPath);
   // Requested file is same as loaded index: no reload is needed.
   if (!Status || (Status->getLastModificationTime() ==
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 3aa6ca8 - [clangd] Call malloc_trim in clangd-index-server periodically

2021-06-25 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-06-25T16:49:31+02:00
New Revision: 3aa6ca8def510b5c10e76899ad9b78f5ba4ea19c

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

LOG: [clangd] Call malloc_trim in clangd-index-server periodically

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

Added: 


Modified: 
clang-tools-extra/clangd/index/remote/server/Server.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/remote/server/Server.cpp 
b/clang-tools-extra/clangd/index/remote/server/Server.cpp
index 7073cc0dc5670..4f4e80b8a4d74 100644
--- a/clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ b/clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -43,6 +43,10 @@
 #include 
 #endif
 
+#ifdef __GLIBC__
+#include 
+#endif
+
 namespace clang {
 namespace clangd {
 namespace remote {
@@ -354,12 +358,25 @@ class Monitor final : public v1::Monitor::Service {
   std::atomic> IndexBuildTime;
 };
 
+void maybeTrimMemory() {
+#if defined(__GLIBC__) && CLANGD_MALLOC_TRIM
+  malloc_trim(0);
+#endif
+}
+
 // Detect changes in \p IndexPath file and load new versions of the index
 // whenever they become available.
 void hotReload(clangd::SwapIndex , llvm::StringRef IndexPath,
llvm::vfs::Status ,
llvm::IntrusiveRefCntPtr ,
Monitor ) {
+  // glibc malloc doesn't shrink an arena if there are items living at the end,
+  // which might happen since we destroy the old index after building new one.
+  // Trim more aggresively to keep memory usage of the server low.
+  // Note that we do it deliberately here rather than after Index.reset(),
+  // because old index might still be kept alive after the reset call if we are
+  // serving requests.
+  maybeTrimMemory();
   auto Status = FS->status(IndexPath);
   // Requested file is same as loaded index: no reload is needed.
   if (!Status || (Status->getLastModificationTime() ==



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


[PATCH] D104616: [analyzer][WIP] Model comparision methods of std::unique_ptr

2021-06-25 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:329
+  return *Ptr;
+return C.getSValBuilder().conjureSymbolVal(
+E, C.getLocationContext(),

In case we conjure a new symbol, we want this stored in the `TrackedRegionMap`. 
So the analyzer can correctly record the constraints between the two symbols. 



Comment at: clang/test/Analysis/smart-ptr.cpp:466
+
+  clang_analyzer_eval(ptr == ptr); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr > ptr);  // expected-warning{{FALSE}}

RedDocMD wrote:
> xazax.hun wrote:
> > Putting tests like this on the same path can be risky. Tests might split 
> > the execution path (maybe not now, but in the future). I think it might be 
> > more future proof to have a large switch statement that switches on an 
> > unknown value and put the tests in separate cases. 
> I didn't quite get you.
You remember this in the other patch:
```
member-constructor.cpp:15:5: warning: FALSE [debug.ExprInspection]
clang_analyzer_eval(*P->p == 0);
^~~
member-constructor.cpp:15:25: note: Assuming the condition is false
clang_analyzer_eval(*P->p == 0);
^~
member-constructor.cpp:15:5: note: FALSE
clang_analyzer_eval(*P->p == 0);
^~~
member-constructor.cpp:15:5: warning: TRUE [debug.ExprInspection]
clang_analyzer_eval(*P->p == 0);
^~~
member-constructor.cpp:15:25: note: Assuming the condition is true
clang_analyzer_eval(*P->p == 0);
^~
member-constructor.cpp:15:5: note: TRUE
clang_analyzer_eval(*P->p == 0);
^~~
2 warnings generated.
```

It looks like this does not happen for overloaded comparison operators at the 
moment. But we might want to do that in the future (@NoW what do you think). I 
was wondering, if we want to future proof these test cases for that behavior. 
But looking at the test cases again, you only have two, where the expected 
result is unknown, and they are at the very end. So feel free to ignore this 
and leave the code as is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104616

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


[PATCH] D103967: [Analyzer][solver] Add dump methods for (dis)equality classes.

2021-06-25 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko accepted this revision.
vsavchenko added a comment.
This revision is now accepted and ready to land.

Awesome, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103967

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


[PATCH] D104917: [Analyzer] Extend exploded-graph-rewriter to support eq and diseq classes

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

LGTM, but I'm not really an expert in `exploded-graph-rewriter`.  I think @NoQ 
should take a look.




Comment at: clang/utils/analyzer/exploded-graph-rewriter.py:299
+self.equivalence_classes = (
+GenericMap({i: ", ".join(eq_classes[i]) for i in range(0, 
len(eq_classes))})
+if eq_classes

I believe that `enumerate` is more idiomatic for Python in situations like this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104917

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


[PATCH] D103986: [PowerPC] Floating Point Builtins for XL Compat.

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

Added non-vsx implementation of builtins and non-vsx backend tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103986

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Basic/Targets/PPC.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-fp.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
  llvm/lib/Target/PowerPC/PPCInstrInfo.td
  llvm/lib/Target/PowerPC/PPCInstrVSX.td
  llvm/test/CodeGen/builtins-ppc-xlcompat-fp.ll

Index: llvm/test/CodeGen/builtins-ppc-xlcompat-fp.ll
===
--- /dev/null
+++ llvm/test/CodeGen/builtins-ppc-xlcompat-fp.ll
@@ -0,0 +1,92 @@
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-unknown \
+; RUN: -mcpu=pwr7 < %s | FileCheck %s --check-prefix=CHECK-PWR7
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-unknown \
+; RUN: -mcpu=pwr8 < %s | FileCheck %s --check-prefix=CHECK-PWR8
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-aix \
+; RUN: -mcpu=pwr7 < %s | FileCheck %s --check-prefix=CHECK-PWR7
+; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-aix \
+; RUN: -mcpu=pwr7 < %s | FileCheck %s --check-prefix=CHECK-PWR7
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-unknown \
+; RUN: -mattr=-vsx -mcpu=pwr7 < %s | FileCheck %s --check-prefix=CHECK-NOVSX
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-unknown \
+; RUN: -mattr=-vsx -mcpu=pwr8 < %s | FileCheck %s --check-prefix=CHECK-NOVSX
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-aix \
+; RUN: -mattr=-vsx -mcpu=pwr7 < %s | FileCheck %s --check-prefix=CHECK-NOVSX
+; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-aix \
+; RUN: -mattr=-vsx -mcpu=pwr7 < %s | FileCheck %s --check-prefix=CHECK-NOVSX
+
+define dso_local double @test_fsel(double %a, double %b, double %c) local_unnamed_addr #0 {
+; CHECK-PWR7-LABEL: test_fsel 
+; CHECK-PWR8-LABEL: test_fsel
+; CHECK-NOVSX-LABEL: test_fsel
+
+entry:
+  %0 = tail call double @llvm.ppc.fsel(double %a, double %b, double %c)
+; CHECK-PWR7: fsel 1, 1, 2, 3
+; CHECK-PWR8: fsel 1, 1, 2, 3
+; CHECK-NOVSX: fsel 1, 1, 2, 3
+
+  ret double %0
+; CHECK-PWR7: blr
+; CHECK-PWR8: blr
+; CHECK-NOVSX: blr
+}
+
+declare double @llvm.ppc.fsel(double, double, double) #2
+
+define dso_local float @test_fsels(float %a, float %b, float %c) local_unnamed_addr #0 {
+; CHECK-PWR7-LABEL: test_fsels
+; CHECK-PWR8-LABEL: test_fsels
+; CHECK-NOVSX-LABEL: test_fsels
+
+entry:
+  %0 = tail call float @llvm.ppc.fsels(float %a, float %b, float %c)
+; CHECK-PWR7: fsel 1, 1, 2, 3
+; CHECK-PWR8: fsel 1, 1, 2, 3
+; CHECK-NOVSX: fsel 1, 1, 2, 3
+
+  ret float %0
+; CHECK-PWR7: blr
+; CHECK-PWR8: blr
+; CHECK-NOVSX: blr
+}
+
+declare float @llvm.ppc.fsels(float, float, float) #2
+
+define dso_local double @test_frsqrte(double %a) local_unnamed_addr #0 {
+; CHECK-PWR7-LABEL: test_frsqrte
+; CHECK-PWR8-LABEL: test_frsqrte
+; CHECK-NOVSX-LABEL: test_frsqrte
+
+entry:
+  %0 = tail call double @llvm.ppc.frsqrte(double %a)
+; CHECK-PWR7: xsrsqrtedp 1, 1
+; CHECK-PWR8: xsrsqrtedp 1, 1
+; CHECK-NOVSX: frsqrte 1, 1
+
+  ret double %0
+; CHECK-PWR7: blr
+; CHECK-PWR8: blr
+; CHECK-NOVSX: blr
+}
+
+declare double @llvm.ppc.frsqrte(double) #2
+
+define dso_local float @test_frsqrtes(float %a) local_unnamed_addr #0 {
+; CHECK-PWR7-LABEL: test_frsqrtes
+; CHECK-PWR8-LABEL: test_frsqrtes
+; CHECK-NOVSX-LABEL: test_frsqrtes
+
+entry:
+  %0 = tail call float @llvm.ppc.frsqrtes(float %a)
+; CHECK-PWR7: frsqrtes 1, 1
+; CHECK-PWR8: xsrsqrtesp 1, 1
+; CHECK-NOVSX: frsqrtes 1, 1 
+
+  ret float %0
+; CHECK-PWR7: blr
+; CHECK-PWR8: blr
+; CHECK-NOVSX: blr
+}
+
+declare float @llvm.ppc.frsqrtes(float) #2
Index: llvm/lib/Target/PowerPC/PPCInstrVSX.td
===
--- llvm/lib/Target/PowerPC/PPCInstrVSX.td
+++ llvm/lib/Target/PowerPC/PPCInstrVSX.td
@@ -2850,6 +2850,8 @@
 def : Pat<(v2i64 (PPCvcmp_rec v2i64:$vA, v2i64:$vB, 199)),
   (VCMPGTUB_rec DblwdCmp.MRGEQ, (v2i64 (XXLXORz)))>;
 } // AddedComplexity = 0
+
+def : Pat<(int_ppc_frsqrte vsfrc:$XB), (XSRSQRTEDP $XB)>;
 } // HasVSX
 
 // Any big endian VSX subtarget.
@@ -3240,6 +3242,8 @@
   (v8i16 (COPY_TO_REGCLASS(XXLEQVOnes), VSRC))>;
 def : Pat<(v16i8 (bitconvert (v16i8 immAllOnesV))),
   (v16i8 (COPY_TO_REGCLASS(XXLEQVOnes), VSRC))>;
+
+def : Pat<(int_ppc_frsqrtes vssrc:$XB), (XSRSQRTESP $XB)>;
 } // HasVSX, HasP8Vector
 
 // Any big endian Power8 VSX subtarget.
Index: llvm/lib/Target/PowerPC/PPCInstrInfo.td
===
--- llvm/lib/Target/PowerPC/PPCInstrInfo.td
+++ llvm/lib/Target/PowerPC/PPCInstrInfo.td
@@ -4382,6 +4382,10 @@
 def : Pat<(i1 (not (trunc i64:$in))),

[PATCH] D104918: [clang-repl] Implement partial translation units and error recovery.

2021-06-25 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev created this revision.
v.g.vassilev added reviewers: rsmith, rjmccall, lhames, teemperor, aprantl, 
sgraenitz, hfinkel.
Herald added subscribers: dexonsmith, kbarton, nemanjai.
v.g.vassilev requested review of this revision.

https://reviews.llvm.org/D96033 contained a discussion regarding efficient 
modeling of error recovery. @rjmccall has outlined the key ideas:

Conceptually, we can split the translation unit into a sequence of partial 
translation units (PTUs). Every declaration will be associated with a unique 
PTU that owns it.

  

The first key insight here is that the owning PTU isn't always the "active" 
(most recent) PTU, and it isn't always the PTU that the declaration "comes 
from". A new declaration (that isn't a redeclaration or specialization of 
anything) does belong to the active PTU. A template specialization, however, 
belongs to the most recent PTU of all the declarations in its signature - 
mostly that means that it can be pulled into a more recent PTU by its template 
arguments.

The second key insight is that processing a PTU might extend an earlier PTU. 
Rolling back the later PTU shouldn't throw that extension away. For example, if 
the second PTU defines a template, and the third PTU requires that template to 
be instantiated at float, that template specialization is still part of the 
second PTU. Similarly, if the fifth PTU uses an inline function belonging to 
the fourth, that definition still belongs to the fourth. When we go to emit 
code in a new PTU, we map each declaration we have to emit back to its owning 
PTU and emit it in a new module for just the extensions to that PTU. We keep 
track of all the modules we've emitted for a PTU so that we can unload them all 
if we decide to roll it back.

  

Most declarations/definitions will only refer to entities from the same or 
earlier PTUs. However, it is possible (primarily by defining a 
previously-declared entity, but also through templates or ADL) for an entity 
that belongs to one PTU to refer to something from a later PTU. We will have to 
keep track of this and prevent unwinding to later PTU when we recognize it.

Fortunately, this should be very rare; and crucially, we don't have to do the 
bookkeeping for this if we've only got one PTU, e.g. in normal compilation. 
Otherwise, PTUs after the first just need to record enough metadata to be able 
to revert any changes they've made to declarations belonging to earlier PTUs, 
e.g. to redeclaration chains or template specialization lists.

It should even eventually be possible for PTUs to provide their own slab 
allocators which can be thrown away as part of rolling back the PTU. We can 
maintain a notion of the active allocator and allocate things like Stmt/Expr 
nodes in it, temporarily changing it to the appropriate PTU whenever we go to 
do something like instantiate a function template. More care will be required 
when allocating declarations and types, though.

We would want the PTU to be efficiently recoverable from a Decl; I'm not sure 
how best to do that. An easy option that would cover most declarations would be 
to make multiple TranslationUnitDecls and parent the declarations 
appropriately, but I don't think that's good enough for things like member 
function templates, since an instantiation of that would still be parented by 
its original class. Maybe we can work this into the DC chain somehow, like how 
lexical DCs are.

  

This patch teaches clang-repl how to recover from errors by disconnecting the 
most recent PTU and update the primary PTU lookup tables. For instance:

  ./clang-repl
  clang-repl> int i = 12; error;
  In file included from <<< inputs >>>:1:
  input_line_0:1:13: error: C++ requires a type specifier for all declarations
  int i = 12; error;
   ^
  error: Parsing failed.
  clang-repl> int i = 13; extern "C" int printf(const char*,...);
  clang-repl> auto r1 = printf("i=%d\n", i);
  i=13
  clang-repl> quit


Repository:
  rC Clang

https://reviews.llvm.org/D104918

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/Redeclarable.h
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/PartialTranslationUnit.h
  clang/include/clang/Interpreter/Transaction.h
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclBase.cpp
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/tools/clang-import-test/clang-import-test.cpp
  clang/unittests/AST/ASTVectorTest.cpp
  clang/unittests/Interpreter/IncrementalProcessingTest.cpp
  

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

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

fixed by 4921ecfc8194c11ec7c659ad1de11da6e8307361 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104505

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


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

2021-06-25 Thread Yaxun Liu 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 rG3193133add7e: [OpenCL] Do not include default header for 
preprocessor output as input (authored by yaxunl).
Herald added a subscriber: ldrumm.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104800

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


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


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

[clang] 4921ecf - [clang] Fix build failure due to _S

2021-06-25 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2021-06-25T10:10:27-04:00
New Revision: 4921ecfc8194c11ec7c659ad1de11da6e8307361

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

LOG: [clang] Fix build failure due to _S

_S is a reserved identifier in  on Solaris.

Added: 


Modified: 
clang/include/clang/Sema/Sema.h

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index d50d2dd83530e..4c3a7035bcc94 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1778,8 +1778,8 @@ class Sema final {
 bool SavedDeferDiags = false;
 
   public:
-DeferDiagsRAII(Sema &_S, bool DeferDiags)
-: S(_S), SavedDeferDiags(S.DeferDiags) {
+DeferDiagsRAII(Sema , bool DeferDiags)
+: S(S), SavedDeferDiags(S.DeferDiags) {
   S.DeferDiags = DeferDiags;
 }
 ~DeferDiagsRAII() { S.DeferDiags = SavedDeferDiags; }



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


[clang] 3193133 - [OpenCL] Do not include default header for preprocessor output as input

2021-06-25 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2021-06-25T10:01:51-04:00
New Revision: 3193133add7eeeaa3872c78aa959bacdc08e59d9

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

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

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

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

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

Reviewed by: Anastasia Stulova

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index f1b5e25525979..a3f0ec577379e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3286,7 +3286,8 @@ static void RenderOpenCLOptions(const ArgList , 
ArgStringList ,
   CmdArgs.push_back(Args.MakeArgString(A->getOption().getPrefixedName()));
 
   // Only add the default headers if we are compiling OpenCL sources.
-  if ((types::isOpenCL(InputType) || Args.hasArg(options::OPT_cl_std_EQ)) &&
+  if ((types::isOpenCL(InputType) ||
+   (Args.hasArg(options::OPT_cl_std_EQ) && types::isSrcFile(InputType))) &&
   !Args.hasArg(options::OPT_cl_no_stdinc)) {
 CmdArgs.push_back("-finclude-default-header");
 CmdArgs.push_back("-fdeclare-opencl-builtins");

diff  --git a/clang/test/Driver/amdgpu-toolchain-opencl.cl 
b/clang/test/Driver/amdgpu-toolchain-opencl.cl
index 3994387f3eadb..152eda1c46927 100644
--- a/clang/test/Driver/amdgpu-toolchain-opencl.cl
+++ b/clang/test/Driver/amdgpu-toolchain-opencl.cl
@@ -7,6 +7,12 @@
 // RUN: %clang -### -target amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm 
-mcpu=fiji -Og %s 2>&1 | FileCheck -check-prefix=CHECK_Og %s
 // RUN: %clang -### -target amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm 
-mcpu=fiji -Ofast %s 2>&1 | FileCheck -check-prefix=CHECK_Ofast %s
 // RUN: %clang -### -target amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm 
-mcpu=fiji %s 2>&1 | FileCheck -check-prefix=CHECK_O_DEFAULT %s
+
+// Check default include file is not included for preprocessor output.
+
+// RUN: %clang -### -target amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm 
-mcpu=fiji %s 2>&1 | FileCheck -check-prefix=CHK-INC %s
+// RUN: %clang -### -target amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm 
-mcpu=fiji -save-temps %s 2>&1 | FileCheck -check-prefix=CHK-INC %s
+
 // CHECK_O0: clang{{.*}} "-O0"
 // CHECK_O1: clang{{.*}} "-O1"
 // CHECK_O2: clang{{.*}} "-O2"
@@ -17,3 +23,5 @@
 // CHECK_Ofast: {{.*}}clang{{.*}} "-Ofast"
 // CHECK_O_DEFAULT: clang{{.*}} "-O3"
 
+// CHK-INC: clang{{.*}} "-cc1" {{.*}}"-finclude-default-header" 
"-fdeclare-opencl-builtins" {{.*}}"-x" "cl"
+// CHK-INC-NOT: clang{{.*}} "-cc1" {{.*}}"-finclude-default-header" 
"-fdeclare-opencl-builtins" {{.*}}"-x" "cpp-output"



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


[PATCH] D103967: [Analyzer][solver] Add dump methods for (dis)equality classes.

2021-06-25 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D103967#2822287 , @steakhal wrote:

> I suspect that the exploded-graph-rewriter should be updated as well so that 
> the HTML dumps also carry this information.

I've put that into a separate patch because that change has its own complexity. 
Plus, I think this patch is meaningful and useful by itself (without the 
exploded-graph-rewriter changes).
https://reviews.llvm.org/D104917


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103967

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


[PATCH] D104917: [Analyzer] Extend exploded-graph-rewriter to support eq and diseq classes

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

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104917

Files:
  clang/utils/analyzer/exploded-graph-rewriter.py


Index: clang/utils/analyzer/exploded-graph-rewriter.py
===
--- clang/utils/analyzer/exploded-graph-rewriter.py
+++ clang/utils/analyzer/exploded-graph-rewriter.py
@@ -267,6 +267,8 @@
 'store': None,
 'environment': None,
 'constraints': None,
+'equivalence_classes': None,
+'disequality_info': None,
 'dynamic_types': None,
 'constructing_objects': None,
 'checker_messages': None
@@ -285,6 +287,39 @@
 (c['symbol'], c['range']) for c in json_ps['constraints']
 ]) if json_ps['constraints'] is not None else None
 
+# Each equivalence_class is represented as List[Str].
+# json_ps['equivalence_classes']: List[List[Str]]
+# Sort by the first element of each equivalence_class.
+eq_classes = (
+sorted(json_ps['equivalence_classes'], key=lambda eqc: eqc[0])
+if json_ps['equivalence_classes']
+else None
+)
+self.equivalence_classes = (
+GenericMap({i: ", ".join(eq_classes[i]) for i in range(0, 
len(eq_classes))})
+if eq_classes
+else None
+)
+
+# Each equivalence_class is represented as List[Str].
+# Disequality info is a mapping from an equivalence class to many
+# equivalence classes:
+# json_ps['disequality_info']: Dict[List[Str], List[List[Str]]]
+def get_diseq_classes(classes):
+""" Flatten List[List[Str]] to Str """
+return "".join([", ".join(cl) for cl in classes])
+
+self.disequality_info = (
+GenericMap(
+{
+", ".join(c["class"]): get_diseq_classes(c["disequal_to"])
+for c in json_ps["disequality_info"]
+}
+)
+if json_ps["disequality_info"]
+else None
+)
+
 self.dynamic_types = GenericMap([
 (t['region'], '%s%s' % (t['dyn_type'],
 ' (or a sub-class)'
@@ -791,6 +826,12 @@
 s, prev_s)
 self.visit_generic_map_in_state('constraints', 'Ranges',
 s, prev_s)
+self.visit_generic_map_in_state('equivalence_classes',
+'Equivalence Classes',
+s, prev_s)
+self.visit_generic_map_in_state('disequality_info',
+'Disequality Info',
+s, prev_s)
 self.visit_generic_map_in_state('dynamic_types', 'Dynamic Types',
 s, prev_s)
 self.visit_environment_in_state('constructing_objects',


Index: clang/utils/analyzer/exploded-graph-rewriter.py
===
--- clang/utils/analyzer/exploded-graph-rewriter.py
+++ clang/utils/analyzer/exploded-graph-rewriter.py
@@ -267,6 +267,8 @@
 'store': None,
 'environment': None,
 'constraints': None,
+'equivalence_classes': None,
+'disequality_info': None,
 'dynamic_types': None,
 'constructing_objects': None,
 'checker_messages': None
@@ -285,6 +287,39 @@
 (c['symbol'], c['range']) for c in json_ps['constraints']
 ]) if json_ps['constraints'] is not None else None
 
+# Each equivalence_class is represented as List[Str].
+# json_ps['equivalence_classes']: List[List[Str]]
+# Sort by the first element of each equivalence_class.
+eq_classes = (
+sorted(json_ps['equivalence_classes'], key=lambda eqc: eqc[0])
+if json_ps['equivalence_classes']
+else None
+)
+self.equivalence_classes = (
+GenericMap({i: ", ".join(eq_classes[i]) for i in range(0, len(eq_classes))})
+if eq_classes
+else None
+)
+
+# Each equivalence_class is represented as List[Str].
+# Disequality info is a mapping from an equivalence class to many
+# equivalence classes:
+# json_ps['disequality_info']: Dict[List[Str], List[List[Str]]]
+def get_diseq_classes(classes):
+ 

[PATCH] D104843: [clangd] Introduce a log-prefix flag to remote-index-server

2021-06-25 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev accepted this revision.
kbobyrev added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104843

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


[PATCH] D102507: [HIP] Support in device code

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

In D102507#2838981 , @tra wrote:

> The key difference between C++ and CUDA/HIP, as implemented in clang, is that 
> `__host__` and `__device__` attributes are considered during function 
> overloading in CUDA and HIP, so `__host__ void foo()`, `__device__ void 
> foo()` and `__host__ __device__ void foo()` are three different functions and 
> not redeclarations of the same function. Details of the original proposal are 
> here:  https://goo.gl/EXnymm.
>
> In D102507#2838776 , @yaxunl wrote:
>
>> 2. Some libc++ functions are mostly common for device or host with minor 
>> differences. For such functions, we can make them `__device__ __host__` and 
>> use `#if __HIP_DEVICE_COMPILE__` (indicating device compilation) for the 
>> minor difference in the function body.
>
> I think we should rely on target overloading when possible, instead of the 
> preprocessor. Minimizing the differences between the code seen by compiler 
> during host and device side compilation will minimize potential issues.
> Which approach we'll end up using is an implementation detail.

Agree.

>> 3. Some libc++ functions have different implementations for device and host. 
>> We can leave these host functions as they are and adding overloaded 
>> `__device__` functions.
>>
>> There are two ways to mark libc++ functions as `__device__ __host__`:
>>
>> 1. Define a macro which expands to empty for non-HIP programs and expands to 
>> `__device__ __host__` for HIP and add it to each libc++ function which is to 
>> be marked as `__device__ __host__`.
>
> One caveat of the overloading based on target attributes is that we can't 
> re-declare a function with `__device__ __host__` as compiler will see 
> attempted redeclaration as a function overload of a function w/o attributes 
> (implicitly `__host__`).

If we keep all the declarations consistent we should be fine.

>> 2. Define macros which expand to empty for non-HIP programs and expand to 
>> `#pragma clang force_cuda_host_device begin/end` for HIP and put them at the 
>> beginning and end of a file where all the functions are to be marked as 
>> `__device__ __host__`.
>>
>> We plan to implement libc++ support in HIP device compilation in a 
>> progressive approach, header by header, and document the supported libc++ 
>> headers. We will prioritize libc++ headers to support based on 1) user 
>> requests 2) whether it has already been supported through clang wrapper 
>> headers (patching) 4) usefulness for device execution 3) availability of 
>> lower level support with HIP runtime.
>
> All of the above applies to CUDA, modulo the macro names and some differences 
> in the builtins and the the functions provided (or not) by runtime on the GPU 
> side.




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

https://reviews.llvm.org/D102507

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


[PATCH] D104847: [Clang][NVPTX] Add NVPTX intrinsics and builtins for CUDA PTX 6.5 and 7.0 WMMA and MMA instructions

2021-06-25 Thread Steffen Larsen via Phabricator via cfe-commits
steffenlarsen marked 4 inline comments as done.
steffenlarsen added a comment.

@tra Thank you for the quick response! I agree with your comments and have made 
changes accordingly.




Comment at: clang/include/clang/Basic/BuiltinsNVPTX.def:762
 
+// Builtins to support double and alternate float WMMA instructions on sm_80
+TARGET_BUILTIN(__dmma_m8n8k4_ld_a, "vd*dC*UiIi", "", AND(SM_80,PTX70))

tra wrote:
> Is this a sufficient set of builtins to compile mma.h in CUDA-11.x?
mma.h was my frame-of-reference for the builtins and I have CUDA 11.3 
(465.19.01) installed, so I would expect it to be.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:16411-16430
 #define MMA_VARIANTS(geom, type) {{ \
+  Intrinsic::nvvm_wmma_##geom##_mma_row_row_##type, \
+  0,\
+  Intrinsic::nvvm_wmma_##geom##_mma_row_col_##type, \
+  0,\
+  Intrinsic::nvvm_wmma_##geom##_mma_col_row_##type, \
+  0,\

tra wrote:
> Nit: satf variants are in the minority. We could  move them to the end of the 
> variant list and rely on default initialization to 0. E.g something like this:
> 
> ```
> unsigned getMMAIntrinsic(int Layout, bool Satf) {
> unsigned Index = Layout + 4*Satf;
> if (Index >= Variants.size())
>   return 0;
> return Variants[Index];
>   }
> #define MMA_VARIANTS(geom, type) 
>   Intrinsic::nvvm_wmma_##geom##_mma_row_row_##type, \
>   Intrinsic::nvvm_wmma_##geom##_mma_row_col_##type, \
>   Intrinsic::nvvm_wmma_##geom##_mma_col_row_##type, \
>   Intrinsic::nvvm_wmma_##geom##_mma_col_col_##type 
> 
> #define MMA_SATF_VARIANTS(geom, type)
>   MMA_VARIANTS(geom, type), \
>   Intrinsic::nvvm_wmma_##geom##_mma_row_row_##type##_satfinite, \
>   Intrinsic::nvvm_wmma_##geom##_mma_row_col_##type##_satfinite, \
>   Intrinsic::nvvm_wmma_##geom##_mma_col_row_##type##_satfinite, \
>   Intrinsic::nvvm_wmma_##geom##_mma_col_col_##type##_satfinite 
> ...
> case NVPTX::BI__hmma_m16n16k16_mma_f16f16:
>   return {8, 8, 4, 4, {{ MMA_SATF_VARIANTS(m16n16k16, f16_f16) }}};
> ...
> case NVPTX::BI__dmma_m8n8k4_mma_f64:
>   return {1, 1, 2, 2, {{MMA_VARIANTS(m8n8k4, f64)}}};
> 
> ```
> 
> Up to you.
I agree, I like this better. In case other options will use the satf parameter 
(e.g. rnd which isn't indicated as being in use from mma.h) this solution is 
also easier to extend in the future.



Comment at: clang/test/CodeGen/builtins-nvptx-mma.py:142-146
+  elif frag.geom == "m16n16k8":
+if frag.frag == "d":
+  prefix = "__mma"
+else:
+  prefix = "__mma_tf32"

tra wrote:
> It's not obvious why  frag `d` is `__mma` and not `__mma_tf32` 
> Can we use frag.ptx_type to make that decision?
We absolutely can. I don't know why that wasn't my first solution.



Comment at: llvm/include/llvm/IR/IntrinsicsNVVM.td:4474
+foreach satf = [0, 1] in {
+  foreach rnd = ["-", "rn", "rz", "rm", "rp"] in {
+foreach op = NVVM_MMA_OPS.all_wmma_ops in {

tra wrote:
> We're often using an empty string to represent a `none`. Comparisons with `-` 
> where we check `rnd` look like we're doing something special there.
> I'd use an empty string for `rnd`, too. 
> 
Empty string works for me. I think there are/were some places that used "-" as 
a default parameter meaning `none`, but I agree with your assessment.


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

https://reviews.llvm.org/D104847

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


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

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

In D104505#2840239 , @ro wrote:

> This patch broke the Solaris/sparcv9 
>  and Solaris/amd64 
>  buildbots:
>
>   
> /opt/llvm-buildbot/home/solaris11-amd64/clang-solaris11-amd64/llvm/clang/include/clang/Sema/Sema.h:1782:11:
>  error: non-const lvalue reference to type 'clang::Sema' cannot bind to a 
> temporary of type 'int'
>   : S(_S), SavedDeferDiags(S.DeferDiags) {
> ^ ~~
>   
> /opt/llvm-buildbot/home/solaris11-amd64/clang-solaris11-amd64/llvm/clang/include/clang/Sema/Sema.h:1782:34:
>  warning: reference 'S' is not yet bound to a value when used here 
> [-Wuninitialized]
>   : S(_S), SavedDeferDiags(S.DeferDiags) {
>^
>   
> /opt/llvm-buildbot/home/solaris11-amd64/clang-solaris11-amd64/llvm/clang/include/clang/Sema/Sema.h:1783:22:
>  error: use of non-static data member 'DeferDiags' of 'Sema' from nested type 
> 'DeferDiagsRAII'
> S.DeferDiags = DeferDiags;
>^~
>   1 warning and 3 errors generated.
>   [173/835] Building CXX object 
> tools/clang/lib/Parse/CMakeFiles/obj.clangParse.dir/ParseDeclCXX.cpp.o
>   FAILED: 
> tools/clang/lib/Parse/CMakeFiles/obj.clangParse.dir/ParseDeclCXX.cpp.o 
>   /opt/llvm/12/bin/clang++  -DCLANG_ROUND_TRIP_CC1_ARGS=ON -DGTEST_HAS_RTTI=0 
> -D_DEBUG -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
> -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/clang/lib/Parse 
> -I/opt/llvm-buildbot/home/solaris11-amd64/clang-solaris11-amd64/llvm/clang/lib/Parse
>  
> -I/opt/llvm-buildbot/home/solaris11-amd64/clang-solaris11-amd64/llvm/clang/include
>  -Itools/clang/include -Iinclude 
> -I/opt/llvm-buildbot/home/solaris11-amd64/clang-solaris11-amd64/llvm/llvm/include
>  
> -I/opt/llvm-buildbot/home/solaris11-amd64/clang-solaris11-amd64/llvm/llvm/include/llvm/Support/Solaris
>  -fPIC -fvisibility-inlines-hidden -Werror=date-time 
> -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
> -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
> -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
> -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
> -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
> -Wmisleading-indentation -fdiagnostics-color -ffunction-sections 
> -fdata-sections -fno-common -Woverloaded-virtual -Wno-nested-anon-types -O3 
> -DNDEBUG-fno-exceptions -fno-rtti -UNDEBUG -std=c++14 -MD -MT 
> tools/clang/lib/Parse/CMakeFiles/obj.clangParse.dir/ParseDeclCXX.cpp.o -MF 
> tools/clang/lib/Parse/CMakeFiles/obj.clangParse.dir/ParseDeclCXX.cpp.o.d -o 
> tools/clang/lib/Parse/CMakeFiles/obj.clangParse.dir/ParseDeclCXX.cpp.o -c 
> /opt/llvm-buildbot/home/solaris11-amd64/clang-solaris11-amd64/llvm/clang/lib/Parse/ParseDeclCXX.cpp
>   In file included from 
> /opt/llvm-buildbot/home/solaris11-amd64/clang-solaris11-amd64/llvm/clang/lib/Parse/ParseDeclCXX.cpp:13:
>   In file included from 
> /opt/llvm-buildbot/home/solaris11-amd64/clang-solaris11-amd64/llvm/clang/include/clang/Parse/Parser.h:24:
>   
> /opt/llvm-buildbot/home/solaris11-amd64/clang-solaris11-amd64/llvm/clang/include/clang/Sema/Sema.h:1781:26:
>  error: expected ')'
>   DeferDiagsRAII(Sema &_S, bool DeferDiags)
>^
>   /usr/include/iso/ctype_iso.h:32:12: note: expanded from macro '_S'
>   #define _S  0x0008  /* Spacing character */
>   ^
>   
> /opt/llvm-buildbot/home/solaris11-amd64/clang-solaris11-amd64/llvm/clang/include/clang/Sema/Sema.h:1781:19:
>  note: to match this '('
>   DeferDiagsRAII(Sema &_S, bool DeferDiags)
> ^
>   
> /opt/llvm-buildbot/home/solaris11-amd64/clang-solaris11-amd64/llvm/clang/include/clang/Sema/Sema.h:1782:11:
>  error: non-const lvalue reference to type 'clang::Sema' cannot bind to a 
> temporary of type 'int'
>   : S(_S), SavedDeferDiags(S.DeferDiags) {
> ^ ~~
>   
> /opt/llvm-buildbot/home/solaris11-amd64/clang-solaris11-amd64/llvm/clang/include/clang/Sema/Sema.h:1782:34:
>  warning: reference 'S' is not yet bound to a value when used here 
> [-Wuninitialized]
>   : S(_S), SavedDeferDiags(S.DeferDiags) {
>^
>   
> /opt/llvm-buildbot/home/solaris11-amd64/clang-solaris11-amd64/llvm/clang/include/clang/Sema/Sema.h:1783:22:
>  error: use of non-static data member 'DeferDiags' of 'Sema' from nested type 
> 'DeferDiagsRAII'
> S.DeferDiags = DeferDiags;
>^~
>   1 warning and 3 errors generated.
>
> `_S` is a reserved identifier in ``.

Thanks for letting me know. I am fixing it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104505


[PATCH] D104915: [OpenCL] Add support of __opencl_c_read_write_images feature macro

2021-06-25 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov created this revision.
azabaznov added reviewers: Anastasia, svenvh.
Herald added subscribers: ldrumm, yaxunl.
Herald added a reviewer: aaron.ballman.
azabaznov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This feature requires support of __opencl_c_images, so diagnostics for that is 
provided as well


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104915

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/opencl-c-3.0.incorrect_options.cl
  clang/test/SemaOpenCL/access-qualifier.cl
  clang/test/SemaOpenCL/unsupported-image.cl

Index: clang/test/SemaOpenCL/unsupported-image.cl
===
--- clang/test/SemaOpenCL/unsupported-image.cl
+++ clang/test/SemaOpenCL/unsupported-image.cl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=-__opencl_c_images %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=-__opencl_c_images,-__opencl_c_read_write_images %s
 // RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images %s
 
 #ifdef __opencl_c_images
Index: clang/test/SemaOpenCL/access-qualifier.cl
===
--- clang/test/SemaOpenCL/access-qualifier.cl
+++ clang/test/SemaOpenCL/access-qualifier.cl
@@ -1,12 +1,14 @@
-// RUN: %clang_cc1 -verify -pedantic -fsyntax-only -cl-std=CL1.2 %s -cl-ext=-cl_khr_3d_image_writes
-// RUN: %clang_cc1 -verify -pedantic -fsyntax-only -cl-std=CL2.0 %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 %s -cl-ext=-cl_khr_3d_image_writes
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL2.0 %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL3.0 %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL3.0 %s -cl-ext=-__opencl_c_read_write_images
 
 typedef image1d_t img1d_ro_default; // expected-note {{previously declared 'read_only' here}}
 
 typedef write_only image1d_t img1d_wo; // expected-note {{previously declared 'write_only' here}}
 typedef read_only image1d_t img1d_ro;
 
-#if __OPENCL_C_VERSION__ >= 200
+#if (__OPENCL_C_VERSION__ == 200) || (__OPENCL_C_VERSION__ == 300 && defined(__opencl_c_read_write_images))
 typedef read_write image1d_t img1d_rw;
 #endif
 
@@ -17,10 +19,10 @@
 void myWrite(write_only image1d_t); // expected-note {{passing argument to parameter here}} expected-note {{passing argument to parameter here}}
 void myRead(read_only image1d_t); // expected-note {{passing argument to parameter here}}
 
-#if __OPENCL_C_VERSION__ >= 200
+#if (__OPENCL_C_VERSION__ == 200) || (__OPENCL_C_VERSION__ == 300 && defined(__opencl_c_read_write_images))
 void myReadWrite(read_write image1d_t);
 #else
-void myReadWrite(read_write image1d_t); // expected-error {{access qualifier 'read_write' can not be used for '__read_write image1d_t' prior to OpenCL version 2.0}}
+void myReadWrite(read_write image1d_t); // expected-error {{access qualifier 'read_write' can not be used for '__read_write image1d_t' prior to OpenCL C version 2.0 or in 3.0 and without __opencl_c_read_write_images feature}}
 #endif
 
 
@@ -36,7 +38,7 @@
   myWrite(img);
 }
 
-#if __OPENCL_C_VERSION__ >= 200
+#if (__OPENCL_C_VERSION__ == 200) || (__OPENCL_C_VERSION__ == 300 && defined(__opencl_c_read_write_images))
 kernel void k4(img1d_rw img) {
   myReadWrite(img);
 }
@@ -62,26 +64,26 @@
 
 kernel void k12(read_only read_only image1d_t i){} // expected-warning {{duplicate 'read_only' declaration specifier}}
 
-#if __OPENCL_C_VERSION__ >= 200
+#if (__OPENCL_C_VERSION__ == 200) || (__OPENCL_C_VERSION__ == 300 && defined(__opencl_c_read_write_images))
 kernel void k13(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'read_only pipe int'}}
 #else
-kernel void k13(__read_write image1d_t i){} // expected-error{{access qualifier '__read_write' can not be used for '__read_write image1d_t' prior to OpenCL version 2.0}}
-#endif
-
-#if __OPENCL_C_VERSION__ >= 200
-void myPipeWrite(write_only pipe int); // expected-note {{passing argument to parameter here}}
-kernel void k14(read_only pipe int p) {
-  myPipeWrite(p); // expected-error {{passing '__private read_only pipe int' to parameter of incompatible type 'write_only pipe int'}}
-}
+kernel void k13(__read_write image1d_t i){} // expected-error{{access qualifier '__read_write' can not be used for '__read_write image1d_t' prior to OpenCL C version 2.0 or in 3.0 and without __opencl_c_read_write_images feature}}
 #endif
 
 #if __OPENCL_C_VERSION__ < 200
 kernel void test_image3d_wo(write_only image3d_t img) {} // 

[PATCH] D104847: [Clang][NVPTX] Add NVPTX intrinsics and builtins for CUDA PTX 6.5 and 7.0 WMMA and MMA instructions

2021-06-25 Thread Steffen Larsen via Phabricator via cfe-commits
steffenlarsen updated this revision to Diff 354487.
steffenlarsen added a comment.

Adjusted for comments and fixed formatting issues.


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

https://reviews.llvm.org/D104847

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-nvptx-mma.cu
  clang/test/CodeGen/builtins-nvptx-mma.py
  llvm/include/llvm/IR/IntrinsicsNVVM.td
  llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
  llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
  llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
  llvm/test/CodeGen/NVPTX/lit.local.cfg
  llvm/test/CodeGen/NVPTX/wmma.py

Index: llvm/test/CodeGen/NVPTX/wmma.py
===
--- llvm/test/CodeGen/NVPTX/wmma.py
+++ llvm/test/CodeGen/NVPTX/wmma.py
@@ -6,7 +6,7 @@
 # RUN: FileCheck %t-ptx60-sm_70.ll < %t-ptx60-sm_70.ll \
 # RUN:   --check-prefixes=INTRINSICS,M16N16
 # RUN: FileCheck %t-ptx60-sm_70.ll < %t-ptx60-sm_70.ll \
-# RUN:   --check-prefixes=INTRINSICS,NOEXTGEOM,NOINT,NOSUBINT,NOMMA
+# RUN:   --check-prefixes=INTRINSICS,NOEXTGEOM,NOINT,NOSUBINT,NOMMA,NODOUBLE,NOALTFLOAT
 # RUN: llc < %t-ptx60-sm_70.ll -march=nvptx64 -mcpu=sm_70 -mattr=+ptx60 \
 # RUN:   | FileCheck %t-ptx60-sm_70.ll
 
@@ -15,7 +15,7 @@
 # RUN: FileCheck %t-ptx61-sm_70.ll < %t-ptx61-sm_70.ll \
 # RUN:   --check-prefixes=INTRINSICS,M16N16,EXTGEOM
 # RUN: FileCheck %t-ptx61-sm_70.ll < %t-ptx61-sm_70.ll \
-# RUN:   --check-prefixes=INTRINSICS,NOINT,NOSUBINT,NOMMA
+# RUN:   --check-prefixes=INTRINSICS,NOINT,NOSUBINT,NOMMA,NODOUBLE,NOALTFLOAT
 # RUN: llc < %t-ptx61-sm_70.ll -march=nvptx64 -mcpu=sm_70 -mattr=+ptx61 \
 # RUN:   | FileCheck %t-ptx61-sm_70.ll
 
@@ -24,7 +24,7 @@
 # RUN: FileCheck %t-ptx63-sm_72.ll < %t-ptx63-sm_72.ll \
 # RUN:   --check-prefixes=INTRINSICS,M16N16,EXTGEOM,INT
 # RUN: FileCheck %t-ptx63-sm_72.ll < %t-ptx63-sm_72.ll \
-# RUN:   --check-prefixes=INTRINSICS,NOSUBINT,NOMMA
+# RUN:   --check-prefixes=INTRINSICS,NOSUBINT,NOMMA,NODOUBLE,NOALTFLOAT
 # RUN: llc < %t-ptx63-sm_72.ll -march=nvptx64 -mcpu=sm_72 -mattr=+ptx63 \
 # RUN:   | FileCheck %t-ptx63-sm_72.ll
 
@@ -33,7 +33,7 @@
 # RUN: FileCheck %t-ptx63-sm_75.ll < %t-ptx63-sm_75.ll \
 # RUN:   --check-prefixes=INTRINSICS,M16N16,EXTGEOM,INT,SUBINT
 # RUN: FileCheck %t-ptx63-sm_75.ll < %t-ptx63-sm_75.ll \
-# RUN:   --check-prefixes=INTRINSICS,NOMMA
+# RUN:   --check-prefixes=INTRINSICS,NOMMA,NODOUBLE,NOALTFLOAT
 # RUN: llc < %t-ptx63-sm_75.ll -march=nvptx64 -mcpu=sm_75 -mattr=+ptx63 \
 # RUN:   | FileCheck %t-ptx63-sm_75.ll
 
@@ -42,10 +42,28 @@
 # RUN: FileCheck %t-ptx64-sm_70.ll < %t-ptx64-sm_70.ll \
 # RUN:   --check-prefixes=INTRINSICS,M16N16,EXTGEOM,MMA
 # RUN: FileCheck %t-ptx64-sm_70.ll < %t-ptx64-sm_70.ll \
-# RUN:   --check-prefixes=INTRINSICS,NOINT,NOSUBINT
+# RUN:   --check-prefixes=INTRINSICS,NOINT,NOSUBINT,NODOUBLE,NOALTFLOAT
 # RUN: llc < %t-ptx64-sm_70.ll -march=nvptx64 -mcpu=sm_70 -mattr=+ptx64 \
 # RUN:   | FileCheck %t-ptx64-sm_70.ll
 
+# Check all variants of instructions supported by PTX65 on SM75+
+# RUN: python %s --ptx=65 --gpu-arch=75 > %t-ptx65-sm_75.ll
+# RUN: FileCheck %t-ptx65-sm_75.ll < %t-ptx65-sm_75.ll \
+# RUN:   --check-prefixes=INTRINSICS,M16N16,EXTGEOM,INT,SUBINT,MMA,PTX65MMA
+# RUN: FileCheck %t-ptx65-sm_75.ll < %t-ptx65-sm_75.ll \
+# RUN:   --check-prefixes=INTRINSICS
+# RUN: llc < %t-ptx65-sm_75.ll -march=nvptx64 -mcpu=sm_75 -mattr=+ptx65 \
+# RUN:   | FileCheck %t-ptx65-sm_75.ll
+
+# Check all variants of instructions supported by PTX70 on SM80+
+# RUN: python %s --ptx=70 --gpu-arch=80 > %t-ptx70-sm_80.ll
+# RUN: FileCheck %t-ptx70-sm_80.ll < %t-ptx70-sm_80.ll \
+# RUN:   --check-prefixes=INTRINSICS,M16N16,EXTGEOM,INT,SUBINT,MMA,ALTFLOAT,DOUBLE,PTX65MMA,PTX70MMA
+# RUN: FileCheck %t-ptx70-sm_80.ll < %t-ptx70-sm_80.ll \
+# RUN:   --check-prefixes=INTRINSICS
+# RUN: llc < %t-ptx70-sm_80.ll -march=nvptx64 -mcpu=sm_80 -mattr=+ptx70 \
+# RUN:   | FileCheck %t-ptx70-sm_80.ll
+
 from __future__ import print_function
 
 import argparse
@@ -56,19 +74,23 @@
   def __init__(self, ptx_type):
 self.ptx_type = ptx_type
 self.llvm_type = {
-"f16" : "<2 x half>",
-"f32" : "float",
-"s32" : "i32",
-"s8"  : "i32",
-"u8"  : "i32",
-"s4"  : "i32",
-"u4"  : "i32",
-"b1"  : "i32",
+"f16"  : "<2 x half>",
+"f32"  : "float",
+"f64"  : "double",
+"s32"  : "i32",
+"s8"   : "i32",
+"u8"   : "i32",
+"s4"   : "i32",
+"u4"   : "i32",
+"b1"   : "i32",
+"bf16" : "i32",
+"tf32" : "i32",
 }[ptx_type];
 
 self.ptx_reg_pattern = {
 "f16" : "%hh[0-9]+",
 "f32" : "%f[0-9]+",
+"f64" : "%fd[0-9]+",

[PATCH] D104904: [OpenMP][AMDGCN] Initial math headers support

2021-06-25 Thread Siu Chi Chan via Phabricator via cfe-commits
scchan added inline comments.



Comment at: clang/lib/Headers/__clang_hip_cmath.h:29
+#ifdef __OPENMP_AMDGCN__
+#define __DEVICE__ static constexpr __attribute__((always_inline, nothrow))
+#define __constant__ __attribute__((constant))

`__DEVICE__` should not imply constexpr.  It should be added to each function 
separately.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104904

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


[PATCH] D104904: [OpenMP][AMDGCN] Initial math headers support

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

LGTM for HIP header changes. Pls make sure it passes internal CI (ePSDB).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104904

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


[PATCH] D104716: [analyzer] Fix assertion failure on code with transparent unions

2021-06-25 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko updated this revision to Diff 354481.
vsavchenko marked 2 inline comments as done.
vsavchenko added a comment.

Remove printState from the test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104716

Files:
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/test/Analysis/transparent_union_bug.c

Index: clang/test/Analysis/transparent_union_bug.c
===
--- /dev/null
+++ clang/test/Analysis/transparent_union_bug.c
@@ -0,0 +1,40 @@
+// RUN: %clang_analyze_cc1 -analyze -triple x86_64-apple-darwin10 \
+// RUN:  -analyzer-checker=core,debug.ExprInspection -verify %s
+
+void clang_analyzer_warnIfReached();
+
+typedef struct {
+  int value;
+} Struct;
+
+typedef union {
+  Struct *ptr;
+  long num;
+} __attribute__((transparent_union)) Alias;
+
+void foo(Struct *x);
+void foo(Alias y) {
+  if (y.ptr == 0) {
+// no-crash
+  }
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+void foobar(long z);
+void foobar(Alias z) {
+  if (z.num != 42) {
+// no-crash
+  }
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+
+void foobaz(Alias x) {
+  if (x.ptr == 0) {
+// no-crash
+  }
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+void bar(Struct arg) {
+  foo();
+  foobar(42);
+  foobaz();
+}
Index: clang/lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -47,6 +47,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/ImmutableList.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/PointerIntPair.h"
@@ -466,6 +467,42 @@
   llvm_unreachable("unknown callable kind");
 }
 
+static bool isTransparentUnion(QualType T) {
+  const RecordType *UT = T->getAsUnionType();
+  return UT && UT->getDecl()->hasAttr();
+}
+
+// In some cases, symbolic cases should be transformed before we associate
+// them with parameters.  This function incapsulates such cases.
+static SVal processArgument(SVal Value, const Expr *ArgumentExpr,
+const ParmVarDecl *Parameter, SValBuilder ) {
+  QualType ParamType = Parameter->getType();
+  QualType ArgumentType = ArgumentExpr->getType();
+
+  // Transparent unions allow users to easily convert values of union field
+  // types into union-typed objects.
+  //
+  // Also, more importantly, they allow users to define functions with different
+  // different parameter types, substituting types matching transparent union
+  // field types with the union type itself.
+  //
+  // Here, we check specifically for latter cases and prevent binding
+  // field-typed values to union-typed regions.
+  if (isTransparentUnion(ParamType) &&
+  // Let's check that we indeed trying to bind different types.
+  !isTransparentUnion(ArgumentType)) {
+BasicValueFactory  = SVB.getBasicValueFactory();
+
+llvm::ImmutableList CompoundSVals = BVF.getEmptySValList();
+CompoundSVals = BVF.prependSVal(Value, CompoundSVals);
+
+// Wrap it with compound value.
+return SVB.makeCompoundVal(ParamType, CompoundSVals);
+  }
+
+  return Value;
+}
+
 static void addParameterValuesToBindings(const StackFrameContext *CalleeCtx,
  CallEvent::BindingsTy ,
  SValBuilder ,
@@ -490,10 +527,12 @@
 // determined in compile-time but not represented as arg-expressions,
 // which makes getArgSVal() fail and return UnknownVal.
 SVal ArgVal = Call.getArgSVal(Idx);
+const Expr *ArgExpr = Call.getArgExpr(Idx);
 if (!ArgVal.isUnknown()) {
   Loc ParamLoc = SVB.makeLoc(
   MRMgr.getParamVarRegion(Call.getOriginExpr(), Idx, CalleeCtx));
-  Bindings.push_back(std::make_pair(ParamLoc, ArgVal));
+  Bindings.push_back(
+  std::make_pair(ParamLoc, processArgument(ArgVal, ArgExpr, *I, SVB)));
 }
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104716: [analyzer] Fix assertion failure on code with transparent unions

2021-06-25 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko updated this revision to Diff 354480.
vsavchenko added a comment.

Use argument expression's type instead of SVal's type


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104716

Files:
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/test/Analysis/transparent_union_bug.c

Index: clang/test/Analysis/transparent_union_bug.c
===
--- /dev/null
+++ clang/test/Analysis/transparent_union_bug.c
@@ -0,0 +1,42 @@
+// RUN: %clang_analyze_cc1 -analyze -triple x86_64-apple-darwin10 \
+// RUN:  -analyzer-checker=core,debug.ExprInspection -verify %s
+
+void clang_analyzer_warnIfReached();
+void clang_analyzer_printState();
+
+typedef struct {
+  int value;
+} Struct;
+
+typedef union {
+  Struct *ptr;
+  long num;
+} __attribute__((transparent_union)) Alias;
+
+void foo(Struct *x);
+void foo(Alias y) {
+  if (y.ptr == 0) {
+// no-crash
+  }
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+void foobar(long z);
+void foobar(Alias z) {
+  clang_analyzer_printState();
+  if (z.num != 42) {
+// no-crash
+  }
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+
+void foobaz(Alias x) {
+  if (x.ptr == 0) {
+// no-crash
+  }
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+void bar(Struct arg) {
+  foo();
+  foobar(42);
+  foobaz();
+}
Index: clang/lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -47,6 +47,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/ImmutableList.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/PointerIntPair.h"
@@ -466,6 +467,42 @@
   llvm_unreachable("unknown callable kind");
 }
 
+static bool isTransparentUnion(QualType T) {
+  const RecordType *UT = T->getAsUnionType();
+  return UT && UT->getDecl()->hasAttr();
+}
+
+// In some cases, symbolic cases should be transformed before we associate
+// them with parameters.  This function incapsulates such cases.
+static SVal processArgument(SVal Value, const Expr *ArgumentExpr,
+const ParmVarDecl *Parameter, SValBuilder ) {
+  QualType ParamType = Parameter->getType();
+  QualType ArgumentType = ArgumentExpr->getType();
+
+  // Transparent unions allow users to easily convert values of union field
+  // types into union-typed objects.
+  //
+  // Also, more importantly, they allow users to define functions with different
+  // different parameter types, substituting types matching transparent union
+  // field types with the union type itself.
+  //
+  // Here, we check specifically for latter cases and prevent binding
+  // field-typed values to union-typed regions.
+  if (isTransparentUnion(ParamType) &&
+  // Let's check that we indeed trying to bind different types.
+  !isTransparentUnion(ArgumentType)) {
+BasicValueFactory  = SVB.getBasicValueFactory();
+
+llvm::ImmutableList CompoundSVals = BVF.getEmptySValList();
+CompoundSVals = BVF.prependSVal(Value, CompoundSVals);
+
+// Wrap it with compound value.
+return SVB.makeCompoundVal(ParamType, CompoundSVals);
+  }
+
+  return Value;
+}
+
 static void addParameterValuesToBindings(const StackFrameContext *CalleeCtx,
  CallEvent::BindingsTy ,
  SValBuilder ,
@@ -490,10 +527,12 @@
 // determined in compile-time but not represented as arg-expressions,
 // which makes getArgSVal() fail and return UnknownVal.
 SVal ArgVal = Call.getArgSVal(Idx);
+const Expr *ArgExpr = Call.getArgExpr(Idx);
 if (!ArgVal.isUnknown()) {
   Loc ParamLoc = SVB.makeLoc(
   MRMgr.getParamVarRegion(Call.getOriginExpr(), Idx, CalleeCtx));
-  Bindings.push_back(std::make_pair(ParamLoc, ArgVal));
+  Bindings.push_back(
+  std::make_pair(ParamLoc, processArgument(ArgVal, ArgExpr, *I, SVB)));
 }
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104647: [analyzer] Support SVal::getType for pointer-to-member values

2021-06-25 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko updated this revision to Diff 354479.
vsavchenko added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104647

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
  clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/lib/StaticAnalyzer/Core/SVals.cpp
  clang/unittests/StaticAnalyzer/SValTest.cpp

Index: clang/unittests/StaticAnalyzer/SValTest.cpp
===
--- clang/unittests/StaticAnalyzer/SValTest.cpp
+++ clang/unittests/StaticAnalyzer/SValTest.cpp
@@ -361,6 +361,41 @@
   EXPECT_EQ(Context.VoidPtrTy, B.getType(Context));
 }
 
+SVAL_TEST(GetMemberPtrType, R"(
+struct A {
+  int a;
+  struct {
+int b;
+  };
+};
+void foo(int A::*x) {
+  int A::*a = ::a;
+  int A::*b = ::b;
+  int A::*c = x;
+}
+)") {
+  SVal A = getByName("a");
+  ASSERT_FALSE(A.getType(Context).isNull());
+  const auto *AMemberPtrTy = dyn_cast(A.getType(Context));
+  ASSERT_NE(AMemberPtrTy, nullptr);
+  EXPECT_EQ(Context.IntTy, AMemberPtrTy->getPointeeType());
+  const auto *ARecordType = dyn_cast(AMemberPtrTy->getClass());
+  ASSERT_NE(ARecordType, nullptr);
+  EXPECT_EQ("A", ARecordType->getDecl()->getName());
+
+  SVal B = getByName("b");
+  ASSERT_FALSE(B.getType(Context).isNull());
+  const auto *BMemberPtrTy = dyn_cast(B.getType(Context));
+  ASSERT_NE(BMemberPtrTy, nullptr);
+  EXPECT_EQ(Context.IntTy, BMemberPtrTy->getPointeeType());
+  const auto *BRecordType = dyn_cast(BMemberPtrTy->getClass());
+  ASSERT_NE(BRecordType, nullptr);
+  EXPECT_EQ("A", BRecordType->getDecl()->getName());
+
+  SVal C = getByName("c");
+  EXPECT_TRUE(C.isUnknown());
+}
+
 } // namespace
 } // namespace ento
 } // namespace clang
Index: clang/lib/StaticAnalyzer/Core/SVals.cpp
===
--- clang/lib/StaticAnalyzer/Core/SVals.cpp
+++ clang/lib/StaticAnalyzer/Core/SVals.cpp
@@ -180,6 +180,9 @@
   QualType VisitNonLocSymbolVal(nonloc::SymbolVal SV) {
 return Visit(SV.getSymbol());
   }
+  QualType VisitNonLocPointerToMember(nonloc::PointerToMember PTM) {
+return PTM.getType();
+  }
   QualType VisitSymbolicRegion(const SymbolicRegion *SR) {
 return Visit(SR->getSymbol());
   }
@@ -209,21 +212,21 @@
 }
 
 bool nonloc::PointerToMember::isNullMemberPointer() const {
-  return getPTMData().isNull();
+  return getPTMData() == nullptr;
 }
 
 const NamedDecl *nonloc::PointerToMember::getDecl() const {
-  const auto PTMD = this->getPTMData();
-  if (PTMD.isNull())
+  if (!getPTMData())
 return nullptr;
 
-  const NamedDecl *ND = nullptr;
-  if (PTMD.is())
-ND = PTMD.get();
-  else
-ND = PTMD.get()->getDeclaratorDecl();
+  return getPTMData()->getDeclaratorDecl();
+}
 
-  return ND;
+QualType nonloc::PointerToMember::getType() const {
+  if (!getPTMData())
+return {};
+
+  return getPTMData()->getType();
 }
 
 //===--===//
@@ -239,17 +242,11 @@
 }
 
 nonloc::PointerToMember::iterator nonloc::PointerToMember::begin() const {
-  const PTMDataType PTMD = getPTMData();
-  if (PTMD.is())
-return {};
-  return PTMD.get()->begin();
+  return getPTMData()->begin();
 }
 
 nonloc::PointerToMember::iterator nonloc::PointerToMember::end() const {
-  const PTMDataType PTMD = getPTMData();
-  if (PTMD.is())
-return {};
-  return PTMD.get()->end();
+  return getPTMData()->end();
 }
 
 //===--===//
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -236,7 +236,7 @@
   return nonloc::SymbolVal(sym);
 }
 
-DefinedSVal SValBuilder::getMemberPointer(const NamedDecl *ND) {
+DefinedSVal SValBuilder::getMemberPointer(const NamedDecl *ND, QualType T) {
   assert(!ND || isa(ND) || isa(ND) ||
  isa(ND));
 
@@ -250,7 +250,8 @@
   return getFunctionPointer(MD);
   }
 
-  return nonloc::PointerToMember(ND);
+  return nonloc::PointerToMember(
+  ND ? getBasicValueFactory().getPointerToMemberData(ND, T) : nullptr);
 }
 
 DefinedSVal SValBuilder::getFunctionPointer(const FunctionDecl *func) {
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -516,7 +516,7 @@
 continue;
   }
   case CK_NullToMemberPointer: {
-SVal V = 

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

2021-06-25 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.

Looks acceptable to me as well. Thanks!


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

https://reviews.llvm.org/D75041

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


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

2021-06-25 Thread Whisperity via Phabricator via cfe-commits
whisperity added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp:249
+  /// the conversion sequence. This method does **NOT** return Begin and End.
+  SmallVector getInvolvedTypesInSequence() const {
+SmallVector Ret;

aaron.ballman wrote:
> Return a `SmallVectorImpl` so that the size of the vector doesn't 
> matter to callers?
Meh... that seems to only work if the context is polymorphic, like reference 
parameters or pointers... This tries to return by value and construct, which is 
not possible for `Impl`.


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

https://reviews.llvm.org/D75041

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


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

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

**NFC** Fix nits.

Let's have one final run with the buildbots, just in case.


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

https://reviews.llvm.org/D75041

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

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c
@@ -3,7 +3,8 @@
 // RUN: {key: bugprone-easily-swappable-parameters.MinimumLength, value: 2}, \
 // RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterNames, value: ""}, \
 // RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes, value: "bool;MyBool;struct U;MAKE_LOGICAL_TYPE(int)"}, \
-// RUN: {key: bugprone-easily-swappable-parameters.QualifiersMix, value: 0} \
+// RUN: {key: bugprone-easily-swappable-parameters.QualifiersMix, value: 0}, \
+// RUN: {key: bugprone-easily-swappable-parameters.ModelImplicitConversions, value: 0} \
 // RUN:  ]}' -- -x c
 
 #define bool _Bool
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-qualifiermixing.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-qualifiermixing.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-qualifiermixing.cpp
@@ -3,7 +3,8 @@
 // RUN: {key: bugprone-easily-swappable-parameters.MinimumLength, value: 2}, \
 // RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterNames, value: ""}, \
 // RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes, value: ""}, \
-// RUN: {key: bugprone-easily-swappable-parameters.QualifiersMix, value: 1} \
+// RUN: {key: bugprone-easily-swappable-parameters.QualifiersMix, value: 1}, \
+// RUN: {key: bugprone-easily-swappable-parameters.ModelImplicitConversions, value: 0} \
 // RUN:  ]}' --
 
 typedef int MyInt1;
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len3.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len3.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len3.cpp
@@ -3,7 +3,8 @@
 // RUN: {key: bugprone-easily-swappable-parameters.MinimumLength, value: 3}, \
 // RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterNames, value: ""}, \
 // RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes, value: ""}, \
-// RUN: {key: bugprone-easily-swappable-parameters.QualifiersMix, value: 0} \
+// RUN: {key: bugprone-easily-swappable-parameters.QualifiersMix, value: 0}, \
+// RUN: {key: bugprone-easily-swappable-parameters.ModelImplicitConversions, value: 0} \
 // RUN:  ]}' --
 
 int add(int Left, int Right) { return Left + Right; } // NO-WARN: Only 2 parameters.
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
@@ -3,7 +3,8 @@
 // RUN: {key: bugprone-easily-swappable-parameters.MinimumLength, value: 2}, \
 // RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterNames, value: ""}, \
 // RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes, value: ""}, \
-// RUN: {key: bugprone-easily-swappable-parameters.QualifiersMix, value: 0} \
+// RUN: 

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

2021-06-25 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko updated this revision to Diff 354475.
vsavchenko marked 9 inline comments as done.
vsavchenko added a comment.

Address comments from review


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104550

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
  clang/lib/StaticAnalyzer/Core/SVals.cpp
  clang/unittests/StaticAnalyzer/CMakeLists.txt
  clang/unittests/StaticAnalyzer/SValTest.cpp

Index: clang/unittests/StaticAnalyzer/SValTest.cpp
===
--- /dev/null
+++ clang/unittests/StaticAnalyzer/SValTest.cpp
@@ -0,0 +1,366 @@
+//===- unittests/StaticAnalyzer/SvalTest.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CheckerRegistration.h"
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclGroup.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
+#include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h"
+#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+
+// getType() tests include whole bunch of type comparisons,
+// so when something is wrong, it's good to have gtest telling us
+// what are those types.
+LLVM_ATTRIBUTE_UNUSED std::ostream <<(std::ostream ,
+   const QualType ) {
+  return OS << T.getAsString();
+}
+
+LLVM_ATTRIBUTE_UNUSED std::ostream <<(std::ostream ,
+   const CanQualType ) {
+  return OS << QualType{T};
+}
+
+namespace ento {
+namespace {
+
+//===--===//
+//   Testing framework implementation
+//===--===//
+
+/// A simple map from variable names to symbolic values used to init them.
+using SVals = llvm::StringMap;
+
+/// SValCollector is the barebone of all tests.
+///
+/// It is implemented as a checker and reacts to binds, so we find
+/// symbolic values of interest, and to end analysis, where we actually
+/// can test whatever we gathered.
+class SValCollector : public Checker {
+public:
+  void checkBind(SVal Loc, SVal Val, const Stmt *S, CheckerContext ) const {
+// Skip instantly if we finished testing.
+// Also, we care only for binds happening in variable initializations.
+if (Tested || !isa(S))
+  return;
+
+if (const auto *VR = llvm::dyn_cast_or_null(Loc.getAsRegion())) {
+  CollectedSVals[VR->getDescriptiveName(false)] = Val;
+}
+  }
+
+  void checkEndAnalysis(ExplodedGraph , BugReporter ,
+ExprEngine ) const {
+if (!Tested) {
+  test(Engine, Engine.getContext());
+  Tested = true;
+  CollectedSVals.clear();
+}
+  }
+
+  /// Helper function for tests to access bound symbolic values.
+  SVal getByName(StringRef Name) const { return CollectedSVals[Name]; }
+
+private:
+  /// Entry point for tests.
+  virtual void test(ExprEngine , const ASTContext ) const = 0;
+
+  mutable bool Tested = false;
+  mutable SVals CollectedSVals;
+};
+
+// SVAL_TEST is a combined way of providing a short code snippet and
+// to test some programmatic predicates on symbolic values produced by the
+// engine for the actual code.
+//
+// Each test has a NAME.  One can think of it as a name for normal gtests.
+//
+// Each test should provide a CODE snippet.  Code snippets might contain any
+// valid C/C++, but have ONLY ONE defined function.  There are no requirements
+// about function's name or parameters.  It can even be a class method.  The
+// body of the function must contain a set of variable declarations.  Each
+// variable declaration gets bound to a symbolic value, so for the following
+// example:
+//
+// int x = ;
+//
+// `x` will be bound to whatever symbolic value the engine produced for .
+// LIVENESS and REASSIGNMENTS don't affect this binding.
+//
+// During the test the actual values can be accessed via `getByName` function,
+// 

[clang] 2a7bb84 - [flang][driver] Add `-fno-analyzed-objects-for-unparse`

2021-06-25 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2021-06-25T13:28:12+01:00
New Revision: 2a7bb8494e9c58b44ad7142d8d309455cd669603

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

LOG: [flang][driver] Add `-fno-analyzed-objects-for-unparse`

This patch adds a new option for the new Flang driver:
`-fno-analyzed-objects-for-unparse`. The semantics are similar to
`-funparse-typed-exprs-to-f18-fc` from `f18`. For consistency, the
latter is replaced with `-fno-analyzed-objects-for-unparse`.

The new option controls the behaviour of the unparser (i.e. the action
corresponding to `-fdebug-unparse`). The default behaviour is to use the
analyzed objects when unparsing. The new flag can be used to turn this
off, so that the original parse-tree objects are used. The analyzed
objects are generated during the semantic checks [1].

This patch also updates the semantics of
`-fno-analyzed-objects-for-unparse`/`-funparse-typed-exprs-to-f18-fc`
in `f18`, so that this flag is always taken into account when `Unparse`
is used (this way the semantics in `f18` and `flang-new` are identical).

The added test file is based on example from Peter Steinfeld.

[1]
https://github.com/llvm/llvm-project/blob/main/flang/docs/Semantics.md

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

Added: 
flang/test/Driver/unparse-use-analyzed.f95

Modified: 
clang/include/clang/Driver/Options.td
flang/include/flang/Frontend/CompilerInvocation.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/lib/Frontend/FrontendOptions.cpp
flang/test/Driver/driver-help.f90
flang/tools/f18/f18.cpp
flang/tools/f18/flang

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index cddc924dacd2e..0122afd2eeada 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4536,6 +4536,11 @@ def fget_symbols_sources : Flag<["-"], 
"fget-symbols-sources">, Group,  Group, 
MetaVarName<"">,
   HelpText<"Use  as the suffix for module files (the default value is 
`.mod`)">;
+def fanalyzed_objects_for_unparse : Flag<["-"],
+  "fanalyzed-objects-for-unparse">,  Group;
+def fno_analyzed_objects_for_unparse : Flag<["-"],
+  "fno-analyzed-objects-for-unparse">,  Group,
+  HelpText<"Do not use the analyzed objects when unparsing">;
 
 }
 

diff  --git a/flang/include/flang/Frontend/CompilerInvocation.h 
b/flang/include/flang/Frontend/CompilerInvocation.h
index f449a69dfa8a0..ad25c39b48507 100644
--- a/flang/include/flang/Frontend/CompilerInvocation.h
+++ b/flang/include/flang/Frontend/CompilerInvocation.h
@@ -75,11 +75,39 @@ class CompilerInvocation : public CompilerInvocationBase {
 
   bool warnAsErr_ = false;
 
+  /// This flag controls the unparsing and is used to decide whether to print 
out
+  /// the semantically analyzed version of an object or expression or the plain
+  /// version that does not include any information from semantic analysis.
+  bool useAnalyzedObjectsForUnparse_ = true;
+
   // Fortran Dialect options
   Fortran::common::IntrinsicTypeDefaultKinds defaultKinds_;
 
   bool EnableConformanceChecks_ = false;
 
+  /// Used in e.g. unparsing to dump the analyzed rather than the original
+  /// parse-tree objects.
+  Fortran::parser::AnalyzedObjectsAsFortran AsFortran_{
+  [](llvm::raw_ostream , const Fortran::evaluate::GenericExprWrapper ) 
{
+if (x.v) {
+  x.v->AsFortran(o);
+} else {
+  o << "(bad expression)";
+}
+  },
+  [](llvm::raw_ostream ,
+  const Fortran::evaluate::GenericAssignmentWrapper ) {
+if (x.v) {
+  x.v->AsFortran(o);
+} else {
+  o << "(bad assignment)";
+}
+  },
+  [](llvm::raw_ostream , const Fortran::evaluate::ProcedureRef ) {
+x.AsFortran(o << "CALL ");
+  },
+  };
+
 public:
   CompilerInvocation() = default;
 
@@ -108,11 +136,21 @@ class CompilerInvocation : public CompilerInvocationBase {
   bool () { return warnAsErr_; }
   const bool () const { return warnAsErr_; }
 
+  bool () { return useAnalyzedObjectsForUnparse_; 
}
+  const bool () const {
+return useAnalyzedObjectsForUnparse_;
+  }
+
   bool () { return EnableConformanceChecks_; }
   const bool () const {
 return EnableConformanceChecks_;
   }
 
+  Fortran::parser::AnalyzedObjectsAsFortran () { return AsFortran_; }
+  const Fortran::parser::AnalyzedObjectsAsFortran () const {
+return AsFortran_;
+  }
+
   Fortran::common::IntrinsicTypeDefaultKinds () {
 return defaultKinds_;
   }
@@ -142,6 +180,10 @@ class CompilerInvocation : public CompilerInvocationBase {
 
   void SetWarnAsErr(bool flag) { warnAsErr_ = flag; }
 
+  void SetUseAnalyzedObjectsForUnparse(bool flag) {

[PATCH] D103612: [flang][driver] Add `-fno-analyzed-objects-for-unparse`

2021-06-25 Thread Andrzej Warzynski via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2a7bb8494e9c: [flang][driver] Add 
`-fno-analyzed-objects-for-unparse` (authored by awarzynski).

Changed prior to commit:
  https://reviews.llvm.org/D103612?vs=354294=354474#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103612

Files:
  clang/include/clang/Driver/Options.td
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/Frontend/FrontendOptions.cpp
  flang/test/Driver/driver-help.f90
  flang/test/Driver/unparse-use-analyzed.f95
  flang/tools/f18/f18.cpp
  flang/tools/f18/flang

Index: flang/tools/f18/flang
===
--- flang/tools/f18/flang
+++ flang/tools/f18/flang
@@ -8,7 +8,7 @@
 #======#
 
 wd=$(cd $(dirname "$0")/.. && pwd)
-opts="-module-suffix .f18.mod "
+opts="-fno-analyzed-objects-for-unparse -module-suffix .f18.mod "
 if ! $wd/bin/f18 $opts "$@"
 then status=$?
  echo flang: in $PWD, f18 failed with exit status $status: $wd/bin/f18 $opts "$@" >&2
Index: flang/tools/f18/f18.cpp
===
--- flang/tools/f18/f18.cpp
+++ flang/tools/f18/f18.cpp
@@ -105,7 +105,7 @@
   bool debugModuleWriter{false};
   bool defaultReal8{false};
   bool measureTree{false};
-  bool unparseTypedExprsToF18_FC{false};
+  bool useAnalyzedObjectsForUnparse{true};
   std::vector F18_FCArgs;
   const char *prefix{nullptr};
   bool getDefinition{false};
@@ -322,7 +322,8 @@
 Unparse(llvm::outs(), parseTree, driver.encoding, true /*capitalize*/,
 options.features.IsEnabled(
 Fortran::common::LanguageFeature::BackslashEscapes),
-nullptr /* action before each statement */, );
+nullptr /* action before each statement */,
+driver.useAnalyzedObjectsForUnparse ?  : nullptr);
 return {};
   }
   if (driver.dumpPreFirTree) {
@@ -353,7 +354,7 @@
 options.features.IsEnabled(
 Fortran::common::LanguageFeature::BackslashEscapes),
 nullptr /* action before each statement */,
-driver.unparseTypedExprsToF18_FC ?  : nullptr);
+driver.useAnalyzedObjectsForUnparse ?  : nullptr);
   }
 
   RunOtherCompiler(driver, tmpSourcePath.data(), relo.data());
@@ -578,8 +579,8 @@
 } else if (arg == "-funparse-with-symbols" ||
 arg == "-fdebug-unparse-with-symbols") {
   driver.dumpUnparseWithSymbols = true;
-} else if (arg == "-funparse-typed-exprs-to-f18-fc") {
-  driver.unparseTypedExprsToF18_FC = true;
+} else if (arg == "-fno-analyzed-objects-for-unparse") {
+  driver.useAnalyzedObjectsForUnparse = false;
 } else if (arg == "-fparse-only" || arg == "-fsyntax-only") {
   driver.syntaxOnly = true;
 } else if (arg == "-c") {
Index: flang/test/Driver/unparse-use-analyzed.f95
===
--- /dev/null
+++ flang/test/Driver/unparse-use-analyzed.f95
@@ -0,0 +1,31 @@
+! Tests `-fno-analyzed-exprs-as-fortran` frontend option
+
+!--
+! RUN lines
+!--
+! RUN: %flang_fc1 -fdebug-unparse  %s | FileCheck %s --check-prefix=DEFAULT
+! RUN: %flang_fc1 -fdebug-unparse -fno-analyzed-objects-for-unparse %s | FileCheck %s --check-prefix=DISABLED
+
+!
+! EXPECTED OUTPUT: default - use analyzed objects
+!
+! DEFAULT: PROGRAM test
+! DEFAULT-NEXT:  REAL, PARAMETER :: val = 3.43e2_4
+! DEFAULT-NEXT:  PRINT *, 3.47e2_4
+! DEFAULT-NEXT: END PROGRAM
+
+!---
+! EXPECTED OUTPUT: disabled - don't use the analyzed objects
+!---
+! DISABLED: PROGRAM test
+! DISABLED-NEXT:  REAL, PARAMETER :: val = 343.0
+! DISABLED-NEXT:  PRINT *, val+4
+! DISABLED-NEXT: END PROGRAM
+
+!--
+! INPUT
+!--
+program test
+  real, parameter :: val = 343.0
+  print *, val + 4
+end program
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -101,6 +101,8 @@
 ! HELP-FC1-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-FC1-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
+! HELP-FC1-NEXT: -fno-analyzed-objects-for-unparse
+! HELP-FC1-NEXT:Do not use the analyzed objects when unparsing
 ! HELP-FC1-NEXT: -fopenacc  Enable 

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

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

In D69560#2840579 , @whisperity wrote:

> In D69560#2840554 , @aaron.ballman 
> wrote:
>
>> This is a very involved check that I think is going to produce some 
>> interesting results for users, thank you for working so diligently on it! I 
>> think all of the patches in the series have now been accepted and this is 
>> ready to land. @whisperity, are you aware of any changes that are left to be 
>> made?
>
> I'll ping @martong privately if they have additional comments about D75041 
> , but otherwise, no, I think no more things 
> left to do. Landing checklist complete.

Great! Unless you hear from @alexfh, @martong, or someone else with additional 
concerns, I think you're set to land this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69560

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


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

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

In D69560#2840554 , @aaron.ballman 
wrote:

> This is a very involved check that I think is going to produce some 
> interesting results for users, thank you for working so diligently on it! I 
> think all of the patches in the series have now been accepted and this is 
> ready to land. @whisperity, are you aware of any changes that are left to be 
> made?

I'll ping @martong privately if they have additional comments about D75041 
, but otherwise, no, I think no more things 
left to do. Landing checklist complete.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69560

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


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

2021-06-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

This is a very involved check that I think is going to produce some interesting 
results for users, thank you for working so diligently on it! I think all of 
the patches in the series have now been accepted and this is ready to land. 
@whisperity, are you aware of any changes that are left to be made?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69560

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


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

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

In D75041#2799036 , @whisperity wrote:

> In D75041#2799023 , @martong wrote:
>
>> Perhaps all conversion related logic should go into their own implementation 
>> file? Seems like it adds up to roughly 1000 lines.
>
> That's against the usual conventions of the project (1 TU for 1 check 
> implementation). The methods are grouped by namespace, you can fold it up in 
> your editor.

FWIW, there's not a hard rule for that -- we put other tidy logic into Utils 
files, for example. However, I think such a cleanup could be done post-commit 
as an NFC change as well.

It's taken me a while to convince myself that it's reasonable to reimplement so 
much of the conversion logic in clang-tidy, but I don't think it's reasonable 
to try to expose an API from Clang for its conversion logic to be reusable in 
this context. So despite my mild discomfort with how complex the logic is in 
this patch, I think it's an acceptable approach. LGTM, aside from some minor 
style nits.




Comment at: 
clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp:249
+  /// the conversion sequence. This method does **NOT** return Begin and End.
+  SmallVector getInvolvedTypesInSequence() const {
+SmallVector Ret;

Return a `SmallVectorImpl` so that the size of the vector doesn't 
matter to callers?



Comment at: 
clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp:556
+static inline bool isUselessSugar(const Type *T) {
+  return isa(T);
+}

One thing that could get interesting here are attributed types, as those may be 
"useless" or "useful" sugars depending on the attribute. However, I think we 
can deal with that later when we have more real-world uses in front of us.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp:962
+public:
+  /// The conversion assocaited with a conversion function, together with the
+  /// mixability flags of the conversion function's parameter or return type





Comment at: 
clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp:1491
+
+const auto  = [&](StringRef ToAdd) {
+  if (LastAddedType != ToAdd && ToAdd != SeqEndTypeStr) {





Comment at: 
clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp:1493
+  if (LastAddedType != ToAdd && ToAdd != SeqEndTypeStr) {
+OS << " -> '" << ToAdd << '\'';
+LastAddedType = ToAdd.str();





Comment at: 
clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp:1503
+if (LastAddedType != DestinationTypeAsDiagnosed) {
+  OS << " -> '" << DestinationTypeAsDiagnosed << '\'';
+  LastAddedType = DestinationTypeAsDiagnosed.str();




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75041

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


[PATCH] D104904: [OpenMP][AMDGCN] Initial math headers support

2021-06-25 Thread Pushpinder Singh via Phabricator via cfe-commits
pdhaliwal updated this revision to Diff 354471.
pdhaliwal added a comment.

Fix format errors


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104904

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Headers/__clang_hip_cmath.h
  clang/lib/Headers/__clang_hip_math.h
  clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h
  clang/lib/Headers/openmp_wrappers/cmath
  clang/lib/Headers/openmp_wrappers/math.h
  clang/test/Headers/Inputs/include/algorithm
  clang/test/Headers/Inputs/include/cstdlib
  clang/test/Headers/Inputs/include/utility
  clang/test/Headers/amdgcn_openmp_device_math.c
  clang/test/Headers/openmp_device_math_isnan.cpp

Index: clang/test/Headers/openmp_device_math_isnan.cpp
===
--- clang/test/Headers/openmp_device_math_isnan.cpp
+++ clang/test/Headers/openmp_device_math_isnan.cpp
@@ -21,14 +21,14 @@
 double math(float f, double d) {
   double r = 0;
   // INT_RETURN: call i32 @__nv_isnanf(float
-  // AMD_INT_RETURN: call i32 @_{{.*}}isnanf(float
+  // AMD_INT_RETURN: call i32 @__ocml_isnan_f32(float
   // BOOL_RETURN: call i32 @__nv_isnanf(float
-  // AMD_BOOL_RETURN: call zeroext i1 @_{{.*}}isnanf(float
+  // AMD_BOOL_RETURN: call i32 @__ocml_isnan_f32(float
   r += std::isnan(f);
   // INT_RETURN: call i32 @__nv_isnand(double
-  // AMD_INT_RETURN: call i32 @_{{.*}}isnand(double
+  // AMD_INT_RETURN: call i32 @__ocml_isnan_f64(double
   // BOOL_RETURN: call i32 @__nv_isnand(double
-  // AMD_BOOL_RETURN: call zeroext i1 @_{{.*}}isnand(double
+  // AMD_BOOL_RETURN: call i32 @__ocml_isnan_f64(double
   r += std::isnan(d);
   return r;
 }
Index: clang/test/Headers/amdgcn_openmp_device_math.c
===
--- /dev/null
+++ clang/test/Headers/amdgcn_openmp_device_math.c
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -internal-isystem %S/Inputs/include -x c -fopenmp -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-host.bc
+// RUN: %clang_cc1 -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-C,CHECK
+// RUN: %clang_cc1 -internal-isystem %S/Inputs/include -x c++ -fopenmp -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-host.bc
+// RUN: %clang_cc1 -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-CPP,CHECK
+
+#ifdef __cplusplus
+#include 
+#else
+#include 
+#endif
+
+void test_math_f64(double x) {
+// CHECK-LABEL: define {{.*}}test_math_f64
+#pragma omp target
+  {
+// CHECK: call double @__ocml_sin_f64
+double l1 = sin(x);
+// CHECK: call double @__ocml_cos_f64
+double l2 = cos(x);
+// CHECK: call double @__ocml_fabs_f64
+double l3 = fabs(x);
+  }
+}
+
+void test_math_f32(float x) {
+// CHECK-LABEL: define {{.*}}test_math_f32
+#pragma omp target
+  {
+// CHECK-C: call double @__ocml_sin_f64
+// CHECK-CPP: call float @__ocml_sin_f32
+float l1 = sin(x);
+// CHECK-C: call double @__ocml_cos_f64
+// CHECK-CPP: call float @__ocml_cos_f32
+float l2 = cos(x);
+// CHECK-C: call double @__ocml_fabs_f64
+// CHECK-CPP: call float @__ocml_fabs_f32
+float l3 = fabs(x);
+  }
+}
+void test_math_f32_suffix(float x) {
+// CHECK-LABEL: define {{.*}}test_math_f32_suffix
+#pragma omp target
+  {
+// CHECK: call float @__ocml_sin_f32
+float l1 = sinf(x);
+// CHECK: call float @__ocml_cos_f32
+float l2 = cosf(x);
+// CHECK: call float @__ocml_fabs_f32
+float l3 = fabsf(x);
+  }
+}
Index: clang/test/Headers/Inputs/include/utility
===
--- /dev/null
+++ clang/test/Headers/Inputs/include/utility
@@ -0,0 +1,2 @@
+#pragma once
+
Index: clang/test/Headers/Inputs/include/cstdlib
===
--- clang/test/Headers/Inputs/include/cstdlib
+++ clang/test/Headers/Inputs/include/cstdlib
@@ -12,6 +12,7 @@
 extern float fabs (float __x) __attribute__ ((__const__)) ;
 #endif
 
+#ifndef __AMDGCN__
 namespace std
 {
 
@@ -29,3 +30,5 @@
 double abs(double __x) { return fabs(__x); }
 
 }
+
+#endif
Index: 

[PATCH] D20689: [clang-tidy] Add 'readability-suspicious-call-argument' check

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

**NFC** Rebase and fix things broken by D104819 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D20689

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
  clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability-suspicious-call-argument.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
@@ -0,0 +1,477 @@
+// RUN: %check_clang_tidy %s readability-suspicious-call-argument %t -- -- -std=c++11
+
+void foo_1(int aa, int bb) {}
+
+void foo_2(int source, int aa) {}
+
+void foo_3(int valToRet, int aa) {}
+
+void foo_4(int pointer, int aa) {}
+
+void foo_5(int aa, int bb, int cc, ...) {}
+
+void foo_6(const int dd, bool ) {}
+
+void foo_7(int aa, int bb, int cc, int ff = 7) {}
+
+void foo_8(int frobble1, int frobble2) {}
+
+// Test functions for convertible argument--parameter types.
+void fun(const int );
+void fun2() {
+  int m = 3;
+  fun(m);
+}
+
+// Test cases for parameters of const reference and value.
+void value_const_reference(int ll, const int );
+
+void const_ref_value_swapped() {
+  const int  = 42;
+  const int  = 42;
+  value_const_reference(kk, ll);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 1st argument 'kk' (passed to 'll') looks like it might be swapped with the 2nd, 'll' (passed to 'kk') [readability-suspicious-call-argument]
+  // CHECK-MESSAGES: :[[@LINE-7]]:6: note: in the call to 'value_const_reference', declared here
+}
+
+// Const, non const references.
+void const_nonconst_parameters(const int , int );
+
+void const_nonconst_swap1() {
+  const int  = 42;
+  int mm;
+  // Do not check, because non-const reference parameter cannot bind to const reference argument.
+  const_nonconst_parameters(nn, mm);
+}
+
+void const_nonconst_swap3() {
+  const int nn = 42;
+  int m = 42;
+  int  = m;
+  // Do not check, const int does not bind to non const reference.
+  const_nonconst_parameters(nn, mm);
+}
+
+void const_nonconst_swap2() {
+  int nn;
+  int mm;
+  // Check for swapped arguments. (Both arguments are non-const.)
+  const_nonconst_parameters(nn, mm);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 1st argument 'nn' (passed to 'mm') looks like it might be swapped with the 2nd, 'mm' (passed to 'nn')
+}
+
+void const_nonconst_pointers(const int *mm, int *nn);
+void const_nonconst_pointers2(const int *mm, const int *nn);
+
+void const_nonconst_pointers_swapped() {
+  int *mm;
+  const int *nn;
+  const_nonconst_pointers(nn, mm);
+}
+
+void const_nonconst_pointers_swapped2() {
+  const int *mm;
+  int *nn;
+  const_nonconst_pointers2(nn, mm);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 1st argument 'nn' (passed to 'mm') looks like it might be swapped with the 2nd, 'mm' (passed to 'nn')
+}
+
+// Test cases for pointers and arrays.
+void pointer_array_parameters(
+int *pp, int qq[4]);
+
+void pointer_array_swap() {
+  int qq[5];
+  int *pp;
+  // Check for swapped arguments. An array implicitly converts to a pointer.
+  pointer_array_parameters(qq, pp);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 1st argument 'qq' (passed to 'pp') looks like it might be swapped with the 2nd, 'pp' (passed to 'qq')
+}
+
+// Test cases for multilevel pointers.
+void multilevel_pointer_parameters(int *const **pp,
+   const int *const *volatile const *qq);
+void multilevel_pointer_parameters2(
+char *nn, char *volatile *const *const *const *const );
+
+typedef float T;
+typedef T *S;
+typedef S *const volatile R;
+typedef R *Q;
+typedef Q *P;
+typedef P *O;
+void multilevel_pointer_parameters3(float **const volatile ***rr, O );
+
+void multilevel_pointer_swap() {
+  int *const **qq;
+  int *const **pp;
+  multilevel_pointer_parameters(qq, pp);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 1st argument 'qq' (passed to 'pp') looks like it might be swapped with the 2nd, 'pp' (passed to 'qq')
+
+  char *mm;
+  char *nn;
+  multilevel_pointer_parameters2(mm, 

[PATCH] D104854: Introduce intrinsic llvm.isnan

2021-06-25 Thread Thomas Preud'homme via Phabricator via cfe-commits
thopre added a comment.

LGTM (besides comment fix) but I'm not too familiar with the vector side of 
things




Comment at: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:6967
+  // NaN has all exp bits set and a non zero significand. Therefore:
+  // isnan(V) == ((exp mask - (abs(V) & exp mask)) < 0)
+  unsigned BitSize = OperandVT.getScalarSizeInBits();

I seem to have made a mistake when I wrote this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104854

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


  1   2   >