[PATCH] D105821: [analyzer] [WIP] Model destructor for std::unique_ptr

2021-07-25 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 361581.
RedDocMD added a comment.

Removed a fatal bug


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105821

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp


Index: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -753,10 +753,13 @@
 *Call, *this);
 
   ExplodedNodeSet DstInvalidated;
-  StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
-  for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
-   I != E; ++I)
-defaultEvalCall(Bldr, *I, *Call, CallOpts);
+  // StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
+  // for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E =
+  // DstPreCall.end();
+  //  I != E; ++I)
+  //   defaultEvalCall(Bldr, *I, *Call, CallOpts);
+  getCheckerManager().runCheckersForEvalCall(DstInvalidated, DstPreCall, *Call,
+ *this, CallOpts);
 
   getCheckerManager().runCheckersForPostCall(Dst, DstInvalidated,
  *Call, *this);
Index: clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
@@ -664,14 +664,11 @@
 for (const auto  : EvalCallCheckers) {
   // TODO: Support the situation when the call doesn't correspond
   // to any Expr.
-  ProgramPoint L = ProgramPoint::getProgramPoint(
-  Call.getOriginExpr(), ProgramPoint::PostStmtKind,
-  Pred->getLocationContext(), EvalCallChecker.Checker);
   bool evaluated = false;
   { // CheckerContext generates transitions(populates checkDest) on
 // destruction, so introduce the scope to make sure it gets properly
 // populated.
-CheckerContext C(B, Eng, Pred, L);
+CheckerContext C(B, Eng, Pred, Call.getProgramPoint());
 evaluated = EvalCallChecker(Call, C);
   }
   assert(!(evaluated && anyEvaluated)
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -279,6 +279,7 @@
 CheckerContext ) const {
 
   ProgramStateRef State = C.getState();
+  Call.dump();
 
   // If any one of the arg is a unique_ptr, then
   // we can try this function
@@ -372,6 +373,19 @@
 }
   }
 
+  if (const auto *DC = dyn_cast()) {
+llvm::errs() << "Found destructor call\n";
+const MemRegion *ThisRegion = DC->getCXXThisVal().getAsRegion();
+assert(ThisRegion && "We do not support explicit calls to destructor");
+const auto *InnerPtrVal = State->get(ThisRegion);
+State = State->remove(ThisRegion);
+if (InnerPtrVal)
+  State = State->invalidateRegions(*InnerPtrVal, nullptr, C.blockCount(),
+   C.getLocationContext(), true);
+C.addTransition(State);
+return true;
+  }
+
   if (!ModelSmartPtrDereference)
 return false;
 


Index: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -753,10 +753,13 @@
 *Call, *this);
 
   ExplodedNodeSet DstInvalidated;
-  StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
-  for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
-   I != E; ++I)
-defaultEvalCall(Bldr, *I, *Call, CallOpts);
+  // StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
+  // for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E =
+  // DstPreCall.end();
+  //  I != E; ++I)
+  //   defaultEvalCall(Bldr, *I, *Call, CallOpts);
+  getCheckerManager().runCheckersForEvalCall(DstInvalidated, DstPreCall, *Call,
+ *this, CallOpts);
 
   getCheckerManager().runCheckersForPostCall(Dst, DstInvalidated,
  *Call, *this);
Index: clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
@@ -664,14 +664,11 @@
 for (const auto  : EvalCallCheckers) {
   // TODO: Support the situation when the call 

[PATCH] D106753: ConvertUTF: Created wrapper convertUTF32ToUTF8String

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

The buildbot seems to think your new unittests are broken.  Not sure why.  (You 
can run just the unittests with "ninja check-llvm-unit".)




Comment at: llvm/include/llvm/Support/ConvertUTF.h:127
+#define UNI_UTF32_BYTE_ORDER_MARK_NATIVE 0xFEFF
+#define UNI_UTF32_BYTE_ORDER_MARK_SWAPPED 0xFFFE
+

UNI_UTF32_BYTE_ORDER_MARK_SWAPPED doesn't have the correct bit pattern.



Comment at: llvm/lib/Support/ConvertUTFWrapper.cpp:168
+  std::vector ByteSwapped;
+  if (Src[0] == UNI_UTF16_BYTE_ORDER_MARK_SWAPPED) {
+ByteSwapped.insert(ByteSwapped.end(), Src, SrcEnd);

MarcusJohnson91 wrote:
> efriedma wrote:
> > Wrong constant.
> > 
> > Is this really the function you want to be using from clang?  I don't 
> > really understand why you'd want to handle byte order marks.
> I don't really care about the BOM tbh, I just figured if I was in here, I 
> should flesh out the UTF-32 interface.
The BOM handling is actually actively a problem if you're planning to use the 
interface to interpret wprintf format strings.  We don't want to byteswap 
`L"\uFFFE%s"` or something like that.


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

https://reviews.llvm.org/D106753

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


[PATCH] D106739: [analyzer] Add option to SATest.py for extra checkers

2021-07-25 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added a comment.

@vsavchenko is this okay?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106739

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


[PATCH] D105821: [analyzer] [WIP] Model destructor for std::unique_ptr

2021-07-25 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added a comment.

In D105821#2897006 , @NoQ wrote:

>> the following code doesn't emit any warnings
>
> This code doesn't seem to have any `unique_ptr`s in it? It's not like you're 
> modeling this custom class as well? Can you try the same with the actual 
> `unique_ptr`?

The following code emits a warning for leaked memory:

  #include 
  
  class Lame {
int *ptr;
  public:
explicit Lame(int *ptr) : ptr(ptr) {}
~Lame() { delete ptr; }
  };
  
  void foo() {
int *ptr = new int(13);
auto smart = std::make_unique(ptr);
// No leak here
  }

It seems that there is a flaw in the way I was testing for warnings. 
Why does the following command not display the warnings? 
`./llvm/release/bin/clang -std=c++17 -Xclang -analyze -Xclang 
-analyzer-checker=core,cplusplus.Move,cplusplus.NewDelete,alpha.cplusplus.SmartPtr
 -Xclang -analyzer-output=text -Xclang -analyzer-config -Xclang 
cplusplus.SmartPtrModeling:ModelSmartPtrDereference=true -c lame-class.cpp`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105821

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


[PATCH] D104601: [Preprocessor] Implement -fminimize-whitespace.

2021-07-25 Thread Michael Kruse 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 rGae6b4238: [Preprocessor] Implement 
-fminimize-whitespace. (authored by Meinersbur).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104601

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.h
  clang/include/clang/Frontend/PreprocessorOutputOptions.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/Types.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/test/Preprocessor/comment_save.c
  clang/test/Preprocessor/first-line-indent.c
  clang/test/Preprocessor/hash_line.c
  clang/test/Preprocessor/line-directive-output-mincol.c
  clang/test/Preprocessor/line-directive-output.c
  clang/test/Preprocessor/macro_space.c
  clang/test/Preprocessor/minimize-whitespace-messages.c
  clang/test/Preprocessor/minimize-whitespace.c
  clang/test/Preprocessor/print_line_include.c
  clang/test/Preprocessor/stringize_space.c

Index: clang/test/Preprocessor/stringize_space.c
===
--- clang/test/Preprocessor/stringize_space.c
+++ clang/test/Preprocessor/stringize_space.c
@@ -1,16 +1,18 @@
 // RUN: %clang_cc1 -E %s | FileCheck --strict-whitespace %s
+// RUN: %clang_cc1 -E -P -fminimize-whitespace %s | FileCheck --strict-whitespace %s --check-prefix=MINWS
 
 #define A(b) -#b  ,  - #b  ,  -# b  ,  - # b
 A()
 
 // CHECK: {{^}}-"" , - "" , -"" , - ""{{$}}
-
+// MINWS: {{^}}-"",-"",-"",-""
 
 #define t(x) #x
 t(a
 c)
 
 // CHECK: {{^}}"a c"{{$}}
+// MINWS-SAME: "a c"
 
 #define str(x) #x
 #define f(x) str(-x)
@@ -18,6 +20,7 @@
 1)
 
 // CHECK: {{^}}"-1"
+// MINWS-SAME: "-1"
 
 #define paste(a,b) str(a&1 | FileCheck %s --strict-whitespace --check-prefix=MINCOL
+// RUN: %clang_cc1 -fminimize-whitespace -E -C %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINCCOL
+// RUN: %clang_cc1 -fminimize-whitespace -E -P %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINWS
+// RUN: %clang_cc1 -fminimize-whitespace -E -C -P %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINCWS
+
+#define NOT_OMP  omp  something
+#define HASH #
+
+  int  a; /*  span-comment  */
+  int  b  ;   //  line-comment
+  _Pragma  (  "omp  barrier"  ) x //  more line-comments
+  #pragma  omp  nothing  //  another comment
+HASH  pragma  NOT_OMP
+  int  e;// again a line
+  int  \
+f  ;
+
+
+// MINCOL:  {{^}}# 9 "{{.*}}minimize-whitespace.c"{{$}}
+// MINCOL:  {{^}}int a;{{$}}
+// MINCOL-NEXT: {{^}}int b;{{$}}
+// MINCOL-NEXT: {{^}}#pragma omp barrier{{$}}
+// MINCOL-NEXT: # 11 "{{.*}}minimize-whitespace.c"
+// MINCOL-NEXT: {{^}}x{{$}}
+// MINCOL-NEXT: {{^}}#pragma omp nothing{{$}}
+// MINCOL-NEXT: {{^ }}#pragma omp something{{$}}
+// MINCOL-NEXT: {{^}}int e;{{$}}
+// MINCOL-NEXT: {{^}}int f;{{$}}
+
+// FIXME: Comments after pragmas disappear, even without -fminimize-whitespace
+// MINCCOL:  {{^}}# 9 "{{.*}}minimize-whitespace.c"{{$}}
+// MINCCOL:  {{^}}int a;/*  span-comment  */{{$}}
+// MINCCOL-NEXT: {{^}}int b;//  line-comment{{$}}
+// MINCCOL-NEXT: {{^}}#pragma omp barrier{{$}}
+// MINCCOL-NEXT: # 11 "{{.*}}minimize-whitespace.c"
+// MINCCOL-NEXT: {{^}}x//  more line-comments{{$}}
+// MINCCOL-NEXT: {{^}}#pragma omp nothing{{$}}
+// MINCCOL-NEXT: {{^ }}#pragma omp something{{$}}
+// MINCCOL-NEXT: {{^}}int e;// again a line{{$}}
+// MINCCOL-NEXT: {{^}}int f;{{$}}
+
+// MINWS:  {{^}}int a;int b;{{$}}
+// MINWS-NEXT: {{^}}#pragma omp barrier{{$}}
+// MINWS-NEXT: {{^}}x{{$}}
+// MINWS-NEXT: {{^}}#pragma omp nothing{{$}}
+// MINWS-NEXT: {{^ }}#pragma omp something int e;int f;{{$}}
+
+// FIXME: Comments after pragmas disappear, even without -fminimize-whitespace
+// MINCWS:  {{^}}int a;/*  span-comment  */int b;//  line-comment{{$}}
+// MINCWS-NEXT: {{^}}#pragma omp barrier{{$}}
+// MINCWS-NEXT: {{^}}x//  more line-comments{{$}}
+// MINCWS-NEXT: {{^}}#pragma omp nothing{{$}}
+// MINCWS-NEXT: {{^ }}#pragma omp something int e;// again a line{{$}}
+// MINCWS-NEXT: {{^}}int f;
+
Index: clang/test/Preprocessor/minimize-whitespace-messages.c
===
--- /dev/null
+++ clang/test/Preprocessor/minimize-whitespace-messages.c
@@ -0,0 +1,8 @@
+// RUN: not %clang -c -fminimize-whitespace %s 2>&1 | FileCheck %s --check-prefix=ON
+// ON: error: invalid argument '-fminimize-whitespace' only allowed with '-E'
+
+// RUN: not %clang -c -fno-minimize-whitespace %s 2>&1 | FileCheck %s  --check-prefix=OFF
+// OFF: error: invalid argument '-fno-minimize-whitespace' only allowed with '-E'
+
+// RUN: not %clang -E -fminimize-whitespace -x assembler-with-cpp %s 2>&1 | FileCheck %s --check-prefix=ASM
+// 

[clang] ae6b400 - [Preprocessor] Implement -fminimize-whitespace.

2021-07-25 Thread Michael Kruse via cfe-commits

Author: Michael Kruse
Date: 2021-07-25T23:30:57-05:00
New Revision: ae6b4238e5f319ffcfc713a15e459be8

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

LOG: [Preprocessor] Implement -fminimize-whitespace.

This patch adds the -fminimize-whitespace with the following effects:

 * If combined with -E, remove as much non-line-breaking whitespace as
   possible.

 * If combined with -E -P, removes as much whitespace as possible,
   including line-breaks.

The motivation is to reduce the amount of insignificant changes in the
preprocessed output with source files where only whitespace has been
changed (add/remove comments, clang-format, etc.) which is in particular
useful with ccache.

A patch for ccache for using this flag has been proposed to ccache as well:
https://github.com/ccache/ccache/pull/815, which will use
-fnormalize-whitespace when clang-13 has been detected, and additionally
uses -P in "unify_mode". ccache already had a unify_mode in an older
version which was removed because of problems that using the
preprocessor itself does not have (such that the custom tokenizer did
not recognize C++11 raw strings).

This patch slightly reorganizes which part is responsible for adding
newlines that are required for semantics. It is now either
startNewLineIfNeeded() or MoveToLine() but never both; this avoids the
ShouldUpdateCurrentLine workaround and avoids redundant lines being
inserted in some cases. It also fixes a mandatory newline not inserted
after a _Pragma("...") that is expanded into a #pragma.

Reviewed By: aaron.ballman

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

Added: 
clang/test/Preprocessor/line-directive-output-mincol.c
clang/test/Preprocessor/minimize-whitespace-messages.c
clang/test/Preprocessor/minimize-whitespace.c

Modified: 
clang/docs/ClangCommandLineReference.rst
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Driver/Options.td
clang/include/clang/Driver/Types.h
clang/include/clang/Frontend/PreprocessorOutputOptions.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/Types.cpp
clang/lib/Frontend/PrintPreprocessedOutput.cpp
clang/lib/Lex/Preprocessor.cpp
clang/test/Preprocessor/comment_save.c
clang/test/Preprocessor/first-line-indent.c
clang/test/Preprocessor/hash_line.c
clang/test/Preprocessor/line-directive-output.c
clang/test/Preprocessor/macro_space.c
clang/test/Preprocessor/print_line_include.c
clang/test/Preprocessor/stringize_space.c

Removed: 




diff  --git a/clang/docs/ClangCommandLineReference.rst 
b/clang/docs/ClangCommandLineReference.rst
index 74557c5bd581..35a3fdd382b4 100644
--- a/clang/docs/ClangCommandLineReference.rst
+++ b/clang/docs/ClangCommandLineReference.rst
@@ -2475,6 +2475,16 @@ Turn on loop unroller
 
 Use #line in preprocessed output
 
+.. option:: -fminimize-whitespace, -fno-minimize-whitespace
+
+Ignore the whitespace from the input file when emitting preprocessor
+output. It will only contain whitespace when necessary, e.g. to keep two
+minus signs from merging into to an increment operator. Useful with the
+-P option to normalize whitespace such that two files with only formatting
+changes are equal.
+
+Only valid with -E on C-like inputs and incompatible with -traditional-cpp.
+
 .. option:: -fvalidate-ast-input-files-content
 
 Compute and store the hash of input files used to build an AST. Files with 
mismatching mtime's are considered valid if both contents is identical

diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index fc3704303a95..3b4daa59f66b 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -129,6 +129,8 @@ def err_drv_invalid_Xopenmp_target_with_args : Error<
   "invalid -Xopenmp-target argument: '%0', options requiring arguments are 
unsupported">;
 def err_drv_argument_only_allowed_with : Error<
   "invalid argument '%0' only allowed with '%1'">;
+def err_drv_minws_unsupported_input_type : Error<
+  "'-fminimize-whitespace' invalid for input of type %0">;
 def err_drv_amdgpu_ieee_without_no_honor_nans : Error<
   "invalid argument '-mno-amdgpu-ieee' only allowed with relaxed NaN 
handling">;
 def err_drv_argument_not_allowed_with : Error<

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1815cd4621e8..991408c0e2a1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1799,6 +1799,9 @@ def frewrite_map_file_EQ : Joined<["-"], 
"frewrite-map-file=">,
 defm use_line_directives : BoolFOption<"use-line-directives",
   PreprocessorOutputOpts<"UseLineDirectives">, 

[PATCH] D95588: [RISCV] Implement the MC layer support of P extension

2021-07-25 Thread Jim Lin via Phabricator via cfe-commits
Jim added a comment.

@jrtc27 Any more feedback? Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95588

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


[PATCH] D106778: [OpenCL] opencl-c.h: add CL 3.0 non-generic address space atomics

2021-07-25 Thread Dave Airlie via Phabricator via cfe-commits
airlied created this revision.
airlied added a project: clang.
Herald added subscribers: ldrumm, jfb, Anastasia, yaxunl.
airlied requested review of this revision.
Herald added a subscriber: cfe-commits.

CL 2.0 interdocued atomics and generic address space so there were
only one set of APIs for doing atomics, however since CL 3.0
makes generic address space optional, there has to be new sets
of atomic interfaces to handle that cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106778

Files:
  clang/lib/Headers/opencl-c.h

Index: clang/lib/Headers/opencl-c.h
===
--- clang/lib/Headers/opencl-c.h
+++ clang/lib/Headers/opencl-c.h
@@ -13289,6 +13289,7 @@
 #endif
 
 // atomic_init()
+#if defined(__opencl_c_generic_address_space)
 void __ovld atomic_init(volatile atomic_int *object, int value);
 void __ovld atomic_init(volatile atomic_uint *object, uint value);
 void __ovld atomic_init(volatile atomic_float *object, float value);
@@ -13299,6 +13300,24 @@
 void __ovld atomic_init(volatile atomic_double *object, double value);
 #endif //cl_khr_fp64
 #endif
+#else
+void __ovld atomic_init(volatile __global atomic_int *object, int value);
+void __ovld atomic_init(volatile __local atomic_int *object, int value);
+void __ovld atomic_init(volatile __global atomic_uint *object, uint value);
+void __ovld atomic_init(volatile __local atomic_uint *object, uint value);
+void __ovld atomic_init(volatile __global atomic_float *object, float value);
+void __ovld atomic_init(volatile __local atomic_float *object, float value);
+#if defined(cl_khr_int64_base_atomics) && defined(cl_khr_int64_extended_atomics)
+void __ovld atomic_init(volatile __global atomic_long *object, long value);
+void __ovld atomic_init(volatile __local atomic_long *object, long value);
+void __ovld atomic_init(volatile __global atomic_ulong *object, ulong value);
+void __ovld atomic_init(volatile __local atomic_ulong *object, ulong value);
+#ifdef cl_khr_fp64
+void __ovld atomic_init(volatile __global atomic_double *object, double value);
+void __ovld atomic_init(volatile __local atomic_double *object, double value);
+#endif //cl_khr_fp64
+#endif
+#endif
 
 // atomic_work_item_fence()
 void __ovld atomic_work_item_fence(cl_mem_fence_flags flags, memory_order order, memory_scope scope);
@@ -13308,6 +13327,7 @@
 // add/sub: atomic type argument can be uintptr_t/intptr_t, value type argument can be ptrdiff_t.
 
 #if defined(__opencl_c_atomic_order_seq_cst) && defined(__opencl_c_atomic_scope_device)
+#if defined(__opencl_c_generic_address_space)
 int __ovld atomic_fetch_add(volatile atomic_int *object, int operand);
 uint __ovld atomic_fetch_add(volatile atomic_uint *object, uint operand);
 int __ovld atomic_fetch_sub(volatile atomic_int *object, int operand);
@@ -13322,7 +13342,6 @@
 uint __ovld atomic_fetch_min(volatile atomic_uint *object, uint operand);
 int __ovld atomic_fetch_max(volatile atomic_int *object, int operand);
 uint __ovld atomic_fetch_max(volatile atomic_uint *object, uint operand);
-
 #if defined(cl_khr_int64_base_atomics) && defined(cl_khr_int64_extended_atomics)
 long __ovld atomic_fetch_add(volatile atomic_long *object, long operand);
 ulong __ovld atomic_fetch_add(volatile atomic_ulong *object, ulong operand);
@@ -13341,9 +13360,92 @@
 uintptr_t __ovld atomic_fetch_add(volatile atomic_uintptr_t *object, ptrdiff_t operand);
 uintptr_t __ovld atomic_fetch_sub(volatile atomic_uintptr_t *object, ptrdiff_t operand);
 #endif //defined(cl_khr_int64_base_atomics) && defined(cl_khr_int64_extended_atomics)
+#else
+int __ovld atomic_fetch_add(volatile __global atomic_int *object, int operand);
+int __ovld atomic_fetch_add(volatile __local atomic_int *object, int operand);
+uint __ovld atomic_fetch_add(volatile __global atomic_uint *object, uint operand);
+uint __ovld atomic_fetch_add(volatile __local atomic_uint *object, uint operand);
+int __ovld atomic_fetch_sub(volatile __global atomic_int *object, int operand);
+int __ovld atomic_fetch_sub(volatile __local atomic_int *object, int operand);
+uint __ovld atomic_fetch_sub(volatile __global atomic_uint *object, uint operand);
+uint __ovld atomic_fetch_sub(volatile __local atomic_uint *object, uint operand);
+int __ovld atomic_fetch_or(volatile __global atomic_int *object, int operand);
+int __ovld atomic_fetch_or(volatile __local atomic_int *object, int operand);
+uint __ovld atomic_fetch_or(volatile __global atomic_uint *object, uint operand);
+uint __ovld atomic_fetch_or(volatile __local atomic_uint *object, uint operand);
+int __ovld atomic_fetch_xor(volatile __global atomic_int *object, int operand);
+int __ovld atomic_fetch_xor(volatile __local atomic_int *object, int operand);
+uint __ovld atomic_fetch_xor(volatile __global atomic_uint *object, uint operand);
+uint __ovld atomic_fetch_xor(volatile __local atomic_uint *object, uint operand);i
+int __ovld atomic_fetch_and(volatile __global atomic_int 

[PATCH] D100768: [Clang][OpenMP] Remove the mandatory flush for capture for OpenMP 5.1

2021-07-25 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D100768#2903520 , @tianshilei1992 
wrote:

> @ABataev I updated the description. If you agree with my understanding, I'll 
> land it.

Still LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100768

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


[PATCH] D100768: [Clang][OpenMP] Remove the mandatory flush for capture for OpenMP 5.1

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

@ABataev I updated the description. If you agree with my understanding, I'll 
land it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100768

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


[PATCH] D105555: [RISCV][Clang] Compute the default target-abi if it's empty.

2021-07-25 Thread Zakk Chen via Phabricator via cfe-commits
khchen updated this revision to Diff 361568.
khchen marked 6 inline comments as done.
khchen added a comment.

address @jrtc27's comment, thanks again!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D10

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/CodeGen/RISCV/riscv-metadata.c
  llvm/include/llvm/Support/TargetParser.h
  llvm/lib/Support/TargetParser.cpp

Index: llvm/lib/Support/TargetParser.cpp
===
--- llvm/lib/Support/TargetParser.cpp
+++ llvm/lib/Support/TargetParser.cpp
@@ -331,5 +331,20 @@
   return true;
 }
 
+StringRef computeDefaultABIFromArch(const llvm::RISCVISAInfo ) {
+  if (ISAInfo.getXLen() == 32) {
+if (ISAInfo.hasExtension("d"))
+  return "ilp32d";
+if (ISAInfo.hasExtension("e"))
+  return "ilp32e";
+return "ilp32";
+  } else if (ISAInfo.getXLen() == 64) {
+if (ISAInfo.hasExtension("d"))
+  return "lp64d";
+return "lp64";
+  }
+  llvm_unreachable("Invalid XLEN");
+}
+
 } // namespace RISCV
 } // namespace llvm
Index: llvm/include/llvm/Support/TargetParser.h
===
--- llvm/include/llvm/Support/TargetParser.h
+++ llvm/include/llvm/Support/TargetParser.h
@@ -17,8 +17,9 @@
 // FIXME: vector is used because that's what clang uses for subtarget feature
 // lists, but SmallVector would probably be better
 #include "llvm/ADT/Triple.h"
-#include "llvm/Support/ARMTargetParser.h"
 #include "llvm/Support/AArch64TargetParser.h"
+#include "llvm/Support/ARMTargetParser.h"
+#include "llvm/Support/RISCVISAInfo.h"
 #include 
 
 namespace llvm {
@@ -174,6 +175,7 @@
 void fillValidTuneCPUArchList(SmallVectorImpl , bool IsRV64);
 bool getCPUFeaturesExceptStdExt(CPUKind Kind, std::vector );
 StringRef resolveTuneCPUAlias(StringRef TuneCPU, bool IsRV64);
+StringRef computeDefaultABIFromArch(const llvm::RISCVISAInfo );
 
 } // namespace RISCV
 
Index: clang/test/CodeGen/RISCV/riscv-metadata.c
===
--- clang/test/CodeGen/RISCV/riscv-metadata.c
+++ clang/test/CodeGen/RISCV/riscv-metadata.c
@@ -1,14 +1,28 @@
+// RUN: %clang_cc1 -triple riscv32 -emit-llvm -o - %s | FileCheck -check-prefix=EMPTY-ILP32 %s
+// RUN: %clang_cc1 -triple riscv32 -emit-llvm -target-feature +f -target-feature +d -o - %s | FileCheck -check-prefix=EMPTY-ILP32D %s
 // RUN: %clang_cc1 -triple riscv32 -target-abi ilp32 -emit-llvm -o - %s | FileCheck -check-prefix=ILP32 %s
 // RUN: %clang_cc1 -triple riscv32 -target-feature +f -target-abi ilp32f -emit-llvm -o - %s | FileCheck -check-prefix=ILP32F %s
 // RUN: %clang_cc1 -triple riscv32 -target-feature +d -target-abi ilp32d -emit-llvm -o - %s | FileCheck -check-prefix=ILP32D %s
+// RUN: %clang_cc1 -triple riscv64 -emit-llvm -o - %s | FileCheck -check-prefix=EMPTY-LP64 %s
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d -emit-llvm -o - %s | FileCheck -check-prefix=EMPTY-LP64D %s
 // RUN: %clang_cc1 -triple riscv64 -target-abi lp64 -emit-llvm -o - %s | FileCheck -check-prefix=LP64 %s
 // RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-abi lp64f -emit-llvm -o - %s | FileCheck -check-prefix=LP64F %s
 // RUN: %clang_cc1 -triple riscv64 -target-feature +d -target-abi lp64d -emit-llvm -o - %s | FileCheck -check-prefix=LP64D %s
 
+// Test expected behavior when giving -target-cpu
+// This cc1 test is similar to clang with -march=rv32ifd -mcpu=sifive-e31, default abi is ilp32d
+// RUN: %clang_cc1 -triple riscv32 -emit-llvm -target-feature +f -target-feature +d -target-cpu sifive-e31 -o - %s | FileCheck -check-prefix=EMPTY-ILP32D %s
+// This cc1 test is similar to clang with -march=rv64i -mcpu=sifive-u74, default abi is lp64
+// RUN: %clang_cc1 -triple riscv64 -emit-llvm -o - -target-cpu sifive-u74 %s | FileCheck -check-prefix=EMPTY-LP64 %s
+
+// EMPTY-ILP32: !{{[0-9]+}} = !{i32 1, !"target-abi", !"ilp32"}
+// EMPTY-ILP32D: !{{[0-9]+}} = !{i32 1, !"target-abi", !"ilp32d"}
 // ILP32: !{{[0-9]+}} = !{i32 1, !"target-abi", !"ilp32"}
 // ILP32F: !{{[0-9]+}} = !{i32 1, !"target-abi", !"ilp32f"}
 // ILP32D: !{{[0-9]+}} = !{i32 1, !"target-abi", !"ilp32d"}
 
+// EMPTY-LP64: !{{[0-9]+}} = !{i32 1, !"target-abi", !"lp64"}
+// EMPTY-LP64D: !{{[0-9]+}} = !{i32 1, !"target-abi", !"lp64d"}
 // LP64: !{{[0-9]+}} = !{i32 1, !"target-abi", !"lp64"}
 // LP64F: !{{[0-9]+}} = !{i32 1, !"target-abi", !"lp64f"}
 // LP64D: !{{[0-9]+}} = !{i32 1, !"target-abi", !"lp64d"}
Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -197,22 +197,7 @@
 // Ignore parsing error, just go 3rd step.
 consumeError(std::move(E));
   } else {
-bool HasD = ISAInfo.hasExtension("d");
- 

[PATCH] D103426: Clang: Extend format string checking to wprintf/wscanf

2021-07-25 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added inline comments.



Comment at: clang/lib/AST/Type.cpp:1962
 
+bool Type::isType(const std::string TypeName) const {
+  QualType Desugar = this->getLocallyUnqualifiedSingleStepDesugaredType();

MarcusJohnson91 wrote:
> efriedma wrote:
> > MarcusJohnson91 wrote:
> > > aaron.ballman wrote:
> > > > Oh, I see now that this is doing a name comparison against the type -- 
> > > > that's not a good API in general because it's *really* hard to guess at 
> > > > what the type will come out as textually. e.g., `class` and `struct` 
> > > > keywords are interchangeable in C++, C sometimes gets confused with 
> > > > `bool` vs `_Bool`, template arguments sometimes matter, nested name 
> > > > specifiers, etc. Callers of this API will have to guess at these 
> > > > details and the printing of the type may change over time (e.g., C may 
> > > > switch from `_Bool` to `bool` and then code calling `isType("_Bool")` 
> > > > may react poorly to the change).
> > > > 
> > > > I think we need to avoid this sort of API on `Type`.
> > > I see your point, I reverted the behavior back to doing the desugaring in 
> > > just isChar16Type and isChar32Type
> > I'm not convinced we should be looking at sugar even in 
> > isChar16Type/isChar32Type/isAnyCharacterType.  That seems like a great way 
> > to end up with subtle bugs that only manifest when someone uses the wrong 
> > typedef.
> > 
> > Where is the distinction between the value `(uint32_t)1` vs. `(char32_t)1` 
> > relevant for C, anyway?
> char32_t is a typedef, not a builtin type in C.
> 
> the underlying type is uint_least32_t, which is usually another typedef to 
> int.
> 
> in order for char32_t to be accepted in C mode, we have to know that it is a 
> string type and not just some random array, so I'm checking the sugar to see 
> if char32_t appears in the typedef chain.
> 
> 
You can't, in general, count on typedefs being present.  For example, `U"text"` 
won't have `char32_t` present in its type; the `char32_t` typedef definition 
won't even be present if `uchar.h` is not included.  All you can be 
(reasonably) assured of is that UTF-16 and UTF-32 literals will have a type 
that matches the underlying type of the `char16_t` and `char32_t` typedef 
definition (this can be violated for at least some compilers if you try hard, 
but that reflects an invalid configuration).


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

https://reviews.llvm.org/D103426

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


[clang] 9451403 - [OPENCL] opencl-c.h: add initial CL 3.0 conditionals for atomic operations.

2021-07-25 Thread Dave Airlie via cfe-commits

Author: Dave Airlie
Date: 2021-07-26T11:06:33+10:00
New Revision: 9451403c5f8c70c2ef022bd721db2b1c452eac79

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

LOG: [OPENCL] opencl-c.h: add initial CL 3.0 conditionals for atomic operations.

This adds the optional wrappers around things, however this isn't sufficient 
yet for CL 3.0 without generic address space, I've got one more additional 
patch to add all those APIs, but this is an easier to review precursor.

Reviewed By: Anastasia

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

Added: 


Modified: 
clang/lib/Headers/opencl-c-base.h
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index 7c724bc2e7a9..b5029a254b7a 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -353,7 +353,9 @@ typedef enum memory_order
   memory_order_acquire = __ATOMIC_ACQUIRE,
   memory_order_release = __ATOMIC_RELEASE,
   memory_order_acq_rel = __ATOMIC_ACQ_REL,
+#if defined(__opencl_c_atomic_order_seq_cst)
   memory_order_seq_cst = __ATOMIC_SEQ_CST
+#endif
 } memory_order;
 
 #endif // defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0)

diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 4be57058b33f..fc50dd718c4e 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -13304,7 +13304,10 @@ void __ovld atomic_init(volatile atomic_double 
*object, double value);
 void __ovld atomic_work_item_fence(cl_mem_fence_flags flags, memory_order 
order, memory_scope scope);
 
 // atomic_fetch()
+// OpenCL v2.0 s6.13.11.7.5:
+// add/sub: atomic type argument can be uintptr_t/intptr_t, value type 
argument can be ptr
diff _t.
 
+#if defined(__opencl_c_atomic_order_seq_cst) && 
defined(__opencl_c_atomic_scope_device)
 int __ovld atomic_fetch_add(volatile atomic_int *object, int operand);
 uint __ovld atomic_fetch_add(volatile atomic_uint *object, uint operand);
 int __ovld atomic_fetch_sub(volatile atomic_int *object, int operand);
@@ -13335,16 +13338,12 @@ long __ovld atomic_fetch_min(volatile atomic_long 
*object, long operand);
 ulong __ovld atomic_fetch_min(volatile atomic_ulong *object, ulong operand);
 long __ovld atomic_fetch_max(volatile atomic_long *object, long operand);
 ulong __ovld atomic_fetch_max(volatile atomic_ulong *object, ulong operand);
-#endif //defined(cl_khr_int64_base_atomics) && 
defined(cl_khr_int64_extended_atomics)
-
-// OpenCL v2.0 s6.13.11.7.5:
-// add/sub: atomic type argument can be uintptr_t/intptr_t, value type 
argument can be ptr
diff _t.
-
-#if defined(cl_khr_int64_base_atomics) && 
defined(cl_khr_int64_extended_atomics)
 uintptr_t __ovld atomic_fetch_add(volatile atomic_uintptr_t *object, ptr
diff _t operand);
 uintptr_t __ovld atomic_fetch_sub(volatile atomic_uintptr_t *object, ptr
diff _t operand);
+#endif //defined(cl_khr_int64_base_atomics) && 
defined(cl_khr_int64_extended_atomics)
 #endif
 
+#if defined(__opencl_c_atomic_scope_device)
 int __ovld atomic_fetch_add_explicit(volatile atomic_int *object, int operand, 
memory_order order);
 uint __ovld atomic_fetch_add_explicit(volatile atomic_uint *object, uint 
operand, memory_order order);
 int __ovld atomic_fetch_sub_explicit(volatile atomic_int *object, int operand, 
memory_order order);
@@ -13374,10 +13373,9 @@ long __ovld atomic_fetch_min_explicit(volatile 
atomic_long *object, long operand
 ulong __ovld atomic_fetch_min_explicit(volatile atomic_ulong *object, ulong 
operand, memory_order order);
 long __ovld atomic_fetch_max_explicit(volatile atomic_long *object, long 
operand, memory_order order);
 ulong __ovld atomic_fetch_max_explicit(volatile atomic_ulong *object, ulong 
operand, memory_order order);
-#endif //defined(cl_khr_int64_base_atomics) && 
defined(cl_khr_int64_extended_atomics)
-#if defined(cl_khr_int64_base_atomics) && 
defined(cl_khr_int64_extended_atomics)
 uintptr_t __ovld atomic_fetch_add_explicit(volatile atomic_uintptr_t *object, 
ptr
diff _t operand, memory_order order);
 uintptr_t __ovld atomic_fetch_sub_explicit(volatile atomic_uintptr_t *object, 
ptr
diff _t operand, memory_order order);
+#endif //defined(cl_khr_int64_base_atomics) && 
defined(cl_khr_int64_extended_atomics)
 #endif
 
 int __ovld atomic_fetch_add_explicit(volatile atomic_int *object, int operand, 
memory_order order, memory_scope scope);
@@ -13417,6 +13415,7 @@ uintptr_t __ovld atomic_fetch_sub_explicit(volatile 
atomic_uintptr_t *object, pt
 
 // atomic_store()
 
+#if defined(__opencl_c_atomic_order_seq_cst) && 
defined(__opencl_c_atomic_scope_device)
 void __ovld atomic_store(volatile atomic_int *object, int desired);
 void __ovld atomic_store(volatile atomic_uint 

[PATCH] D106111: opencl-c.h: add initial CL 3.0 conditionals for atomic operations.

2021-07-25 Thread Dave Airlie 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 rG9451403c5f8c: [OPENCL] opencl-c.h: add initial CL 3.0 
conditionals for atomic operations. (authored by airlied).

Changed prior to commit:
  https://reviews.llvm.org/D106111?vs=360349=361566#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106111

Files:
  clang/lib/Headers/opencl-c-base.h
  clang/lib/Headers/opencl-c.h

Index: clang/lib/Headers/opencl-c.h
===
--- clang/lib/Headers/opencl-c.h
+++ clang/lib/Headers/opencl-c.h
@@ -13304,7 +13304,10 @@
 void __ovld atomic_work_item_fence(cl_mem_fence_flags flags, memory_order order, memory_scope scope);
 
 // atomic_fetch()
+// OpenCL v2.0 s6.13.11.7.5:
+// add/sub: atomic type argument can be uintptr_t/intptr_t, value type argument can be ptrdiff_t.
 
+#if defined(__opencl_c_atomic_order_seq_cst) && defined(__opencl_c_atomic_scope_device)
 int __ovld atomic_fetch_add(volatile atomic_int *object, int operand);
 uint __ovld atomic_fetch_add(volatile atomic_uint *object, uint operand);
 int __ovld atomic_fetch_sub(volatile atomic_int *object, int operand);
@@ -13335,16 +13338,12 @@
 ulong __ovld atomic_fetch_min(volatile atomic_ulong *object, ulong operand);
 long __ovld atomic_fetch_max(volatile atomic_long *object, long operand);
 ulong __ovld atomic_fetch_max(volatile atomic_ulong *object, ulong operand);
-#endif //defined(cl_khr_int64_base_atomics) && defined(cl_khr_int64_extended_atomics)
-
-// OpenCL v2.0 s6.13.11.7.5:
-// add/sub: atomic type argument can be uintptr_t/intptr_t, value type argument can be ptrdiff_t.
-
-#if defined(cl_khr_int64_base_atomics) && defined(cl_khr_int64_extended_atomics)
 uintptr_t __ovld atomic_fetch_add(volatile atomic_uintptr_t *object, ptrdiff_t operand);
 uintptr_t __ovld atomic_fetch_sub(volatile atomic_uintptr_t *object, ptrdiff_t operand);
+#endif //defined(cl_khr_int64_base_atomics) && defined(cl_khr_int64_extended_atomics)
 #endif
 
+#if defined(__opencl_c_atomic_scope_device)
 int __ovld atomic_fetch_add_explicit(volatile atomic_int *object, int operand, memory_order order);
 uint __ovld atomic_fetch_add_explicit(volatile atomic_uint *object, uint operand, memory_order order);
 int __ovld atomic_fetch_sub_explicit(volatile atomic_int *object, int operand, memory_order order);
@@ -13374,10 +13373,9 @@
 ulong __ovld atomic_fetch_min_explicit(volatile atomic_ulong *object, ulong operand, memory_order order);
 long __ovld atomic_fetch_max_explicit(volatile atomic_long *object, long operand, memory_order order);
 ulong __ovld atomic_fetch_max_explicit(volatile atomic_ulong *object, ulong operand, memory_order order);
-#endif //defined(cl_khr_int64_base_atomics) && defined(cl_khr_int64_extended_atomics)
-#if defined(cl_khr_int64_base_atomics) && defined(cl_khr_int64_extended_atomics)
 uintptr_t __ovld atomic_fetch_add_explicit(volatile atomic_uintptr_t *object, ptrdiff_t operand, memory_order order);
 uintptr_t __ovld atomic_fetch_sub_explicit(volatile atomic_uintptr_t *object, ptrdiff_t operand, memory_order order);
+#endif //defined(cl_khr_int64_base_atomics) && defined(cl_khr_int64_extended_atomics)
 #endif
 
 int __ovld atomic_fetch_add_explicit(volatile atomic_int *object, int operand, memory_order order, memory_scope scope);
@@ -13417,6 +13415,7 @@
 
 // atomic_store()
 
+#if defined(__opencl_c_atomic_order_seq_cst) && defined(__opencl_c_atomic_scope_device)
 void __ovld atomic_store(volatile atomic_int *object, int desired);
 void __ovld atomic_store(volatile atomic_uint *object, uint desired);
 void __ovld atomic_store(volatile atomic_float *object, float desired);
@@ -13428,7 +13427,9 @@
 void __ovld atomic_store(volatile atomic_long *object, long desired);
 void __ovld atomic_store(volatile atomic_ulong *object, ulong desired);
 #endif
+#endif
 
+#if defined(__opencl_c_atomic_scope_device)
 void __ovld atomic_store_explicit(volatile atomic_int *object, int desired, memory_order order);
 void __ovld atomic_store_explicit(volatile atomic_uint *object, uint desired, memory_order order);
 void __ovld atomic_store_explicit(volatile atomic_float *object, float desired, memory_order order);
@@ -13439,6 +13440,7 @@
 void __ovld atomic_store_explicit(volatile atomic_long *object, long desired, memory_order order);
 void __ovld atomic_store_explicit(volatile atomic_ulong *object, ulong desired, memory_order order);
 #endif
+#endif
 
 void __ovld atomic_store_explicit(volatile atomic_int *object, int desired, memory_order order, memory_scope scope);
 void __ovld atomic_store_explicit(volatile atomic_uint *object, uint desired, memory_order order, memory_scope scope);
@@ -13452,7 +13454,7 @@
 #endif
 
 // atomic_load()
-
+#if defined(__opencl_c_atomic_order_seq_cst) && defined(__opencl_c_atomic_scope_device)
 int __ovld 

[PATCH] D106757: [PowerPC] Implement partial vector ld/st builtins for XL compatibility

2021-07-25 Thread Albion Fung via Phabricator via cfe-commits
Conanap accepted this revision.
Conanap added a comment.
This revision is now accepted and ready to land.

Thanks for answering the Qs. LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106757

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


[PATCH] D106753: ConvertUTF: Created wrapper convertUTF32ToUTF8String

2021-07-25 Thread Marcus Johnson via Phabricator via cfe-commits
MarcusJohnson91 added a comment.

Anyone got any ideas what happened this time?


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

https://reviews.llvm.org/D106753

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


[PATCH] D105320: [CodeView] Saturate values bigger than supported by APInt.

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

.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105320

Files:
  llvm/include/llvm/ADT/APInt.h
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
  llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/test/DebugInfo/COFF/integer-128.ll

Index: llvm/test/DebugInfo/COFF/integer-128.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/COFF/integer-128.ll
@@ -0,0 +1,136 @@
+; RUN: llc < %s | FileCheck %s --check-prefix=ASM
+
+; // C++ source to regenerate:
+; enum class uns : __uint128_t { unsval = __uint128_t(1) << 64 };
+; uns t1() { return uns::unsval; }
+; enum class sig : __int128 { sigval = -(__int128(1) << 64) };
+; sig t2() { return sig::sigval; }
+; struct test {
+;   static const __uint128_t u128 = __uint128_t(1) << 64;
+;   static const __int128s128 = -(__int128(1) << 64);
+; };
+; test t3() { return test(); }
+; 
+; $ clang a.cpp -S -emit-llvm -g -gcodeview
+
+; --
+
+; ASM-LABEL: .long   241 # Symbol subsection for globals
+;
+; ASM-LABEL: .short	4359# Record kind: S_CONSTANT
+; ASM-NEXT:  .long	4110# Type
+; ASM-NEXT:  .byte	0x0a, 0x80, 0xff, 0xff  # Value
+; ASM-NEXT:  .byte	0xff, 0xff, 0xff, 0xff
+; ASM-NEXT:  .byte	0xff, 0xff
+; ASM-NEXT:  .asciz	"test::u128"# Name
+; ASM-NEXT:  .p2align	2
+;
+; ASM-LABEL: .short	4359# Record kind: S_CONSTANT
+; ASM-NEXT:  .long	4111# Type
+; ASM-NEXT:  .byte	0x09, 0x80, 0x00, 0x00  # Value
+; ASM-NEXT:  .byte	0x00, 0x00, 0x00, 0x00
+; ASM-NEXT:  .byte	0x00, 0x80
+; ASM-NEXT:  .asciz	"test::s128"# Name
+; ASM-NEXT:  .p2align	2
+;
+; ASM-LABEL: .short	0x1203  # Record kind: LF_FIELDLIST
+; ASM-NEXT:  .short	0x1502  # Member kind: Enumerator ( LF_ENUMERATE )
+; ASM-NEXT:  .short	0x3 # Attrs: Public
+; ASM-NEXT:  .short	0x800a
+; ASM-NEXT:  .quad	0x  # EnumValue
+; ASM-NEXT:  .asciz	"unsval"# Name
+;
+; ASM-LABEL: .short	0x1203  # Record kind: LF_FIELDLIST
+; ASM-NEXT:  .short	0x1502  # Member kind: Enumerator ( LF_ENUMERATE )
+; ASM-NEXT:  .short	0x3 # Attrs: Public
+; ASM-NEXT:  .short	0x800a
+; ASM-NEXT:  .quad	0x  # EnumValue
+; ASM-NEXT:  .asciz	"sigval"# Name
+
+; --
+
+; ModuleID = 'a.cpp'
+source_filename = "a.cpp"
+target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-windows-gnu"
+
+%struct.test = type { i8 }
+
+; Function Attrs: mustprogress noinline nounwind optnone
+define dso_local <2 x i64> @_Z2t1v() #0 !dbg !23 {
+entry:
+  %retval = alloca i128, align 16
+  store i128 18446744073709551616, i128* %retval, align 16, !dbg !27
+  %0 = bitcast i128* %retval to <2 x i64>*, !dbg !27
+  %1 = load <2 x i64>, <2 x i64>* %0, align 16, !dbg !27
+  ret <2 x i64> %1, !dbg !27
+}
+
+; Function Attrs: mustprogress noinline nounwind optnone
+define dso_local <2 x i64> @_Z2t2v() #0 !dbg !28 {
+entry:
+  %retval = alloca i128, align 16
+  store i128 -18446744073709551616, i128* %retval, align 16, !dbg !31
+  %0 = bitcast i128* %retval to <2 x i64>*, !dbg !31
+  %1 = load <2 x i64>, <2 x i64>* %0, align 16, !dbg !31
+  ret <2 x i64> %1, !dbg !31
+}
+
+; Function Attrs: mustprogress noinline nounwind optnone
+define dso_local i8 @_Z2t3v() #1 !dbg !32 {
+entry:
+  %retval = alloca %struct.test, align 1
+  %coerce.dive = getelementptr inbounds %struct.test, %struct.test* %retval, i32 0, i32 0, !dbg !41
+  %0 = load i8, i8* %coerce.dive, align 1, !dbg !41
+  ret i8 %0, !dbg !41
+}
+
+attributes #0 = { mustprogress noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="128" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
+attributes #1 = { mustprogress noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!19, !20, !21}
+!llvm.ident = !{!22}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 13.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, 

[PATCH] D105320: [CodeView] Saturate values bigger than supported by APInt.

2021-07-25 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 361543.
mizvekov marked 4 inline comments as done.
mizvekov added a comment.

- Expose and use APInt::isSingleWord.
- Use ApInt::getLimitedValue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105320

Files:
  llvm/include/llvm/ADT/APInt.h
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
  llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/test/DebugInfo/COFF/integer-128.ll

Index: llvm/test/DebugInfo/COFF/integer-128.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/COFF/integer-128.ll
@@ -0,0 +1,136 @@
+; RUN: llc < %s | FileCheck %s --check-prefix=ASM
+
+; // C++ source to regenerate:
+; enum class uns : __uint128_t { unsval = __uint128_t(1) << 64 };
+; uns t1() { return uns::unsval; }
+; enum class sig : __int128 { sigval = -(__int128(1) << 64) };
+; sig t2() { return sig::sigval; }
+; struct test {
+;   static const __uint128_t u128 = __uint128_t(1) << 64;
+;   static const __int128s128 = -(__int128(1) << 64);
+; };
+; test t3() { return test(); }
+; 
+; $ clang a.cpp -S -emit-llvm -g -gcodeview
+
+; --
+
+; ASM-LABEL: .long   241 # Symbol subsection for globals
+;
+; ASM-LABEL: .short	4359# Record kind: S_CONSTANT
+; ASM-NEXT:  .long	4110# Type
+; ASM-NEXT:  .byte	0x0a, 0x80, 0xff, 0xff  # Value
+; ASM-NEXT:  .byte	0xff, 0xff, 0xff, 0xff
+; ASM-NEXT:  .byte	0xff, 0xff
+; ASM-NEXT:  .asciz	"test::u128"# Name
+; ASM-NEXT:  .p2align	2
+;
+; ASM-LABEL: .short	4359# Record kind: S_CONSTANT
+; ASM-NEXT:  .long	4111# Type
+; ASM-NEXT:  .byte	0x09, 0x80, 0x00, 0x00  # Value
+; ASM-NEXT:  .byte	0x00, 0x00, 0x00, 0x00
+; ASM-NEXT:  .byte	0x00, 0x80
+; ASM-NEXT:  .asciz	"test::s128"# Name
+; ASM-NEXT:  .p2align	2
+;
+; ASM-LABEL: .short	0x1203  # Record kind: LF_FIELDLIST
+; ASM-NEXT:  .short	0x1502  # Member kind: Enumerator ( LF_ENUMERATE )
+; ASM-NEXT:  .short	0x3 # Attrs: Public
+; ASM-NEXT:  .short	0x800a
+; ASM-NEXT:  .quad	0x  # EnumValue
+; ASM-NEXT:  .asciz	"unsval"# Name
+;
+; ASM-LABEL: .short	0x1203  # Record kind: LF_FIELDLIST
+; ASM-NEXT:  .short	0x1502  # Member kind: Enumerator ( LF_ENUMERATE )
+; ASM-NEXT:  .short	0x3 # Attrs: Public
+; ASM-NEXT:  .short	0x800a
+; ASM-NEXT:  .quad	0x  # EnumValue
+; ASM-NEXT:  .asciz	"sigval"# Name
+
+; --
+
+; ModuleID = 'a.cpp'
+source_filename = "a.cpp"
+target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-windows-gnu"
+
+%struct.test = type { i8 }
+
+; Function Attrs: mustprogress noinline nounwind optnone
+define dso_local <2 x i64> @_Z2t1v() #0 !dbg !23 {
+entry:
+  %retval = alloca i128, align 16
+  store i128 18446744073709551616, i128* %retval, align 16, !dbg !27
+  %0 = bitcast i128* %retval to <2 x i64>*, !dbg !27
+  %1 = load <2 x i64>, <2 x i64>* %0, align 16, !dbg !27
+  ret <2 x i64> %1, !dbg !27
+}
+
+; Function Attrs: mustprogress noinline nounwind optnone
+define dso_local <2 x i64> @_Z2t2v() #0 !dbg !28 {
+entry:
+  %retval = alloca i128, align 16
+  store i128 -18446744073709551616, i128* %retval, align 16, !dbg !31
+  %0 = bitcast i128* %retval to <2 x i64>*, !dbg !31
+  %1 = load <2 x i64>, <2 x i64>* %0, align 16, !dbg !31
+  ret <2 x i64> %1, !dbg !31
+}
+
+; Function Attrs: mustprogress noinline nounwind optnone
+define dso_local i8 @_Z2t3v() #1 !dbg !32 {
+entry:
+  %retval = alloca %struct.test, align 1
+  %coerce.dive = getelementptr inbounds %struct.test, %struct.test* %retval, i32 0, i32 0, !dbg !41
+  %0 = load i8, i8* %coerce.dive, align 1, !dbg !41
+  ret i8 %0, !dbg !41
+}
+
+attributes #0 = { mustprogress noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="128" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
+attributes #1 = { mustprogress noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!19, !20, !21}
+!llvm.ident = !{!22}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, 

[PATCH] D105951: [clang] P2266 implicit moves STL workaround

2021-07-25 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

If you think landing this in 13 after the release branch is created will be 
complicated, then please consider this message a gentle **Ping** :)

Frankly, I am satisfied with the mechanics of this workaround as is.

- After another look, I think doing something more targeted will be unduly 
convoluted, as we would want to target particular function overloads, one which 
is an operator>>.
- The STL will still be tested upstream, with "-fno-mscompatibility".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105951

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


[PATCH] D103426: Clang: Extend format string checking to wprintf/wscanf

2021-07-25 Thread Marcus Johnson via Phabricator via cfe-commits
MarcusJohnson91 marked 5 inline comments as done.
MarcusJohnson91 added inline comments.



Comment at: clang/lib/AST/Expr.cpp:1091
+  if (llvm::convertUTF32ToUTF8String(AR, Output)) {
+CString = new char[Output.size() + 1];
+memcpy(CString, Output.c_str(), Output.size());

efriedma wrote:
> This leaks memory.
> 
> This function should return either a StringRef to memory that's part of AST 
> object, or an std::string.
I've switched over to using getStringAsChar and doing the conversion there 
instead of in getStrDataAsChar, on the other patch. (just going through this 
review to see if I missed any feedback)



Comment at: clang/lib/AST/Type.cpp:1962
 
+bool Type::isType(const std::string TypeName) const {
+  QualType Desugar = this->getLocallyUnqualifiedSingleStepDesugaredType();

efriedma wrote:
> MarcusJohnson91 wrote:
> > aaron.ballman wrote:
> > > Oh, I see now that this is doing a name comparison against the type -- 
> > > that's not a good API in general because it's *really* hard to guess at 
> > > what the type will come out as textually. e.g., `class` and `struct` 
> > > keywords are interchangeable in C++, C sometimes gets confused with 
> > > `bool` vs `_Bool`, template arguments sometimes matter, nested name 
> > > specifiers, etc. Callers of this API will have to guess at these details 
> > > and the printing of the type may change over time (e.g., C may switch 
> > > from `_Bool` to `bool` and then code calling `isType("_Bool")` may react 
> > > poorly to the change).
> > > 
> > > I think we need to avoid this sort of API on `Type`.
> > I see your point, I reverted the behavior back to doing the desugaring in 
> > just isChar16Type and isChar32Type
> I'm not convinced we should be looking at sugar even in 
> isChar16Type/isChar32Type/isAnyCharacterType.  That seems like a great way to 
> end up with subtle bugs that only manifest when someone uses the wrong 
> typedef.
> 
> Where is the distinction between the value `(uint32_t)1` vs. `(char32_t)1` 
> relevant for C, anyway?
char32_t is a typedef, not a builtin type in C.

the underlying type is uint_least32_t, which is usually another typedef to int.

in order for char32_t to be accepted in C mode, we have to know that it is a 
string type and not just some random array, so I'm checking the sugar to see if 
char32_t appears in the typedef chain.




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

https://reviews.llvm.org/D103426

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


[PATCH] D106756: Added l16/l32 length modifiers for char16_t/char32_t

2021-07-25 Thread Marcus Johnson via Phabricator via cfe-commits
MarcusJohnson91 updated this revision to Diff 361539.
MarcusJohnson91 added a comment.

Clang-formatted the diff


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

https://reviews.llvm.org/D106756

Files:
  clang/include/clang/AST/FormatString.h
  clang/lib/AST/FormatString.cpp

Index: clang/lib/AST/FormatString.cpp
===
--- clang/lib/AST/FormatString.cpp
+++ clang/lib/AST/FormatString.cpp
@@ -520,6 +520,12 @@
 case WCStrTy:
   Res = C.getPointerType(C.getWideCharType());
   break;
+case Char16Ty:
+  Res = C.getPointerType(C.getChar16Type());
+  break;
+case Char32Ty:
+  Res = C.getPointerType(C.getChar32Type());
+  break;
 case ObjCPointerTy:
   Res = C.ObjCBuiltinIdTy;
   break;
@@ -607,6 +613,10 @@
 return "m";
   case AsWide:
 return "w";
+  case AsUTF16:
+return "l16";
+  case AsUTF32:
+return "l32";
   case None:
 return "";
   }
@@ -860,6 +870,17 @@
 default:
   return false;
   }
+case LengthModifier::AsUTF16:
+case LengthModifier::AsUTF32:
+  switch (CS.getKind()) {
+  case ConversionSpecifier::cArg:
+  case ConversionSpecifier::CArg:
+  case ConversionSpecifier::sArg:
+  case ConversionSpecifier::SArg:
+return true;
+  default:
+return false;
+  }
 case LengthModifier::AsWide:
   switch (CS.getKind()) {
 case ConversionSpecifier::cArg:
@@ -886,6 +907,8 @@
 case LengthModifier::AsSizeT:
 case LengthModifier::AsPtrDiff:
 case LengthModifier::AsLongDouble:
+case LengthModifier::AsUTF16:
+case LengthModifier::AsUTF32:
   return true;
 case LengthModifier::AsAllocate:
 case LengthModifier::AsMAllocate:
@@ -997,6 +1020,12 @@
 } else if (Identifier->getName() == "ptrdiff_t") {
   LM.setKind(LengthModifier::AsPtrDiff);
   return true;
+} else if (Identifier->getName() == "char16_t") {
+  LM.setKind(LengthModifier::AsUTF16);
+  return true;
+} else if (Identifier->getName() == "char32_t") {
+  LM.setKind(LengthModifier::AsUTF32);
+  return true;
 }
 
 QualType T = Typedef->getUnderlyingType();
Index: clang/include/clang/AST/FormatString.h
===
--- clang/include/clang/AST/FormatString.h
+++ clang/include/clang/AST/FormatString.h
@@ -65,22 +65,24 @@
 public:
   enum Kind {
 None,
-AsChar,   // 'hh'
-AsShort,  // 'h'
-AsShortLong,  // 'hl' (OpenCL float/int vector element)
-AsLong,   // 'l'
-AsLongLong,   // 'll'
-AsQuad,   // 'q' (BSD, deprecated, for 64-bit integer types)
-AsIntMax, // 'j'
-AsSizeT,  // 'z'
-AsPtrDiff,// 't'
-AsInt32,  // 'I32' (MSVCRT, like __int32)
-AsInt3264,// 'I'   (MSVCRT, like __int3264 from MIDL)
-AsInt64,  // 'I64' (MSVCRT, like __int64)
-AsLongDouble, // 'L'
-AsAllocate,   // for '%as', GNU extension to C90 scanf
-AsMAllocate,  // for '%ms', GNU extension to scanf
-AsWide,   // 'w' (MSVCRT, like l but only for c, C, s, S, or Z
+AsChar, // 'hh'
+AsShort,// 'h'
+AsShortLong,// 'hl' (OpenCL float/int vector element)
+AsLong, // 'l'
+AsLongLong, // 'll'
+AsQuad, // 'q' (BSD, deprecated, for 64-bit integer types)
+AsIntMax,   // 'j'
+AsSizeT,// 'z'
+AsPtrDiff,  // 't'
+AsInt32,// 'I32' (MSVCRT, like __int32)
+AsInt3264,  // 'I'   (MSVCRT, like __int3264 from MIDL)
+AsInt64,// 'I64' (MSVCRT, like __int64)
+AsLongDouble,   // 'L'
+AsAllocate, // for '%as', GNU extension to C90 scanf
+AsMAllocate,// for '%ms', GNU extension to scanf
+AsUTF16,// for '%l16(c|s)', Clang extension
+AsUTF32,// for '%l32(c|s)', Clang extension
+AsWide, // 'w' (MSVCRT, like l but only for c, C, s, S, or Z
 AsWideChar = AsLong // for '%ls', only makes sense for printf
   };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106755: Extended format string checking to wprintf/wscanf

2021-07-25 Thread Marcus Johnson via Phabricator via cfe-commits
MarcusJohnson91 updated this revision to Diff 361538.
MarcusJohnson91 added a comment.

Clang-formatted the diff.


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

https://reviews.llvm.org/D106755

Files:
  clang-tools-extra/clang-tidy/boost/UseToStringCheck.cpp
  clang-tools-extra/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/FormatString.h
  clang/include/clang/AST/Type.h
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/OSLog.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprObjC.cpp
  clang/lib/Sema/SemaFixItUtils.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
  clang/test/Sema/format-strings-c90.c
  clang/test/Sema/format-strings-darwin.c
  clang/test/Sema/format-strings-int-typedefs.c
  clang/test/Sema/format-strings-ms.c
  clang/test/Sema/format-strings-non-iso.c
  clang/test/Sema/format-strings-pedantic.c
  clang/test/Sema/format-strings-scanf.c
  clang/test/Sema/string-plus-char.c
  clang/test/SemaCXX/format-strings-0x.cpp
  clang/test/SemaCXX/format-strings.cpp

Index: clang/test/SemaCXX/format-strings.cpp
===
--- clang/test/SemaCXX/format-strings.cpp
+++ clang/test/SemaCXX/format-strings.cpp
@@ -3,11 +3,15 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -Wformat-non-iso -fblocks -std=c++11 %s
 
 #include 
+#include 
 
 extern "C" {
 extern int scanf(const char *restrict, ...);
 extern int printf(const char *restrict, ...);
 extern int vprintf(const char *restrict, va_list);
+extern int wscanf(const wchar_t *restrict, ...);
+extern int wprintf(const wchar_t *restrict, ...);
+extern int vwprintf(const wchar_t *restrict, va_list);
 }
 
 void f(char **sp, float *fp) {
@@ -18,12 +22,23 @@
   // expected-warning@-4 {{format specifies type 'float *' but the argument has type 'char **'}}
 #endif
 
+  scanf("%as", sp);
+#if __cplusplus <= 199711L
+  // expected-warning@-2 {{'a' length modifier is not supported by ISO C}}
+#else
+  // expected-warning@-4 {{format specifies type 'float *' but the argument has type 'wchar_t **'}}
+#endif
+
   printf("%a", 1.0);
   scanf("%afoobar", fp);
+
+  wprintf("%a", 1.0);
+  wscanf("%afoobar", fp);
 }
 
 void g() {
   printf("%ls", "foo"); // expected-warning{{format specifies type 'wchar_t *' but the argument has type 'const char *'}}
+  wprintf("%ls", "foo"); // expected-warning{{format specifies type 'wchar_t *' but the argument has type 'const char *'}}
 }
 
 // Test that we properly handle format_idx on C++ members.
Index: clang/test/SemaCXX/format-strings-0x.cpp
===
--- clang/test/SemaCXX/format-strings-0x.cpp
+++ clang/test/SemaCXX/format-strings-0x.cpp
@@ -3,33 +3,53 @@
 extern "C" {
 extern int scanf(const char *restrict, ...);
 extern int printf(const char *restrict, ...);
+extern int wscanf(const wchar_t *restrict, ...);
 }
 
 void f(char **sp, float *fp) {
   scanf("%as", sp); // expected-warning{{format specifies type 'float *' but the argument has type 'char **'}}
+  wscanf("%as", sp); // expected-warning{{format specifies type 'float *' but the argument has type 'wchar_t **'}}
 
   printf("%p", sp); // expected-warning{{format specifies type 'void *' but the argument has type 'char **'}}
+  wprintf("%p", sp); // expected-warning{{format specifies type 'void *' but the argument has type 'wchar_t **'}}
   scanf("%p", sp);  // expected-warning{{format specifies type 'void **' but the argument has type 'char **'}}
+  wscanf("%p", sp); // expected-warning{{format specifies type 'void **' but the argument has type 'wchar_t **'}}
 
   printf("%a", 1.0);
   scanf("%afoobar", fp);
+  wprintf("%a", 1.0);
+  wscanf("%afoobar", fp);
   printf(nullptr);
   printf(*sp); // expected-warning {{not a string literal}}
   // expected-note@-1{{treat the string as an argument to avoid this}}
+  wprintf(*sp); // expected-warning {{not a string literal}}
+  // expected-note@-1{{treat the string as an argument to avoid this}}
 
   // PR13099
   printf(
 R"foobar(%)foobar"
 R"bazquux(d)bazquux" // expected-warning {{more '%' conversions than data arguments}}
 R"xyzzy()xyzzy");
+  wprintf(
+  R"foobar(%)foobar"
+  R"bazquux(d)bazquux" // expected-warning {{more '%' conversions than data arguments}}
+  R"xyzzy()xyzzy");
 
   printf(u8"this is %d test", 0); // ok
+  wprintf(u8"this is %d test", 0); // ok
   printf(u8R"foo(
   \u1234\U0010fffe
  

[PATCH] D106753: ConvertUTF: Created wrapper convertUTF32ToUTF8String

2021-07-25 Thread Marcus Johnson via Phabricator via cfe-commits
MarcusJohnson91 updated this revision to Diff 361535.
MarcusJohnson91 marked an inline comment as done.
MarcusJohnson91 added a comment.

Implemented the fixes mentioned and reformatted the patch


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

https://reviews.llvm.org/D106753

Files:
  llvm/include/llvm/Support/ConvertUTF.h
  llvm/lib/Support/ConvertUTFWrapper.cpp
  llvm/unittests/Support/ConvertUTFTest.cpp

Index: llvm/unittests/Support/ConvertUTFTest.cpp
===
--- llvm/unittests/Support/ConvertUTFTest.cpp
+++ llvm/unittests/Support/ConvertUTFTest.cpp
@@ -36,6 +36,28 @@
   EXPECT_EQ(Expected, Result);
 }
 
+TEST(ConvertUTFTest, ConvertUTF32LittleEndianToUTF8String) {
+  // Src is the look of disapproval.
+  alignas(UTF32) static const char Src[] = "\xff\xfe\xa0\x0c_\x00\xa0\x0c";
+  ArrayRef Ref(Src, sizeof(Src) - 1);
+  std::string Result;
+  bool Success = convertUTF32ToUTF8String(Ref, Result);
+  EXPECT_TRUE(Success);
+  std::string Expected("\xe0\xb2\xa0_\xe0\xb2\xa0");
+  EXPECT_EQ(Expected, Result);
+}
+
+TEST(ConvertUTFTest, ConvertUTF32BigEndianToUTF8String) {
+  // Src is the look of disapproval.
+  alignas(UTF32) static const char Src[] = "\xfe\xff\x0c\xa0\x00_\x0c\xa0";
+  ArrayRef Ref(Src, sizeof(Src) - 1);
+  std::string Result;
+  bool Success = convertUTF32ToUTF8String(Ref, Result);
+  EXPECT_TRUE(Success);
+  std::string Expected("\xe0\xb2\xa0_\xe0\xb2\xa0");
+  EXPECT_EQ(Expected, Result);
+}
+
 TEST(ConvertUTFTest, ConvertUTF8ToUTF16String) {
   // Src is the look of disapproval.
   static const char Src[] = "\xe0\xb2\xa0_\xe0\xb2\xa0";
@@ -78,6 +100,33 @@
   EXPECT_FALSE(HasBOM);
 }
 
+TEST(ConvertUTFTest, HasUTF32BOM) {
+  bool HasBOM = hasUTF32ByteOrderMark(makeArrayRef("\x00\x00\xfe\xff", 4));
+  EXPECT_TRUE(HasBOM);
+  HasBOM = hasUTF32ByteOrderMark(makeArrayRef("\xff\xfe\x00\x00", 4));
+  EXPECT_TRUE(HasBOM);
+  HasBOM = hasUTF32ByteOrderMark(makeArrayRef("\x00\x00\xfe\xff ", 5));
+  EXPECT_TRUE(HasBOM); // Don't care about odd lengths.
+  HasBOM = hasUTF32ByteOrderMark(makeArrayRef("\x00\x00\xfe\xff\x00asdf", 9));
+  EXPECT_TRUE(HasBOM);
+
+  HasBOM = hasUTF32ByteOrderMark(None);
+  EXPECT_FALSE(HasBOM);
+  HasBOM = hasUTF32ByteOrderMark(makeArrayRef("\xfe", 1));
+  EXPECT_FALSE(HasBOM);
+}
+
+TEST(ConvertUTFTest, UTF32WrappersForConvertUTF32ToUTF8String) {
+  // Src is the look of disapproval.
+  alignas(UTF32) static const char Src[] = "\xff\xfe\xa0\x0c_\x00\xa0\x0c";
+  ArrayRef SrcRef = makeArrayRef((const UTF32 *)Src, 4);
+  std::string Result;
+  bool Success = convertUTF32ToUTF8String(SrcRef, Result);
+  EXPECT_TRUE(Success);
+  std::string Expected("\xe0\xb2\xa0_\xe0\xb2\xa0");
+  EXPECT_EQ(Expected, Result);
+}
+
 TEST(ConvertUTFTest, UTF16WrappersForConvertUTF16ToUTF8String) {
   // Src is the look of disapproval.
   alignas(UTF16) static const char Src[] = "\xff\xfe\xa0\x0c_\x00\xa0\x0c";
Index: llvm/lib/Support/ConvertUTFWrapper.cpp
===
--- llvm/lib/Support/ConvertUTFWrapper.cpp
+++ llvm/lib/Support/ConvertUTFWrapper.cpp
@@ -83,6 +83,13 @@
(S[0] == '\xfe' && S[1] == '\xff')));
 }
 
+bool hasUTF32ByteOrderMark(ArrayRef S) {
+  return (
+  S.size() >= 4 &&
+  ((S[0] == '\x00' && S[1] == '\x00' && S[2] == '\xfe' && S[3] == '\xff') ||
+   (S[0] == '\xff' && S[1] == '\xfe' && S[2] == '\x00' && S[3] == '\x00')));
+}
+
 bool convertUTF16ToUTF8String(ArrayRef SrcBytes, std::string ) {
   assert(Out.empty());
 
@@ -141,6 +148,64 @@
   Src.size() * sizeof(UTF16)), Out);
 }
 
+bool convertUTF32ToUTF8String(ArrayRef SrcBytes, std::string ) {
+  assert(Out.empty());
+
+  // Error out on an uneven byte count.
+  if (SrcBytes.size() % 4)
+return false;
+
+  // Avoid OOB by returning early on empty input.
+  if (SrcBytes.empty())
+return true;
+
+  const UTF32 *Src = reinterpret_cast(SrcBytes.begin());
+  const UTF32 *SrcEnd = reinterpret_cast(SrcBytes.end());
+
+  assert((uintptr_t)Src % sizeof(UTF32) == 0);
+
+  // Byteswap if necessary.
+  std::vector ByteSwapped;
+  if (Src[0] == UNI_UTF32_BYTE_ORDER_MARK_SWAPPED) {
+ByteSwapped.insert(ByteSwapped.end(), Src, SrcEnd);
+for (unsigned I = 0, E = ByteSwapped.size(); I != E; ++I)
+  ByteSwapped[I] = llvm::ByteSwap_32(ByteSwapped[I]);
+Src = [0];
+SrcEnd = [ByteSwapped.size() - 1] + 1;
+  }
+
+  // Skip the BOM for conversion.
+  if (Src[0] == UNI_UTF32_BYTE_ORDER_MARK_NATIVE)
+Src++;
+
+  // Just allocate enough space up front.  We'll shrink it later.  Allocate
+  // enough that we can fit a null terminator without reallocating.
+  Out.resize(SrcBytes.size() * UNI_MAX_UTF8_BYTES_PER_CODE_POINT + 1);
+  UTF8 *Dst = reinterpret_cast([0]);
+  UTF8 *DstEnd = Dst + Out.size();
+
+  ConversionResult CR =
+  ConvertUTF32toUTF8(, SrcEnd, , DstEnd, strictConversion);
+  assert(CR != targetExhausted);
+
+  if (CR != conversionOK) {
+

[PATCH] D106755: Extended format string checking to wprintf/wscanf

2021-07-25 Thread Marcus Johnson via Phabricator via cfe-commits
MarcusJohnson91 updated this revision to Diff 361534.
MarcusJohnson91 added a comment.
Herald added subscribers: llvm-commits, dexonsmith, hiraditya.
Herald added a project: LLVM.

Implemented the fixes mentioned and reformatted the patch


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

https://reviews.llvm.org/D106755

Files:
  llvm/include/llvm/Support/ConvertUTF.h
  llvm/lib/Support/ConvertUTFWrapper.cpp
  llvm/unittests/Support/ConvertUTFTest.cpp

Index: llvm/unittests/Support/ConvertUTFTest.cpp
===
--- llvm/unittests/Support/ConvertUTFTest.cpp
+++ llvm/unittests/Support/ConvertUTFTest.cpp
@@ -36,6 +36,28 @@
   EXPECT_EQ(Expected, Result);
 }
 
+TEST(ConvertUTFTest, ConvertUTF32LittleEndianToUTF8String) {
+  // Src is the look of disapproval.
+  alignas(UTF32) static const char Src[] = "\xff\xfe\xa0\x0c_\x00\xa0\x0c";
+  ArrayRef Ref(Src, sizeof(Src) - 1);
+  std::string Result;
+  bool Success = convertUTF32ToUTF8String(Ref, Result);
+  EXPECT_TRUE(Success);
+  std::string Expected("\xe0\xb2\xa0_\xe0\xb2\xa0");
+  EXPECT_EQ(Expected, Result);
+}
+
+TEST(ConvertUTFTest, ConvertUTF32BigEndianToUTF8String) {
+  // Src is the look of disapproval.
+  alignas(UTF32) static const char Src[] = "\xfe\xff\x0c\xa0\x00_\x0c\xa0";
+  ArrayRef Ref(Src, sizeof(Src) - 1);
+  std::string Result;
+  bool Success = convertUTF32ToUTF8String(Ref, Result);
+  EXPECT_TRUE(Success);
+  std::string Expected("\xe0\xb2\xa0_\xe0\xb2\xa0");
+  EXPECT_EQ(Expected, Result);
+}
+
 TEST(ConvertUTFTest, ConvertUTF8ToUTF16String) {
   // Src is the look of disapproval.
   static const char Src[] = "\xe0\xb2\xa0_\xe0\xb2\xa0";
@@ -78,6 +100,33 @@
   EXPECT_FALSE(HasBOM);
 }
 
+TEST(ConvertUTFTest, HasUTF32BOM) {
+  bool HasBOM = hasUTF32ByteOrderMark(makeArrayRef("\x00\x00\xfe\xff", 4));
+  EXPECT_TRUE(HasBOM);
+  HasBOM = hasUTF32ByteOrderMark(makeArrayRef("\xff\xfe\x00\x00", 4));
+  EXPECT_TRUE(HasBOM);
+  HasBOM = hasUTF32ByteOrderMark(makeArrayRef("\x00\x00\xfe\xff ", 5));
+  EXPECT_TRUE(HasBOM); // Don't care about odd lengths.
+  HasBOM = hasUTF32ByteOrderMark(makeArrayRef("\x00\x00\xfe\xff\x00asdf", 9));
+  EXPECT_TRUE(HasBOM);
+
+  HasBOM = hasUTF32ByteOrderMark(None);
+  EXPECT_FALSE(HasBOM);
+  HasBOM = hasUTF32ByteOrderMark(makeArrayRef("\xfe", 1));
+  EXPECT_FALSE(HasBOM);
+}
+
+TEST(ConvertUTFTest, UTF32WrappersForConvertUTF32ToUTF8String) {
+  // Src is the look of disapproval.
+  alignas(UTF32) static const char Src[] = "\xff\xfe\xa0\x0c_\x00\xa0\x0c";
+  ArrayRef SrcRef = makeArrayRef((const UTF32 *)Src, 4);
+  std::string Result;
+  bool Success = convertUTF32ToUTF8String(SrcRef, Result);
+  EXPECT_TRUE(Success);
+  std::string Expected("\xe0\xb2\xa0_\xe0\xb2\xa0");
+  EXPECT_EQ(Expected, Result);
+}
+
 TEST(ConvertUTFTest, UTF16WrappersForConvertUTF16ToUTF8String) {
   // Src is the look of disapproval.
   alignas(UTF16) static const char Src[] = "\xff\xfe\xa0\x0c_\x00\xa0\x0c";
Index: llvm/lib/Support/ConvertUTFWrapper.cpp
===
--- llvm/lib/Support/ConvertUTFWrapper.cpp
+++ llvm/lib/Support/ConvertUTFWrapper.cpp
@@ -83,6 +83,13 @@
(S[0] == '\xfe' && S[1] == '\xff')));
 }
 
+bool hasUTF32ByteOrderMark(ArrayRef S) {
+  return (
+  S.size() >= 4 &&
+  ((S[0] == '\x00' && S[1] == '\x00' && S[2] == '\xfe' && S[3] == '\xff') ||
+   (S[0] == '\xff' && S[1] == '\xfe' && S[2] == '\x00' && S[3] == '\x00')));
+}
+
 bool convertUTF16ToUTF8String(ArrayRef SrcBytes, std::string ) {
   assert(Out.empty());
 
@@ -141,6 +148,64 @@
   Src.size() * sizeof(UTF16)), Out);
 }
 
+bool convertUTF32ToUTF8String(ArrayRef SrcBytes, std::string ) {
+  assert(Out.empty());
+
+  // Error out on an uneven byte count.
+  if (SrcBytes.size() % 4)
+return false;
+
+  // Avoid OOB by returning early on empty input.
+  if (SrcBytes.empty())
+return true;
+
+  const UTF32 *Src = reinterpret_cast(SrcBytes.begin());
+  const UTF32 *SrcEnd = reinterpret_cast(SrcBytes.end());
+
+  assert((uintptr_t)Src % sizeof(UTF32) == 0);
+
+  // Byteswap if necessary.
+  std::vector ByteSwapped;
+  if (Src[0] == UNI_UTF32_BYTE_ORDER_MARK_SWAPPED) {
+ByteSwapped.insert(ByteSwapped.end(), Src, SrcEnd);
+for (unsigned I = 0, E = ByteSwapped.size(); I != E; ++I)
+  ByteSwapped[I] = llvm::ByteSwap_32(ByteSwapped[I]);
+Src = [0];
+SrcEnd = [ByteSwapped.size() - 1] + 1;
+  }
+
+  // Skip the BOM for conversion.
+  if (Src[0] == UNI_UTF32_BYTE_ORDER_MARK_NATIVE)
+Src++;
+
+  // Just allocate enough space up front.  We'll shrink it later.  Allocate
+  // enough that we can fit a null terminator without reallocating.
+  Out.resize(SrcBytes.size() * UNI_MAX_UTF8_BYTES_PER_CODE_POINT + 1);
+  UTF8 *Dst = reinterpret_cast([0]);
+  UTF8 *DstEnd = Dst + Out.size();
+
+  ConversionResult CR =
+  ConvertUTF32toUTF8(, SrcEnd, , DstEnd, strictConversion);
+  assert(CR != 

[PATCH] D98214: [clang-format] Fix aligning with linebreaks

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

In D98214#2901304 , @baramin wrote:

> This is true.
>  .clang-format:
>
>   Language:Cpp
>   AlignConsecutiveAssignments: Consecutive
>   BinPackArguments: false
>   BinPackParameters: false
>   ColumnLimit: 120
>   ConstructorInitializerIndentWidth: 4
>   ContinuationIndentWidth: 4
>   IndentWidth: 4
>   TabWidth:4
>   UseCRLF: false
>   UseTab:  Never
>
> Format, that looks like a regression for me:
> Now:
>
>   void SomeFunc() {
>   newWatcher.maxAgeUsec = ToLegacyTimestamp(GetMaxAge(
>   FromLegacyTimestamp(monitorFrequencyUsec), 
> seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));
>   newWatcher.maxAge = ToLegacyTimestamp(GetMaxAge(
>   FromLegacyTimestamp(monitorFrequencyUsec), 
> seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));
>   newWatcher.max= ToLegacyTimestamp(GetMaxAge(
>  FromLegacyTimestamp(monitorFrequencyUsec), 
> seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));
>   }
>
> Before:
>
>   void SomeFunc() {
>   newWatcher.maxAgeUsec = ToLegacyTimestamp(GetMaxAge(
>   FromLegacyTimestamp(monitorFrequencyUsec), 
> seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));
>   newWatcher.maxAge = ToLegacyTimestamp(GetMaxAge(
>   FromLegacyTimestamp(monitorFrequencyUsec), 
> seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));
>   newWatcher.max= ToLegacyTimestamp(GetMaxAge(
>   FromLegacyTimestamp(monitorFrequencyUsec), 
> seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));
>   }

The fix is in D106773 , please have a look at 
it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98214

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


[PATCH] D106773: [clang-format] Fix aligning with linebreaks #2

2021-07-25 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: MyDeveloperDay, curdeius, baramin.
HazardyKnusperkeks added a project: clang-format.
HazardyKnusperkeks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This amends c5243c63cda3c740d6e9c7e501f6518c21688da3 
 to fix 
formatting continued function calls with BinPacking = false.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106773

Files:
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16411,6 +16411,37 @@
"}",
Style);
   // clang-format on
+
+  Style = getLLVMStyleWithColumns(120);
+  Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive;
+  Style.ContinuationIndentWidth = 4;
+  Style.IndentWidth = 4;
+
+  // clang-format off
+  verifyFormat("void SomeFunc() {\n"
+   "newWatcher.maxAgeUsec = 
ToLegacyTimestamp(GetMaxAge(FromLegacyTimestamp(monitorFrequencyUsec),\n"
+   "
seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));\n"
+   "newWatcher.maxAge = 
ToLegacyTimestamp(GetMaxAge(FromLegacyTimestamp(monitorFrequencyUsec),\n"
+   "
seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));\n"
+   "newWatcher.max= 
ToLegacyTimestamp(GetMaxAge(FromLegacyTimestamp(monitorFrequencyUsec),\n"
+   "
seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));\n"
+   "}",
+   Style);
+  // clang-format on
+
+  Style.BinPackArguments = false;
+
+  // clang-format off
+  verifyFormat("void SomeFunc() {\n"
+   "newWatcher.maxAgeUsec = ToLegacyTimestamp(GetMaxAge(\n"
+   "
FromLegacyTimestamp(monitorFrequencyUsec), 
seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));\n"
+   "newWatcher.maxAge = ToLegacyTimestamp(GetMaxAge(\n"
+   "
FromLegacyTimestamp(monitorFrequencyUsec), 
seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));\n"
+   "newWatcher.max= ToLegacyTimestamp(GetMaxAge(\n"
+   "
FromLegacyTimestamp(monitorFrequencyUsec), 
seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));\n"
+   "}",
+   Style);
+  // clang-format on
 }
 
 TEST_F(FormatTest, AlignWithInitializerPeriods) {
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -347,7 +347,7 @@
 if (ScopeStart > Start + 1 &&
 Changes[ScopeStart - 2].Tok->is(tok::identifier) &&
 Changes[ScopeStart - 1].Tok->is(tok::l_paren))
-  return true;
+  return Style.BinPackArguments;
 
 // Ternary operator
 if (Changes[i].Tok->is(TT_ConditionalExpr))


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16411,6 +16411,37 @@
"}",
Style);
   // clang-format on
+
+  Style = getLLVMStyleWithColumns(120);
+  Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive;
+  Style.ContinuationIndentWidth = 4;
+  Style.IndentWidth = 4;
+
+  // clang-format off
+  verifyFormat("void SomeFunc() {\n"
+   "newWatcher.maxAgeUsec = ToLegacyTimestamp(GetMaxAge(FromLegacyTimestamp(monitorFrequencyUsec),\n"
+   "seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));\n"
+   "newWatcher.maxAge = ToLegacyTimestamp(GetMaxAge(FromLegacyTimestamp(monitorFrequencyUsec),\n"
+   "seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));\n"
+   "newWatcher.max= ToLegacyTimestamp(GetMaxAge(FromLegacyTimestamp(monitorFrequencyUsec),\n"
+   "seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));\n"
+   "}",
+   Style);
+  // clang-format on
+
+  Style.BinPackArguments = false;
+
+  // clang-format off
+  verifyFormat("void SomeFunc() {\n"
+   "newWatcher.maxAgeUsec = ToLegacyTimestamp(GetMaxAge(\n"
+   "FromLegacyTimestamp(monitorFrequencyUsec), 

[PATCH] D106753: ConvertUTF: Created wrapper convertUTF32ToUTF8String

2021-07-25 Thread Marcus Johnson via Phabricator via cfe-commits
MarcusJohnson91 marked 3 inline comments as done.
MarcusJohnson91 added inline comments.



Comment at: llvm/lib/Support/ConvertUTFWrapper.cpp:168
+  std::vector ByteSwapped;
+  if (Src[0] == UNI_UTF16_BYTE_ORDER_MARK_SWAPPED) {
+ByteSwapped.insert(ByteSwapped.end(), Src, SrcEnd);

efriedma wrote:
> Wrong constant.
> 
> Is this really the function you want to be using from clang?  I don't really 
> understand why you'd want to handle byte order marks.
I don't really care about the BOM tbh, I just figured if I was in here, I 
should flesh out the UTF-32 interface.


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

https://reviews.llvm.org/D106753

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


[PATCH] D105320: [CodeView] Saturate values bigger than supported by APInt.

2021-07-25 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 361527.
mizvekov marked an inline comment as done.
mizvekov added a comment.

- rebase on top of D106585 
- Reimplement test based on IR


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105320

Files:
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
  llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/test/DebugInfo/COFF/integer-128.ll

Index: llvm/test/DebugInfo/COFF/integer-128.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/COFF/integer-128.ll
@@ -0,0 +1,136 @@
+; RUN: llc < %s | FileCheck %s --check-prefix=ASM
+
+; // C++ source to regenerate:
+; enum class uns : __uint128_t { unsval = __uint128_t(1) << 64 };
+; uns t1() { return uns::unsval; }
+; enum class sig : __int128 { sigval = -(__int128(1) << 64) };
+; sig t2() { return sig::sigval; }
+; struct test {
+;   static const __uint128_t u128 = __uint128_t(1) << 64;
+;   static const __int128s128 = -(__int128(1) << 64);
+; };
+; test t3() { return test(); }
+; 
+; $ clang a.cpp -S -emit-llvm -g -gcodeview
+
+; --
+
+; ASM-LABEL: .long   241 # Symbol subsection for globals
+;
+; ASM-LABEL: .short	4359# Record kind: S_CONSTANT
+; ASM-NEXT:  .long	4110# Type
+; ASM-NEXT:  .byte	0x0a, 0x80, 0xff, 0xff  # Value
+; ASM-NEXT:  .byte	0xff, 0xff, 0xff, 0xff
+; ASM-NEXT:  .byte	0xff, 0xff
+; ASM-NEXT:  .asciz	"test::u128"# Name
+; ASM-NEXT:  .p2align	2
+;
+; ASM-LABEL: .short	4359# Record kind: S_CONSTANT
+; ASM-NEXT:  .long	4111# Type
+; ASM-NEXT:  .byte	0x09, 0x80, 0x00, 0x00  # Value
+; ASM-NEXT:  .byte	0x00, 0x00, 0x00, 0x00
+; ASM-NEXT:  .byte	0x00, 0x80
+; ASM-NEXT:  .asciz	"test::s128"# Name
+; ASM-NEXT:  .p2align	2
+;
+; ASM-LABEL: .short	0x1203  # Record kind: LF_FIELDLIST
+; ASM-NEXT:  .short	0x1502  # Member kind: Enumerator ( LF_ENUMERATE )
+; ASM-NEXT:  .short	0x3 # Attrs: Public
+; ASM-NEXT:  .short	0x800a
+; ASM-NEXT:  .quad	0x  # EnumValue
+; ASM-NEXT:  .asciz	"unsval"# Name
+;
+; ASM-LABEL: .short	0x1203  # Record kind: LF_FIELDLIST
+; ASM-NEXT:  .short	0x1502  # Member kind: Enumerator ( LF_ENUMERATE )
+; ASM-NEXT:  .short	0x3 # Attrs: Public
+; ASM-NEXT:  .short	0x800a
+; ASM-NEXT:  .quad	0x  # EnumValue
+; ASM-NEXT:  .asciz	"sigval"# Name
+
+; --
+
+; ModuleID = 'a.cpp'
+source_filename = "a.cpp"
+target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-windows-gnu"
+
+%struct.test = type { i8 }
+
+; Function Attrs: mustprogress noinline nounwind optnone
+define dso_local <2 x i64> @_Z2t1v() #0 !dbg !23 {
+entry:
+  %retval = alloca i128, align 16
+  store i128 18446744073709551616, i128* %retval, align 16, !dbg !27
+  %0 = bitcast i128* %retval to <2 x i64>*, !dbg !27
+  %1 = load <2 x i64>, <2 x i64>* %0, align 16, !dbg !27
+  ret <2 x i64> %1, !dbg !27
+}
+
+; Function Attrs: mustprogress noinline nounwind optnone
+define dso_local <2 x i64> @_Z2t2v() #0 !dbg !28 {
+entry:
+  %retval = alloca i128, align 16
+  store i128 -18446744073709551616, i128* %retval, align 16, !dbg !31
+  %0 = bitcast i128* %retval to <2 x i64>*, !dbg !31
+  %1 = load <2 x i64>, <2 x i64>* %0, align 16, !dbg !31
+  ret <2 x i64> %1, !dbg !31
+}
+
+; Function Attrs: mustprogress noinline nounwind optnone
+define dso_local i8 @_Z2t3v() #1 !dbg !32 {
+entry:
+  %retval = alloca %struct.test, align 1
+  %coerce.dive = getelementptr inbounds %struct.test, %struct.test* %retval, i32 0, i32 0, !dbg !41
+  %0 = load i8, i8* %coerce.dive, align 1, !dbg !41
+  ret i8 %0, !dbg !41
+}
+
+attributes #0 = { mustprogress noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="128" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
+attributes #1 = { mustprogress noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!19, !20, !21}
+!llvm.ident = !{!22}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: 

[PATCH] D91950: [clang-format] Add BreakBeforeInlineASMColon configuration

2021-07-25 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:3800
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeInlineASMColon = true;
   verifyFormat(

I already gave my go in the past, but now I have to wonder, why are you setting 
this to `true` here? Does this mean before your change clang-format did behave 
as if the option is `true`? If that's the case please set the default also to 
`true`. If the old behavior is neither `true` nor `false` we have to find 
something different.


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

https://reviews.llvm.org/D91950

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


[PATCH] D106753: ConvertUTF: Created wrapper convertUTF32ToUTF8String

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

Please fix clang-format issues.  (You can use the clang-format-diff.py script.)




Comment at: llvm/lib/Support/ConvertUTFWrapper.cpp:154
+  // Error out on an uneven byte count.
+  if (SrcBytes.size() % 2)
+return false;

Wrong constant.



Comment at: llvm/lib/Support/ConvertUTFWrapper.cpp:168
+  std::vector ByteSwapped;
+  if (Src[0] == UNI_UTF16_BYTE_ORDER_MARK_SWAPPED) {
+ByteSwapped.insert(ByteSwapped.end(), Src, SrcEnd);

Wrong constant.

Is this really the function you want to be using from clang?  I don't really 
understand why you'd want to handle byte order marks.



Comment at: llvm/lib/Support/ConvertUTFWrapper.cpp:203
+{
+  return convertUTF16ToUTF8String(
+  llvm::ArrayRef(reinterpret_cast(Src.data()),

Wrong function?


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

https://reviews.llvm.org/D106753

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


[PATCH] D106401: [CUDA, MemCpyOpt] Add a flag to force-enable memcpyopt and use it for CUDA.

2021-07-25 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

Would the variant of the original patch at D106769 
 be sufficient for your purposes? Or are you 
also interested in the optimizations that introduce new memset/memcpy?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106401

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


[PATCH] D106757: [PowerPC] Implement partial vector ld/st builtins for XL compatibility

2021-07-25 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added a comment.

In D106757#2902849 , @Conanap wrote:

> do we need an IR -> ASM test case as well?

I didn't add this as the builtins do not produce any new IR - there are no new 
intrinsics or any other modifications to the back end. Since the code is 
completely contained in the front end, I feel like the tests should be as well.




Comment at: clang/lib/Headers/altivec.h:3151
+#else
+#define __vec_ldrmb __builtin_vsx_ldrmb
+#define __vec_strmb __builtin_vsx_strmb

Conanap wrote:
> I believe the preference is to have this defined in 
> `clang/lib/Basic/Targets/PPC.cpp` under `defineXLCompatMacros`
That is a very good point. However for the Altivec builtins, there is long 
standing precedent for having these defined in the header. We actually don't 
want the vector builtins to be defined without the inclusion of `altivec.h`.



Comment at: clang/test/CodeGen/builtins-ppc-ld-st-rmb.c:1
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: powerpc-registered-target

The test case is quite verbose but the checks were produced by the script so it 
should be easy to maintain. The reason I added so many checks is that the 
produce code is very dependent on:
- endianness
- CPU
- the number of bytes (in the store case)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106757

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


[PATCH] D106349: [clang-format] respect AfterEnum for enums

2021-07-25 Thread Michael Zimmermann via Phabricator via cfe-commits
m1cha updated this revision to Diff 361493.
m1cha added a comment.

I've added a note to `ReleaseNotes.rst`


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

https://reviews.llvm.org/D106349

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2451,6 +2451,14 @@
   Style.AllowShortEnumsOnASingleLine = true;
   verifyFormat("enum { A, B, C } ShortEnum1, ShortEnum2;", Style);
   Style.AllowShortEnumsOnASingleLine = false;
+  verifyFormat("enum {\n"
+   "  A,\n"
+   "  B,\n"
+   "  C\n"
+   "} ShortEnum1, ShortEnum2;",
+   Style);
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterEnum = true;
   verifyFormat("enum\n"
"{\n"
"  A,\n"
@@ -22123,8 +22131,7 @@
Style);
   // Enumerations are not records and should be unaffected.
   Style.AllowShortEnumsOnASingleLine = false;
-  verifyFormat("enum class E\n"
-   "{\n"
+  verifyFormat("enum class E {\n"
"  A,\n"
"  B\n"
"};\n",
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -706,6 +706,8 @@
 return Style.BraceWrapping.AfterUnion;
   if (InitialToken.is(tok::kw_struct))
 return Style.BraceWrapping.AfterStruct;
+  if (InitialToken.is(tok::kw_enum))
+return Style.BraceWrapping.AfterEnum;
   return false;
 }
 
@@ -2511,6 +2513,8 @@
 }
 
 bool UnwrappedLineParser::parseEnum() {
+  const FormatToken  = *FormatTok;
+
   // Won't be 'enum' for NS_ENUMs.
   if (FormatTok->Tok.is(tok::kw_enum))
 nextToken();
@@ -2561,7 +2565,8 @@
 return true;
   }
 
-  if (!Style.AllowShortEnumsOnASingleLine)
+  if (!Style.AllowShortEnumsOnASingleLine &&
+  ShouldBreakBeforeBrace(Style, InitialToken))
 addUnwrappedLine();
   // Parse enum body.
   nextToken();
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -284,6 +284,9 @@
 
 - Support for formatting JSON file (\*.json) has been added to clang-format.
 
+- ``AllowShortEnumsOnASingleLine=false`` now respects 
``BraceWrapping.AfterEnum``
+  when formatting an enum.
+
 libclang
 
 


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2451,6 +2451,14 @@
   Style.AllowShortEnumsOnASingleLine = true;
   verifyFormat("enum { A, B, C } ShortEnum1, ShortEnum2;", Style);
   Style.AllowShortEnumsOnASingleLine = false;
+  verifyFormat("enum {\n"
+   "  A,\n"
+   "  B,\n"
+   "  C\n"
+   "} ShortEnum1, ShortEnum2;",
+   Style);
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterEnum = true;
   verifyFormat("enum\n"
"{\n"
"  A,\n"
@@ -22123,8 +22131,7 @@
Style);
   // Enumerations are not records and should be unaffected.
   Style.AllowShortEnumsOnASingleLine = false;
-  verifyFormat("enum class E\n"
-   "{\n"
+  verifyFormat("enum class E {\n"
"  A,\n"
"  B\n"
"};\n",
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -706,6 +706,8 @@
 return Style.BraceWrapping.AfterUnion;
   if (InitialToken.is(tok::kw_struct))
 return Style.BraceWrapping.AfterStruct;
+  if (InitialToken.is(tok::kw_enum))
+return Style.BraceWrapping.AfterEnum;
   return false;
 }
 
@@ -2511,6 +2513,8 @@
 }
 
 bool UnwrappedLineParser::parseEnum() {
+  const FormatToken  = *FormatTok;
+
   // Won't be 'enum' for NS_ENUMs.
   if (FormatTok->Tok.is(tok::kw_enum))
 nextToken();
@@ -2561,7 +2565,8 @@
 return true;
   }
 
-  if (!Style.AllowShortEnumsOnASingleLine)
+  if (!Style.AllowShortEnumsOnASingleLine &&
+  ShouldBreakBeforeBrace(Style, InitialToken))
 addUnwrappedLine();
   // Parse enum body.
   nextToken();
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -284,6 +284,9 @@
 
 - Support for formatting JSON file (\*.json) has been added to clang-format.
 
+- ``AllowShortEnumsOnASingleLine=false`` now respects ``BraceWrapping.AfterEnum``
+  when 

[PATCH] D106753: ConvertUTF: Created wrapper convertUTF32ToUTF8String

2021-07-25 Thread Marcus Johnson via Phabricator via cfe-commits
MarcusJohnson91 added a comment.

I don't understand why the build failed?

I've compiled it and ran all the tests with `time ninja check`


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

https://reviews.llvm.org/D106753

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