[PATCH] D116875: [clang-tidy] Add performance-inefficient-array-traversal check

2022-01-08 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/performance/InefficientArrayTraversalCheck.cpp:59
+ // TODO: Add support for x [+-]= 1 and x = x [+-] 1
+ hasIncrement(unaryOperator(hasUnaryOperand(ToDecl),
+hasAnyOperatorName("++", "--"))),

I think will be reasonable to check for `+=` and `-=`.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:117
+
+  Detects nested for loops used to traverse a 2D array where the row index is
+  iterated on the inner loop.

Please highlight `for` with double back-ticks. Same in documentation.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/performance-inefficient-array-traversal.rst:15
+
+
+This array access pattern results in nonsequential data access which is cache 

Excessive newline.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/performance-inefficient-array-traversal.rst:26
+   Array[Y][X]++;
+

Excessive newline.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116875

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


[PATCH] D116824: [clang-tidy] Fix RenamerClangTidyChecks suggesting invalid macro identifiers

2022-01-08 Thread Nathan James via Phabricator via cfe-commits
njames93 accepted this revision.
njames93 added a comment.
This revision is now accepted and ready to land.

LGTM, Thanks. Don't know how I missed this one last time round.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116824

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


[PATCH] D116875: [clang-tidy] Add performance-inefficient-array-traversal check

2022-01-08 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: alexfh, aaron.ballman.
Herald added subscribers: carlosgalvezp, kristof.beyls, xazax.hun, mgorny.
njames93 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Adds a check that detects 2D array traversals where the array is traversed 
column wise instead of row wise.
These patterns harm cache performance as well as prevent auto-vectorisation 
opportunities.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116875

Files:
  clang-tools-extra/clang-tidy/performance/CMakeLists.txt
  clang-tools-extra/clang-tidy/performance/InefficientArrayTraversalCheck.cpp
  clang-tools-extra/clang-tidy/performance/InefficientArrayTraversalCheck.h
  clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/performance-inefficient-array-traversal.rst
  
clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-array-traversal.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-array-traversal.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-array-traversal.cpp
@@ -0,0 +1,72 @@
+// RUN: %check_clang_tidy %s performance-inefficient-array-traversal %t
+
+constexpr unsigned Rows = 10U;
+constexpr unsigned Cols = 16U;
+
+int Arr[Rows][Cols];
+int *PtrArr[Cols];
+int **Ptr;
+
+void foo();
+
+void warned() {
+  for (unsigned I = 0; I < Cols; ++I) {
+for (unsigned J = 0; J < Rows; ++J) {
+  Arr[J][I]++;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: Nonsequential array traversal can harm performance
+  // CHECK-MESSAGES: :[[@LINE-3]]:5: note: Row index 'J' incremented in this loop
+  // CHECK-MESSAGES: :[[@LINE-5]]:3: note: Column index 'I' incremented in this loop
+}
+  }
+  for (unsigned I = 0; I < Cols; ++I)
+for (unsigned J = 0; J < Rows; ++J)
+  Arr[J][I]++;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: Nonsequential array traversal can harm performance
+
+  for (unsigned I = 0; I < Cols; ++I)
+for (unsigned J = 0; J < Rows; ++J)
+  PtrArr[J][I]++;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: Nonsequential array traversal can harm performance
+
+  for (unsigned I = 0; I < Cols; ++I)
+for (unsigned J = 0; J < Rows; ++J)
+  Ptr[J][I]++;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: Nonsequential array traversal can harm performance
+
+  // Still warn on this as calls inside the inner loop shouldn't complicate a fix.
+  for (unsigned I = 0; I < Cols; ++I) {
+for (unsigned J = 0; J < Rows; ++J) {
+  foo();
+  Arr[J][I]++;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: Nonsequential array traversal can harm performance
+  foo();
+}
+  }
+}
+
+void ignored() {
+  // Correct traversal.
+  for (unsigned I = 0; I < Rows; ++I) {
+for (unsigned J = 0; J < Cols; ++J) {
+  Arr[I][J]++;
+}
+  }
+  for (unsigned I = 0; I < Rows; ++I) {
+for (unsigned J = 0; J < Cols; ++J) {
+  PtrArr[I][J]++;
+}
+  }
+  // Don'w warn on these cases as extra code inside the outer loop could complicate a fix.
+  for (unsigned I = 0; I < Cols; ++I) {
+foo();
+for (unsigned J = 0; J < Rows; ++J) {
+  Arr[J][I]++;
+}
+  }
+  for (unsigned I = 0; I < Cols; ++I) {
+for (unsigned J = 0; J < Rows; ++J) {
+  Arr[J][I]++;
+}
+foo();
+  }
+}
Index: clang-tools-extra/docs/clang-tidy/checks/performance-inefficient-array-traversal.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/performance-inefficient-array-traversal.rst
@@ -0,0 +1,26 @@
+.. title:: clang-tidy - performance-inefficient-array-traversal
+
+performance-inefficient-array-traversal
+===
+
+Detects nested for loops used to traverse a 2D array where the row index is 
+iterated on the inner loop.
+
+.. code-block:: c++
+
+   for (int X = 0; X < Columns; ++X)
+ for (int Y = 0; Y < Rows; ++Y)
+   Array[Y][X]++;
+
+
+This array access pattern results in nonsequential data access which is cache 
+unfriendly and can prevent auto vectorization optimizations.
+
+A much faster version of the above loop would be
+
+.. code-block:: c++
+
+   for (int Y = 0; Y < Rows; ++Y)
+ for (int X = 0; X < Columns; ++X)
+   Array[Y][X]++;
+
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -273,6 +273,7 @@
`performance-for-range-copy `_, "Yes"
`performance-implicit-conversion-in-loop `_,
`performance-inefficient-algorithm `_, "Yes"
+   

LLVM build master will be restarted soon

2022-01-08 Thread Galina Kistanova via cfe-commits
 Hello,

LLVM build master will be restarted at 9 PM PST.

Thanks

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


[PATCH] D116865: [OpenMP][FIX] Emit debug declares only if debug info is available

2022-01-08 Thread Johannes Doerfert via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG37639b72a17b: [OpenMP][FIX] Emit debug declares only if 
debug info is available (authored by jdoerfert).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116865

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/debug_private.c
  clang/test/OpenMP/debug_task_shared.c


Index: clang/test/OpenMP/debug_task_shared.c
===
--- clang/test/OpenMP/debug_task_shared.c
+++ clang/test/OpenMP/debug_task_shared.c
@@ -5,6 +5,9 @@
 
 // RUN: %clang_cc1 -debug-info-kind=constructor -DSHARED -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=CHECK
 // RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=line-directives-only -DSHARED -x c -verify 
-triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=line-tables-only -DSHARED -x c -verify 
-triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=limited -DSHARED -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=CHECK
 // expected-no-diagnostics
 
 // CHECK-LABEL: define internal i32 @.omp_task_entry.
Index: clang/test/OpenMP/debug_private.c
===
--- clang/test/OpenMP/debug_private.c
+++ clang/test/OpenMP/debug_private.c
@@ -4,6 +4,9 @@
 // REQUIRES: x86_64-linux
 
 // RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=line-directives-only -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=line-tables-only -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=limited -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
 // expected-no-diagnostics
 
 // CHECK: define internal i32 @.omp_task_entry.
@@ -11,6 +14,7 @@
 // CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv.ptr.addr.i, 
metadata [[PRIV1:![0-9]+]], metadata !DIExpression(DW_OP_deref))
 // CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv.ptr.addr1.i, 
metadata [[PRIV2:![0-9]+]], metadata !DIExpression(DW_OP_deref))
 // CHECK:  call void @llvm.dbg.declare(metadata i32** %.firstpriv.ptr.addr.i, 
metadata [[FPRIV:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+// NEG-NOT: call void @llvm.dbg.declare
 
 // CHECK: [[PRIV1]] = !DILocalVariable(name: "priv1"
 // CHECK: [[PRIV2]] = !DILocalVariable(name: "priv2"
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -4460,8 +4460,9 @@
   CGF.getContext().getASTRecordLayout(CaptureRecord);
   unsigned Offset =
   Layout.getFieldOffset(It->second->getFieldIndex()) / CharWidth;
-  (void)DI->EmitDeclareOfAutoVariable(SharedVar, ContextValue,
-  CGF.Builder, false);
+  if (CGF.CGM.getCodeGenOpts().hasReducedDebugInfo())
+(void)DI->EmitDeclareOfAutoVariable(SharedVar, ContextValue,
+CGF.Builder, false);
   llvm::Instruction  = CGF.Builder.GetInsertBlock()->back();
   // Get the call dbg.declare instruction we just created and update
   // its DIExpression to add offset to base address.
@@ -4560,8 +4561,10 @@
 CGF.getContext().getDeclAlign(Pair.first));
 Scope.addPrivate(Pair.first, [Replacement]() { return Replacement; });
 if (auto *DI = CGF.getDebugInfo())
-  DI->EmitDeclareOfAutoVariable(Pair.first, Pair.second.getPointer(),
-CGF.Builder, /*UsePointerValue*/ true);
+  if (CGF.CGM.getCodeGenOpts().hasReducedDebugInfo())
+(void)DI->EmitDeclareOfAutoVariable(
+Pair.first, Pair.second.getPointer(), CGF.Builder,
+/*UsePointerValue*/ true);
   }
   // Adjust mapping for internal locals by mapping actual memory instead of
   // a pointer to this memory.


Index: clang/test/OpenMP/debug_task_shared.c
===
--- clang/test/OpenMP/debug_task_shared.c
+++ clang/test/OpenMP/debug_task_shared.c
@@ -5,6 +5,9 @@
 
 // RUN: %clang_cc1 

[clang] 37639b7 - [OpenMP][FIX] Emit debug declares only if debug info is available

2022-01-08 Thread Johannes Doerfert via cfe-commits

Author: Johannes Doerfert
Date: 2022-01-08T17:01:19-06:00
New Revision: 37639b72a17be443e7f73e906554f8bbd0dbf271

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

LOG: [OpenMP][FIX] Emit debug declares only if debug info is available

The `EmitDeclareOfAutoVariable` introduced in D114504 and D115510 has a
precondition that cannot be violated. It is unclear if we should call it
directly given the sparse usage in clang but for now we should at least
not crash if the debug info kind is too low.

Fixes #52938.

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

Added: 


Modified: 
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/test/OpenMP/debug_private.c
clang/test/OpenMP/debug_task_shared.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 94472668c8e70..b340e0505a788 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -4460,8 +4460,9 @@ void CodeGenFunction::EmitOMPTaskBasedDirective(
   CGF.getContext().getASTRecordLayout(CaptureRecord);
   unsigned Offset =
   Layout.getFieldOffset(It->second->getFieldIndex()) / CharWidth;
-  (void)DI->EmitDeclareOfAutoVariable(SharedVar, ContextValue,
-  CGF.Builder, false);
+  if (CGF.CGM.getCodeGenOpts().hasReducedDebugInfo())
+(void)DI->EmitDeclareOfAutoVariable(SharedVar, ContextValue,
+CGF.Builder, false);
   llvm::Instruction  = CGF.Builder.GetInsertBlock()->back();
   // Get the call dbg.declare instruction we just created and update
   // its DIExpression to add offset to base address.
@@ -4560,8 +4561,10 @@ void CodeGenFunction::EmitOMPTaskBasedDirective(
 CGF.getContext().getDeclAlign(Pair.first));
 Scope.addPrivate(Pair.first, [Replacement]() { return Replacement; });
 if (auto *DI = CGF.getDebugInfo())
-  DI->EmitDeclareOfAutoVariable(Pair.first, Pair.second.getPointer(),
-CGF.Builder, /*UsePointerValue*/ true);
+  if (CGF.CGM.getCodeGenOpts().hasReducedDebugInfo())
+(void)DI->EmitDeclareOfAutoVariable(
+Pair.first, Pair.second.getPointer(), CGF.Builder,
+/*UsePointerValue*/ true);
   }
   // Adjust mapping for internal locals by mapping actual memory instead of
   // a pointer to this memory.

diff  --git a/clang/test/OpenMP/debug_private.c 
b/clang/test/OpenMP/debug_private.c
index a68e1d1be7526..f25b45855b112 100644
--- a/clang/test/OpenMP/debug_private.c
+++ b/clang/test/OpenMP/debug_private.c
@@ -4,6 +4,9 @@
 // REQUIRES: x86_64-linux
 
 // RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=line-directives-only -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=line-tables-only -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=limited -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
 // expected-no-diagnostics
 
 // CHECK: define internal i32 @.omp_task_entry.
@@ -11,6 +14,7 @@
 // CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv.ptr.addr.i, 
metadata [[PRIV1:![0-9]+]], metadata !DIExpression(DW_OP_deref))
 // CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv.ptr.addr1.i, 
metadata [[PRIV2:![0-9]+]], metadata !DIExpression(DW_OP_deref))
 // CHECK:  call void @llvm.dbg.declare(metadata i32** %.firstpriv.ptr.addr.i, 
metadata [[FPRIV:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+// NEG-NOT: call void @llvm.dbg.declare
 
 // CHECK: [[PRIV1]] = !DILocalVariable(name: "priv1"
 // CHECK: [[PRIV2]] = !DILocalVariable(name: "priv2"

diff  --git a/clang/test/OpenMP/debug_task_shared.c 
b/clang/test/OpenMP/debug_task_shared.c
index c3a23bc486324..941d31eead3c9 100644
--- a/clang/test/OpenMP/debug_task_shared.c
+++ b/clang/test/OpenMP/debug_task_shared.c
@@ -5,6 +5,9 @@
 
 // RUN: %clang_cc1 -debug-info-kind=constructor -DSHARED -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=CHECK
 // RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=line-directives-only -DSHARED -x c -verify 
-triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=NEG
+// 

[PATCH] D116865: [OpenMP][FIX] Emit debug declares only if debug info is available

2022-01-08 Thread Ye Luo via Phabricator via cfe-commits
ye-luo added a comment.

Confirm that #52938 is fixed by this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116865

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


[PATCH] D113359: [Libomptarget][WIP] Introduce VGPU Plugin

2022-01-08 Thread Atmn Patel via Phabricator via cfe-commits
atmnpatel updated this revision to Diff 398370.
atmnpatel added a comment.

- Fixed lifetime issue around ffi_call
- Addressed comments

The existing x86 plugin uses ffi, so this does as well, no explicit benefit in 
doing so. Is it worth keeping?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113359

Files:
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/ADT/Triple.h
  llvm/include/llvm/Frontend/OpenMP/OMPGridValues.h
  llvm/lib/Support/Triple.cpp
  openmp/CMakeLists.txt
  openmp/libomptarget/DeviceRTL/CMakeLists.txt
  openmp/libomptarget/DeviceRTL/include/ThreadEnvironment.h
  openmp/libomptarget/DeviceRTL/src/Debug.cpp
  openmp/libomptarget/DeviceRTL/src/Kernel.cpp
  openmp/libomptarget/DeviceRTL/src/Mapping.cpp
  openmp/libomptarget/DeviceRTL/src/Misc.cpp
  openmp/libomptarget/DeviceRTL/src/Synchronization.cpp
  openmp/libomptarget/DeviceRTL/src/Utils.cpp
  openmp/libomptarget/plugins/CMakeLists.txt
  openmp/libomptarget/plugins/vgpu/CMakeLists.txt
  openmp/libomptarget/plugins/vgpu/src/ThreadEnvironment.cpp
  openmp/libomptarget/plugins/vgpu/src/ThreadEnvironment.h
  openmp/libomptarget/plugins/vgpu/src/ThreadEnvironmentImpl.h
  openmp/libomptarget/plugins/vgpu/src/rtl.cpp
  openmp/libomptarget/src/rtl.cpp
  openmp/libomptarget/test/lit.cfg

Index: openmp/libomptarget/test/lit.cfg
===
--- openmp/libomptarget/test/lit.cfg
+++ openmp/libomptarget/test/lit.cfg
@@ -114,9 +114,11 @@
 
 # Scan all the valid targets.
 for libomptarget_target in config.libomptarget_all_targets:
+print("Checking {}".format(libomptarget_target))
 # Is this target in the current system? If so create a compile, run and test
 # command. Otherwise create command that return false.
 if libomptarget_target == config.libomptarget_current_target:
+print("First")
 config.substitutions.append(("%libomptarget-compilexx-run-and-check-generic", 
 "%libomptarget-compilexx-run-and-check-" + libomptarget_target))
 config.substitutions.append(("%libomptarget-compile-run-and-check-generic",
@@ -176,6 +178,7 @@
 config.substitutions.append(("%fcheck-" + libomptarget_target, \
 config.libomptarget_filecheck + " %s"))
 else:
+print("Second")
 config.substitutions.append(("%libomptarget-compile-run-and-check-" + \
 libomptarget_target, \
 "echo ignored-command"))
Index: openmp/libomptarget/src/rtl.cpp
===
--- openmp/libomptarget/src/rtl.cpp
+++ openmp/libomptarget/src/rtl.cpp
@@ -24,12 +24,13 @@
 // List of all plugins that can support offloading.
 static const char *RTLNames[] = {
 /* PowerPC target   */ "libomptarget.rtl.ppc64.so",
-/* x86_64 target*/ "libomptarget.rtl.x86_64.so",
+/* x86_64 target "libomptarget.rtl.x86_64.so", */
 /* CUDA target  */ "libomptarget.rtl.cuda.so",
 /* AArch64 target   */ "libomptarget.rtl.aarch64.so",
 /* SX-Aurora VE target  */ "libomptarget.rtl.ve.so",
 /* AMDGPU target*/ "libomptarget.rtl.amdgpu.so",
 /* Remote target*/ "libomptarget.rtl.rpc.so",
+/* Virtual GPU target   */ "libomptarget.rtl.vgpu.so",
 };
 
 PluginManager *PM;
@@ -79,7 +80,13 @@
   // is correct and if they are supporting any devices.
   for (auto *Name : RTLNames) {
 DP("Loading library '%s'...\n", Name);
-void *dynlib_handle = dlopen(Name, RTLD_NOW);
+
+int Flags = RTLD_NOW;
+
+if (strcmp(Name, "libomptarget.rtl.vgpu.so") == 0)
+  Flags |= RTLD_GLOBAL;
+
+void *dynlib_handle = dlopen(Name, Flags);
 
 if (!dynlib_handle) {
   // Library does not exist or cannot be found.
Index: openmp/libomptarget/plugins/vgpu/src/rtl.cpp
===
--- /dev/null
+++ openmp/libomptarget/plugins/vgpu/src/rtl.cpp
@@ -0,0 +1,609 @@
+//===--RTLs/vgpu/src/rtl.cpp - Target RTLs Implementation - C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// RTL for virtual (x86) GPU
+//
+//===--===//
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "Debug.h"
+#include "ThreadEnvironment.h"

[PATCH] D116861: [UBSan] Fix incorrect alignment reported when global new returns an offset pointer

2022-01-08 Thread Lambert Clara via Phabricator via cfe-commits
belkiss updated this revision to Diff 398369.
belkiss added a comment.

Use static_cast/reinterpret_cast instead of C-casts
This will also retry the CI, apparently fuzzer-finalstats.test is flaky


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116861

Files:
  clang/lib/CodeGen/CGExprCXX.cpp
  compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp


Index: compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp
===
--- /dev/null
+++ compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp
@@ -0,0 +1,35 @@
+// RUN: %clangxx -fsanitize=alignment %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not="runtime error" 
-allow-empty
+// Disable with msan and tsan because they also override global new
+// UNSUPPORTED: ubsan-msan, ubsan-tsan
+
+#include 
+#include 
+#include 
+
+void *operator new(std::size_t count) {
+  constexpr const size_t offset = 8;
+
+  // allocate a bit more so we can safely offset it
+  void *ptr = std::malloc(count + offset);
+
+  // verify malloc returned 16 bytes aligned mem
+  static_assert(__STDCPP_DEFAULT_NEW_ALIGNMENT__ == 16,
+"Global new doesn't return 16 bytes aligned memory!");
+  assert((reinterpret_cast(ptr) &
+  (__STDCPP_DEFAULT_NEW_ALIGNMENT__ - 1)) == 0);
+
+  return static_cast(ptr) + offset;
+}
+
+struct Param {
+  void *_cookie1;
+  void *_cookie2;
+};
+
+static_assert(alignof(Param) == 8, "Param struct alignment must be 8 bytes!");
+
+int main() {
+  // CHECK-NOT: runtime error: constructor call on misaligned address 
[[PTR:0x[0-9a-f]*]] for type 'Param', which requires 16 byte alignment
+  Param *p = new Param;
+}
Index: clang/lib/CodeGen/CGExprCXX.cpp
===
--- clang/lib/CodeGen/CGExprCXX.cpp
+++ clang/lib/CodeGen/CGExprCXX.cpp
@@ -1731,8 +1731,8 @@
   SkippedChecks.set(SanitizerKind::Null, nullCheck);
   EmitTypeCheck(CodeGenFunction::TCK_ConstructorCall,
 E->getAllocatedTypeSourceInfo()->getTypeLoc().getBeginLoc(),
-result.getPointer(), allocType, result.getAlignment(),
-SkippedChecks, numElements);
+result.getPointer(), allocType, allocAlign, SkippedChecks,
+numElements);
 
   EmitNewInitializer(*this, E, allocType, elementTy, result, numElements,
  allocSizeWithoutCookie);


Index: compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp
===
--- /dev/null
+++ compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp
@@ -0,0 +1,35 @@
+// RUN: %clangxx -fsanitize=alignment %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not="runtime error" -allow-empty
+// Disable with msan and tsan because they also override global new
+// UNSUPPORTED: ubsan-msan, ubsan-tsan
+
+#include 
+#include 
+#include 
+
+void *operator new(std::size_t count) {
+  constexpr const size_t offset = 8;
+
+  // allocate a bit more so we can safely offset it
+  void *ptr = std::malloc(count + offset);
+
+  // verify malloc returned 16 bytes aligned mem
+  static_assert(__STDCPP_DEFAULT_NEW_ALIGNMENT__ == 16,
+"Global new doesn't return 16 bytes aligned memory!");
+  assert((reinterpret_cast(ptr) &
+  (__STDCPP_DEFAULT_NEW_ALIGNMENT__ - 1)) == 0);
+
+  return static_cast(ptr) + offset;
+}
+
+struct Param {
+  void *_cookie1;
+  void *_cookie2;
+};
+
+static_assert(alignof(Param) == 8, "Param struct alignment must be 8 bytes!");
+
+int main() {
+  // CHECK-NOT: runtime error: constructor call on misaligned address [[PTR:0x[0-9a-f]*]] for type 'Param', which requires 16 byte alignment
+  Param *p = new Param;
+}
Index: clang/lib/CodeGen/CGExprCXX.cpp
===
--- clang/lib/CodeGen/CGExprCXX.cpp
+++ clang/lib/CodeGen/CGExprCXX.cpp
@@ -1731,8 +1731,8 @@
   SkippedChecks.set(SanitizerKind::Null, nullCheck);
   EmitTypeCheck(CodeGenFunction::TCK_ConstructorCall,
 E->getAllocatedTypeSourceInfo()->getTypeLoc().getBeginLoc(),
-result.getPointer(), allocType, result.getAlignment(),
-SkippedChecks, numElements);
+result.getPointer(), allocType, allocAlign, SkippedChecks,
+numElements);
 
   EmitNewInitializer(*this, E, allocType, elementTy, result, numElements,
  allocSizeWithoutCookie);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99484: Use `GNUInstallDirs` to support custom installation dirs.

2022-01-08 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 updated this revision to Diff 398366.
Ericson2314 added a comment.

Make sure possibly exposed modules have their own `include(GNUInstallDirs)`s


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99484

Files:
  clang-tools-extra/clang-doc/tool/CMakeLists.txt
  clang-tools-extra/clang-include-fixer/find-all-symbols/tool/CMakeLists.txt
  clang-tools-extra/clang-include-fixer/tool/CMakeLists.txt
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/tool/CMakeLists.txt
  clang-tools-extra/modularize/CMakeLists.txt
  clang/CMakeLists.txt
  clang/cmake/modules/AddClang.cmake
  clang/tools/c-index-test/CMakeLists.txt
  clang/tools/clang-format/CMakeLists.txt
  clang/tools/clang-nvlink-wrapper/CMakeLists.txt
  clang/tools/clang-rename/CMakeLists.txt
  clang/tools/libclang/CMakeLists.txt
  clang/tools/scan-build-py/CMakeLists.txt
  clang/tools/scan-build/CMakeLists.txt
  clang/tools/scan-view/CMakeLists.txt
  clang/utils/hmaptool/CMakeLists.txt
  compiler-rt/cmake/base-config-ix.cmake
  libc/CMakeLists.txt
  libcxx/CMakeLists.txt
  libcxx/cmake/Modules/HandleLibCXXABI.cmake
  libcxxabi/CMakeLists.txt
  libunwind/CMakeLists.txt
  llvm/cmake/modules/LLVMInstallSymlink.cmake
  mlir/CMakeLists.txt
  mlir/cmake/modules/AddMLIR.cmake
  openmp/CMakeLists.txt
  openmp/libompd/src/CMakeLists.txt
  openmp/runtime/src/CMakeLists.txt
  openmp/tools/multiplex/CMakeLists.txt
  polly/CMakeLists.txt
  polly/cmake/CMakeLists.txt
  polly/lib/External/CMakeLists.txt
  pstl/CMakeLists.txt

Index: pstl/CMakeLists.txt
===
--- pstl/CMakeLists.txt
+++ pstl/CMakeLists.txt
@@ -7,6 +7,8 @@
 #===--===##
 cmake_minimum_required(VERSION 3.13.4)
 
+include(GNUInstallDirs)
+
 set(PARALLELSTL_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/include/pstl/internal/pstl_config.h")
 file(STRINGS "${PARALLELSTL_VERSION_FILE}" PARALLELSTL_VERSION_SOURCE REGEX "#define _PSTL_VERSION .*$")
 string(REGEX REPLACE "#define _PSTL_VERSION (.*)$" "\\1" PARALLELSTL_VERSION_SOURCE "${PARALLELSTL_VERSION_SOURCE}")
@@ -90,10 +92,10 @@
   "${CMAKE_CURRENT_BINARY_DIR}/ParallelSTLConfigVersion.cmake"
 DESTINATION lib/cmake/ParallelSTL)
 install(DIRECTORY include/
-DESTINATION include
+DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
 PATTERN "*.in" EXCLUDE)
 install(FILES "${PSTL_CONFIG_SITE_PATH}"
-DESTINATION include)
+DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
 
 add_custom_target(install-pstl
   COMMAND "${CMAKE_COMMAND}" -P "${PROJECT_BINARY_DIR}/cmake_install.cmake" -DCOMPONENT=ParallelSTL)
Index: polly/lib/External/CMakeLists.txt
===
--- polly/lib/External/CMakeLists.txt
+++ polly/lib/External/CMakeLists.txt
@@ -290,7 +290,7 @@
 install(DIRECTORY
   ${ISL_SOURCE_DIR}/include/
   ${ISL_BINARY_DIR}/include/
-  DESTINATION include/polly
+  DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/polly"
   FILES_MATCHING
   PATTERN "*.h"
   PATTERN "CMakeFiles" EXCLUDE
Index: polly/cmake/CMakeLists.txt
===
--- polly/cmake/CMakeLists.txt
+++ polly/cmake/CMakeLists.txt
@@ -1,5 +1,6 @@
 # Keep this in sync with llvm/cmake/CMakeLists.txt!
 
+include(ExtendPath)
 include(FindPrefixFromConfig)
 
 set(LLVM_INSTALL_PACKAGE_DIR "lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
@@ -83,17 +84,18 @@
 # Generate PollyConfig.cmake for the install tree.
 unset(POLLY_EXPORTS)
 find_prefix_from_config(POLLY_CONFIG_CODE POLLY_INSTALL_PREFIX "${POLLY_INSTALL_PACKAGE_DIR}")
-set(POLLY_CONFIG_LLVM_CMAKE_DIR "\${POLLY_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}")
-set(POLLY_CONFIG_CMAKE_DIR "\${POLLY_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}")
-set(POLLY_CONFIG_LIBRARY_DIRS "\${POLLY_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}")
+extend_path(POLLY_CONFIG_LLVM_CMAKE_DIR "\${POLLY_INSTALL_PREFIX}" "${LLVM_INSTALL_PACKAGE_DIR}")
+extend_path(POLLY_CONFIG_CMAKE_DIR "\${POLLY_INSTALL_PREFIX}" "${POLLY_INSTALL_PACKAGE_DIR}")
+extend_path(POLLY_CONFIG_LIBRARY_DIRS "\${POLLY_INSTALL_PREFIX}" "lib${LLVM_LIBDIR_SUFFIX}")
+extend_path(base_includedir "\${POLLY_INSTALL_PREFIX}" "${CMAKE_INSTALL_INCLUDEDIR}")
 if (POLLY_BUNDLED_ISL)
   set(POLLY_CONFIG_INCLUDE_DIRS
-"\${POLLY_INSTALL_PREFIX}/include"
-"\${POLLY_INSTALL_PREFIX}/include/polly"
+"${base_includedir}"
+"${base_includedir}/polly"
 )
 else()
   set(POLLY_CONFIG_INCLUDE_DIRS
-"\${POLLY_INSTALL_PREFIX}/include"
+"${base_includedir}"
 ${ISL_INCLUDE_DIRS}
 )
 endif()
@@ -110,12 +112,12 @@
 foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS)
   get_target_property(tgt_type ${tgt} TYPE)
   if (tgt_type STREQUAL "EXECUTABLE")
-set(tgt_prefix "bin/")
+set(tgt_prefix 

[PATCH] D116856: [docs] Fix documentation of -fno-strict-float-cast-overflow after D115804.

2022-01-08 Thread Craig Topper 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 rGdb4cb4668b04: [docs] Fix documentation of 
-fno-strict-float-cast-overflow after D115804. (authored by craig.topper).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116856

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


Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -1380,8 +1380,8 @@
When a floating-point value is not representable in a destination integer
type, the code has undefined behavior according to the language standard.
By default, Clang will not guarantee any particular result in that case.
-   With the 'no-strict' option, Clang attempts to match the overflowing 
behavior
-   of the target's native float-to-int conversion instructions.
+   With the 'no-strict' option, Clang will saturate towards the smallest and
+   largest representable integer values instead. NaNs will be converted to 
zero.
 
 .. _opt_fmath-errno:
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -243,6 +243,9 @@
   -ffp-contract=fast, whereas the (now corrected) default behavior is
   -ffp-contract=on.
   -ffp-model=precise is now exactly the default mode of the compiler.
+- -fstrict-float-cast-overflow no longer has target specific behavior. Clang
+  will saturate towards the smallest and largest representable integer values.
+  NaNs will be converted to zero.
 
 Internal API Changes
 


Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -1380,8 +1380,8 @@
When a floating-point value is not representable in a destination integer
type, the code has undefined behavior according to the language standard.
By default, Clang will not guarantee any particular result in that case.
-   With the 'no-strict' option, Clang attempts to match the overflowing behavior
-   of the target's native float-to-int conversion instructions.
+   With the 'no-strict' option, Clang will saturate towards the smallest and
+   largest representable integer values instead. NaNs will be converted to zero.
 
 .. _opt_fmath-errno:
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -243,6 +243,9 @@
   -ffp-contract=fast, whereas the (now corrected) default behavior is
   -ffp-contract=on.
   -ffp-model=precise is now exactly the default mode of the compiler.
+- -fstrict-float-cast-overflow no longer has target specific behavior. Clang
+  will saturate towards the smallest and largest representable integer values.
+  NaNs will be converted to zero.
 
 Internal API Changes
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] db4cb46 - [docs] Fix documentation of -fno-strict-float-cast-overflow after D115804.

2022-01-08 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2022-01-08T12:12:44-08:00
New Revision: db4cb4668b046ae988914ae49105ff3cc0bc9d92

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

LOG: [docs] Fix documentation of -fno-strict-float-cast-overflow after D115804.

Previously this was documented as having the behavior of the
"target's native float-to-int conversion". After D115804, clang
uses saturating FP cast intrinsics which have the same behavior
on all targets.

Reviewed By: nikic

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7e24d06567fc3..d7c78c73ceb03 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -243,6 +243,9 @@ Floating Point Support in Clang
   -ffp-contract=fast, whereas the (now corrected) default behavior is
   -ffp-contract=on.
   -ffp-model=precise is now exactly the default mode of the compiler.
+- -fstrict-float-cast-overflow no longer has target specific behavior. Clang
+  will saturate towards the smallest and largest representable integer values.
+  NaNs will be converted to zero.
 
 Internal API Changes
 

diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index d83b7a27bb3bd..5f46322f19af2 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1380,8 +1380,8 @@ floating point semantic models: precise (the default), 
strict, and fast.
When a floating-point value is not representable in a destination integer
type, the code has undefined behavior according to the language standard.
By default, Clang will not guarantee any particular result in that case.
-   With the 'no-strict' option, Clang attempts to match the overflowing 
behavior
-   of the target's native float-to-int conversion instructions.
+   With the 'no-strict' option, Clang will saturate towards the smallest and
+   largest representable integer values instead. NaNs will be converted to 
zero.
 
 .. _opt_fmath-errno:
 



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


[PATCH] D116865: [OpenMP][FIX] Emit debug declares only if debug info is available

2022-01-08 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert updated this revision to Diff 398358.
jdoerfert added a comment.

Clang format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116865

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/debug_private.c
  clang/test/OpenMP/debug_task_shared.c


Index: clang/test/OpenMP/debug_task_shared.c
===
--- clang/test/OpenMP/debug_task_shared.c
+++ clang/test/OpenMP/debug_task_shared.c
@@ -5,6 +5,9 @@
 
 // RUN: %clang_cc1 -debug-info-kind=constructor -DSHARED -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=CHECK
 // RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=line-directives-only -DSHARED -x c -verify 
-triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=line-tables-only -DSHARED -x c -verify 
-triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=limited -DSHARED -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=CHECK
 // expected-no-diagnostics
 
 // CHECK-LABEL: define internal i32 @.omp_task_entry.
Index: clang/test/OpenMP/debug_private.c
===
--- clang/test/OpenMP/debug_private.c
+++ clang/test/OpenMP/debug_private.c
@@ -4,6 +4,9 @@
 // REQUIRES: x86_64-linux
 
 // RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=line-directives-only -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=line-tables-only -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=limited -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
 // expected-no-diagnostics
 
 // CHECK: define internal i32 @.omp_task_entry.
@@ -11,6 +14,7 @@
 // CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv.ptr.addr.i, 
metadata [[PRIV1:![0-9]+]], metadata !DIExpression(DW_OP_deref))
 // CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv.ptr.addr1.i, 
metadata [[PRIV2:![0-9]+]], metadata !DIExpression(DW_OP_deref))
 // CHECK:  call void @llvm.dbg.declare(metadata i32** %.firstpriv.ptr.addr.i, 
metadata [[FPRIV:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+// NEG-NOT: call void @llvm.dbg.declare
 
 // CHECK: [[PRIV1]] = !DILocalVariable(name: "priv1"
 // CHECK: [[PRIV2]] = !DILocalVariable(name: "priv2"
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -4460,8 +4460,9 @@
   CGF.getContext().getASTRecordLayout(CaptureRecord);
   unsigned Offset =
   Layout.getFieldOffset(It->second->getFieldIndex()) / CharWidth;
-  (void)DI->EmitDeclareOfAutoVariable(SharedVar, ContextValue,
-  CGF.Builder, false);
+  if (CGF.CGM.getCodeGenOpts().hasReducedDebugInfo())
+(void)DI->EmitDeclareOfAutoVariable(SharedVar, ContextValue,
+CGF.Builder, false);
   llvm::Instruction  = CGF.Builder.GetInsertBlock()->back();
   // Get the call dbg.declare instruction we just created and update
   // its DIExpression to add offset to base address.
@@ -4560,8 +4561,10 @@
 CGF.getContext().getDeclAlign(Pair.first));
 Scope.addPrivate(Pair.first, [Replacement]() { return Replacement; });
 if (auto *DI = CGF.getDebugInfo())
-  DI->EmitDeclareOfAutoVariable(Pair.first, Pair.second.getPointer(),
-CGF.Builder, /*UsePointerValue*/ true);
+  if (CGF.CGM.getCodeGenOpts().hasReducedDebugInfo())
+(void)DI->EmitDeclareOfAutoVariable(
+Pair.first, Pair.second.getPointer(), CGF.Builder,
+/*UsePointerValue*/ true);
   }
   // Adjust mapping for internal locals by mapping actual memory instead of
   // a pointer to this memory.


Index: clang/test/OpenMP/debug_task_shared.c
===
--- clang/test/OpenMP/debug_task_shared.c
+++ clang/test/OpenMP/debug_task_shared.c
@@ -5,6 +5,9 @@
 
 // RUN: %clang_cc1 -debug-info-kind=constructor -DSHARED -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 

[clang] d1b127b - [clang] Remove unused forward declarations (NFC)

2022-01-08 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-01-08T11:56:40-08:00
New Revision: d1b127b5b747a1c10409825c400da9bbfac70f2d

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

LOG: [clang] Remove unused forward declarations (NFC)

Added: 


Modified: 
clang/lib/AST/CXXABI.h
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/lib/AST/Interp/ByteCodeStmtGen.h
clang/lib/AST/Interp/Context.h
clang/lib/AST/Interp/InterpBlock.h
clang/lib/AST/Interp/Pointer.h
clang/lib/AST/Interp/Program.h
clang/lib/CodeGen/CGBlocks.h
clang/lib/CodeGen/CGCXXABI.h
clang/lib/CodeGen/CGCall.h
clang/lib/CodeGen/CGCleanup.h
clang/lib/CodeGen/CGDebugInfo.h
clang/lib/CodeGen/CGOpenMPRuntime.h
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/CodeGen/CodeGenModule.h
clang/lib/CodeGen/CodeGenTBAA.h
clang/lib/CodeGen/CodeGenTypes.h
clang/lib/CodeGen/MacroPPCallbacks.h
clang/lib/CodeGen/TargetInfo.h
clang/lib/Format/TokenAnnotator.h
clang/lib/Interpreter/IncrementalParser.h
clang/lib/Serialization/ASTReaderInternals.h
clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
clang/lib/StaticAnalyzer/Frontend/ModelInjector.h

Removed: 




diff  --git a/clang/lib/AST/CXXABI.h b/clang/lib/AST/CXXABI.h
index ca9424bcb7a49..9258a53fefebc 100644
--- a/clang/lib/AST/CXXABI.h
+++ b/clang/lib/AST/CXXABI.h
@@ -21,7 +21,6 @@ namespace clang {
 class ASTContext;
 class CXXConstructorDecl;
 class DeclaratorDecl;
-class Expr;
 class MangleContext;
 class MangleNumberingContext;
 class MemberPointerType;

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 716f28551e58e..124a6ff03f186 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -28,8 +28,6 @@ namespace clang {
 class QualType;
 
 namespace interp {
-class Function;
-class State;
 
 template  class LocalScope;
 template  class RecordScope;

diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.h 
b/clang/lib/AST/Interp/ByteCodeStmtGen.h
index d9c0b64ed4b82..3bc665b84b4d0 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -25,11 +25,7 @@
 #include "llvm/ADT/Optional.h"
 
 namespace clang {
-class QualType;
-
 namespace interp {
-class Function;
-class State;
 
 template  class LoopScope;
 template  class SwitchScope;

diff  --git a/clang/lib/AST/Interp/Context.h b/clang/lib/AST/Interp/Context.h
index 4f25ff977b81d..0627d9fb14f5d 100644
--- a/clang/lib/AST/Interp/Context.h
+++ b/clang/lib/AST/Interp/Context.h
@@ -23,7 +23,6 @@
 namespace clang {
 class ASTContext;
 class LangOptions;
-class Stmt;
 class FunctionDecl;
 class VarDecl;
 

diff  --git a/clang/lib/AST/Interp/InterpBlock.h 
b/clang/lib/AST/Interp/InterpBlock.h
index 0ccdef221c836..2d5386e60b8ca 100644
--- a/clang/lib/AST/Interp/InterpBlock.h
+++ b/clang/lib/AST/Interp/InterpBlock.h
@@ -25,10 +25,8 @@ namespace clang {
 namespace interp {
 class Block;
 class DeadBlock;
-class Context;
 class InterpState;
 class Pointer;
-class Function;
 enum PrimType : unsigned;
 
 /// A memory block, either on the stack or in the heap.

diff  --git a/clang/lib/AST/Interp/Pointer.h b/clang/lib/AST/Interp/Pointer.h
index f2f6e0e760185..587531aec82a0 100644
--- a/clang/lib/AST/Interp/Pointer.h
+++ b/clang/lib/AST/Interp/Pointer.h
@@ -26,10 +26,7 @@ namespace clang {
 namespace interp {
 class Block;
 class DeadBlock;
-class Context;
-class InterpState;
 class Pointer;
-class Function;
 enum PrimType : unsigned;
 
 /// A pointer to a memory block, live or dead.

diff  --git a/clang/lib/AST/Interp/Program.h b/clang/lib/AST/Interp/Program.h
index c81ec777a5fe7..ca985af8ad30b 100644
--- a/clang/lib/AST/Interp/Program.h
+++ b/clang/lib/AST/Interp/Program.h
@@ -29,15 +29,12 @@ namespace clang {
 class RecordDecl;
 class Expr;
 class FunctionDecl;
-class Stmt;
 class StringLiteral;
 class VarDecl;
 
 namespace interp {
 class Context;
-class State;
 class Record;
-class Scope;
 
 /// The program contains and links the bytecode for all functions.
 class Program {

diff  --git a/clang/lib/CodeGen/CGBlocks.h b/clang/lib/CodeGen/CGBlocks.h
index 698ecd3d926a6..552d720b0a1d9 100644
--- a/clang/lib/CodeGen/CGBlocks.h
+++ b/clang/lib/CodeGen/CGBlocks.h
@@ -26,14 +26,7 @@
 #include "clang/Basic/TargetInfo.h"
 
 namespace llvm {
-class Constant;
-class Function;
-class GlobalValue;
-class DataLayout;
-class FunctionType;
-class PointerType;
 class Value;
-class LLVMContext;
 }
 
 namespace clang {

diff  --git a/clang/lib/CodeGen/CGCXXABI.h b/clang/lib/CodeGen/CGCXXABI.h
index ea839db7528eb..e94e19bab0ad1 100644
--- a/clang/lib/CodeGen/CGCXXABI.h
+++ b/clang/lib/CodeGen/CGCXXABI.h
@@ 

[PATCH] D116865: [OpenMP][FIX] Emit debug declares only if debug info is available

2022-01-08 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert created this revision.
jdoerfert added reviewers: ye-luo, JonChesterfield, jhuber6.
Herald added subscribers: guansong, bollu, yaxunl.
jdoerfert requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

The `EmitDeclareOfAutoVariable` introduced in D114504 
 and D115510 
 has a
precondition that cannot be violated. It is unclear if we should call it
directly given the sparse usage in clang but for now we should at least
not crash if the debug info kind is too low.

Fixes #52938.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116865

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/debug_private.c
  clang/test/OpenMP/debug_task_shared.c


Index: clang/test/OpenMP/debug_task_shared.c
===
--- clang/test/OpenMP/debug_task_shared.c
+++ clang/test/OpenMP/debug_task_shared.c
@@ -5,6 +5,9 @@
 
 // RUN: %clang_cc1 -debug-info-kind=constructor -DSHARED -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=CHECK
 // RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=line-directives-only -DSHARED -x c -verify 
-triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=line-tables-only -DSHARED -x c -verify 
-triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=limited -DSHARED -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=CHECK
 // expected-no-diagnostics
 
 // CHECK-LABEL: define internal i32 @.omp_task_entry.
Index: clang/test/OpenMP/debug_private.c
===
--- clang/test/OpenMP/debug_private.c
+++ clang/test/OpenMP/debug_private.c
@@ -4,6 +4,9 @@
 // REQUIRES: x86_64-linux
 
 // RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=line-directives-only -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=line-tables-only -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s 
--check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=limited -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
 // expected-no-diagnostics
 
 // CHECK: define internal i32 @.omp_task_entry.
@@ -11,6 +14,7 @@
 // CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv.ptr.addr.i, 
metadata [[PRIV1:![0-9]+]], metadata !DIExpression(DW_OP_deref))
 // CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv.ptr.addr1.i, 
metadata [[PRIV2:![0-9]+]], metadata !DIExpression(DW_OP_deref))
 // CHECK:  call void @llvm.dbg.declare(metadata i32** %.firstpriv.ptr.addr.i, 
metadata [[FPRIV:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+// NEG-NOT: call void @llvm.dbg.declare
 
 // CHECK: [[PRIV1]] = !DILocalVariable(name: "priv1"
 // CHECK: [[PRIV2]] = !DILocalVariable(name: "priv2"
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -4460,8 +4460,9 @@
   CGF.getContext().getASTRecordLayout(CaptureRecord);
   unsigned Offset =
   Layout.getFieldOffset(It->second->getFieldIndex()) / CharWidth;
-  (void)DI->EmitDeclareOfAutoVariable(SharedVar, ContextValue,
-  CGF.Builder, false);
+  if (CGF.CGM.getCodeGenOpts().hasReducedDebugInfo())
+(void)DI->EmitDeclareOfAutoVariable(SharedVar, ContextValue,
+CGF.Builder, false);
   llvm::Instruction  = CGF.Builder.GetInsertBlock()->back();
   // Get the call dbg.declare instruction we just created and update
   // its DIExpression to add offset to base address.
@@ -4560,8 +4561,9 @@
 CGF.getContext().getDeclAlign(Pair.first));
 Scope.addPrivate(Pair.first, [Replacement]() { return Replacement; });
 if (auto *DI = CGF.getDebugInfo())
-  DI->EmitDeclareOfAutoVariable(Pair.first, Pair.second.getPointer(),
-CGF.Builder, /*UsePointerValue*/ true);
+  if (CGF.CGM.getCodeGenOpts().hasReducedDebugInfo())
+(void)DI->EmitDeclareOfAutoVariable(Pair.first, 
Pair.second.getPointer(),
+  CGF.Builder, /*UsePointerValue*/ 
true);
   }
   

[PATCH] D96248: [OpenMP][AMDGPU] Add support for linking libomptarget bitcode

2022-01-08 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added inline comments.



Comment at: clang/include/clang/Driver/Options.td:948
 def libomptarget_nvptx_bc_path_EQ : Joined<["--"], 
"libomptarget-nvptx-bc-path=">, Group,
   HelpText<"Path to libomptarget-nvptx bitcode library">;
 def dD : Flag<["-"], "dD">, Group, Flags<[CC1Option]>,

jdoerfert wrote:
> Why do we need two options that literally do the same thing?
> I cannot think of a use case where we would specify two distinct paths, can 
> anyone else?
It's for when someone has decided to put nvptx bitcode in one directory and 
amdgpu in another. That's presently useless. It might be more helpful once we 
can target both platforms from one compile, but even then passing bitcode-path 
once per arch seems better.

In favour of throwing one option away and renaming the other to work on 
both/all targets


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96248

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


[PATCH] D96248: [OpenMP][AMDGPU] Add support for linking libomptarget bitcode

2022-01-08 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert reopened this revision.
jdoerfert added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/include/clang/Driver/Options.td:948
 def libomptarget_nvptx_bc_path_EQ : Joined<["--"], 
"libomptarget-nvptx-bc-path=">, Group,
   HelpText<"Path to libomptarget-nvptx bitcode library">;
 def dD : Flag<["-"], "dD">, Group, Flags<[CC1Option]>,

Why do we need two options that literally do the same thing?
I cannot think of a use case where we would specify two distinct paths, can 
anyone else?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96248

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


[PATCH] D116722: [clang] Verify ssp buffer size is a valid integer

2022-01-08 Thread Alex via Phabricator via cfe-commits
alextsao1999 updated this revision to Diff 398354.
alextsao1999 added a comment.

update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116722

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Clang.cpp


Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3187,14 +3187,27 @@
 CmdArgs.push_back(Args.MakeArgString(Twine(StackProtectorLevel)));
   }
 
+  auto IsInteger = [](StringRef Str) -> bool {
+if (Str.empty())
+  return false;
+for (auto  : Str)
+  if (Chr < '0' || Chr > '9')
+return false;
+return true;
+  };
+
   // --param ssp-buffer-size=
   for (const Arg *A : Args.filtered(options::OPT__param)) {
 StringRef Str(A->getValue());
-if (Str.startswith("ssp-buffer-size=")) {
+auto StrSplit = Str.split('=');
+if (StrSplit.first.equals("ssp-buffer-size")) {
   if (StackProtectorLevel) {
-CmdArgs.push_back("-stack-protector-buffer-size");
-// FIXME: Verify the argument is a valid integer.
-CmdArgs.push_back(Args.MakeArgString(Str.drop_front(16)));
+if (IsInteger(StrSplit.second)) {
+  CmdArgs.push_back("-stack-protector-buffer-size");
+  CmdArgs.push_back(Args.MakeArgString(StrSplit.second));
+} else {
+  D.Diag(clang::diag::err_invalid_ssp_buffer_size);
+}
   }
   A->claim();
 }
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -278,6 +278,8 @@
   DefaultError;
 def err_invalid_macos_32bit_deployment_target : Error<
   "32-bit targets are not supported when building for Mac Catalyst">;
+def err_invalid_ssp_buffer_size : Error<
+  "ssp buffer size is not valid">;
 def err_drv_invalid_os_in_arg : Error<"invalid OS value '%0' in '%1'">;
 def err_drv_conflicting_deployment_targets : Error<
   "conflicting deployment targets, both '%0' and '%1' are present in 
environment">;


Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3187,14 +3187,27 @@
 CmdArgs.push_back(Args.MakeArgString(Twine(StackProtectorLevel)));
   }
 
+  auto IsInteger = [](StringRef Str) -> bool {
+if (Str.empty())
+  return false;
+for (auto  : Str)
+  if (Chr < '0' || Chr > '9')
+return false;
+return true;
+  };
+
   // --param ssp-buffer-size=
   for (const Arg *A : Args.filtered(options::OPT__param)) {
 StringRef Str(A->getValue());
-if (Str.startswith("ssp-buffer-size=")) {
+auto StrSplit = Str.split('=');
+if (StrSplit.first.equals("ssp-buffer-size")) {
   if (StackProtectorLevel) {
-CmdArgs.push_back("-stack-protector-buffer-size");
-// FIXME: Verify the argument is a valid integer.
-CmdArgs.push_back(Args.MakeArgString(Str.drop_front(16)));
+if (IsInteger(StrSplit.second)) {
+  CmdArgs.push_back("-stack-protector-buffer-size");
+  CmdArgs.push_back(Args.MakeArgString(StrSplit.second));
+} else {
+  D.Diag(clang::diag::err_invalid_ssp_buffer_size);
+}
   }
   A->claim();
 }
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -278,6 +278,8 @@
   DefaultError;
 def err_invalid_macos_32bit_deployment_target : Error<
   "32-bit targets are not supported when building for Mac Catalyst">;
+def err_invalid_ssp_buffer_size : Error<
+  "ssp buffer size is not valid">;
 def err_drv_invalid_os_in_arg : Error<"invalid OS value '%0' in '%1'">;
 def err_drv_conflicting_deployment_targets : Error<
   "conflicting deployment targets, both '%0' and '%1' are present in environment">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116861: [UBSan] Fix incorrect alignment reported when global new returns an offset pointer

2022-01-08 Thread Lambert Clara via Phabricator via cfe-commits
belkiss updated this revision to Diff 398351.
belkiss added a comment.

Clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116861

Files:
  clang/lib/CodeGen/CGExprCXX.cpp
  compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp


Index: compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp
===
--- /dev/null
+++ compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp
@@ -0,0 +1,34 @@
+// RUN: %clangxx -fsanitize=alignment %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not="runtime error" 
-allow-empty
+// Disable with msan and tsan because they also override global new
+// UNSUPPORTED: ubsan-msan, ubsan-tsan
+
+#include 
+#include 
+#include 
+
+void *operator new(std::size_t count) {
+  constexpr const size_t offset = 8;
+
+  // allocate a bit more so we can safely offset it
+  void *ptr = std::malloc(count + offset);
+
+  // verify malloc returned 16 bytes aligned mem
+  static_assert(__STDCPP_DEFAULT_NEW_ALIGNMENT__ == 16,
+"Global new doesn't return 16 bytes aligned memory!");
+  assert(((std::ptrdiff_t)ptr & (__STDCPP_DEFAULT_NEW_ALIGNMENT__ - 1)) == 0);
+
+  return (char *)ptr + offset;
+}
+
+struct Param {
+  void *_cookie1;
+  void *_cookie2;
+};
+
+static_assert(alignof(Param) == 8, "Param struct alignment must be 8 bytes!");
+
+int main() {
+  // CHECK-NOT: runtime error: constructor call on misaligned address 
[[PTR:0x[0-9a-f]*]] for type 'Param', which requires 16 byte alignment
+  Param *p = new Param;
+}
Index: clang/lib/CodeGen/CGExprCXX.cpp
===
--- clang/lib/CodeGen/CGExprCXX.cpp
+++ clang/lib/CodeGen/CGExprCXX.cpp
@@ -1731,8 +1731,8 @@
   SkippedChecks.set(SanitizerKind::Null, nullCheck);
   EmitTypeCheck(CodeGenFunction::TCK_ConstructorCall,
 E->getAllocatedTypeSourceInfo()->getTypeLoc().getBeginLoc(),
-result.getPointer(), allocType, result.getAlignment(),
-SkippedChecks, numElements);
+result.getPointer(), allocType, allocAlign, SkippedChecks,
+numElements);
 
   EmitNewInitializer(*this, E, allocType, elementTy, result, numElements,
  allocSizeWithoutCookie);


Index: compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp
===
--- /dev/null
+++ compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp
@@ -0,0 +1,34 @@
+// RUN: %clangxx -fsanitize=alignment %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not="runtime error" -allow-empty
+// Disable with msan and tsan because they also override global new
+// UNSUPPORTED: ubsan-msan, ubsan-tsan
+
+#include 
+#include 
+#include 
+
+void *operator new(std::size_t count) {
+  constexpr const size_t offset = 8;
+
+  // allocate a bit more so we can safely offset it
+  void *ptr = std::malloc(count + offset);
+
+  // verify malloc returned 16 bytes aligned mem
+  static_assert(__STDCPP_DEFAULT_NEW_ALIGNMENT__ == 16,
+"Global new doesn't return 16 bytes aligned memory!");
+  assert(((std::ptrdiff_t)ptr & (__STDCPP_DEFAULT_NEW_ALIGNMENT__ - 1)) == 0);
+
+  return (char *)ptr + offset;
+}
+
+struct Param {
+  void *_cookie1;
+  void *_cookie2;
+};
+
+static_assert(alignof(Param) == 8, "Param struct alignment must be 8 bytes!");
+
+int main() {
+  // CHECK-NOT: runtime error: constructor call on misaligned address [[PTR:0x[0-9a-f]*]] for type 'Param', which requires 16 byte alignment
+  Param *p = new Param;
+}
Index: clang/lib/CodeGen/CGExprCXX.cpp
===
--- clang/lib/CodeGen/CGExprCXX.cpp
+++ clang/lib/CodeGen/CGExprCXX.cpp
@@ -1731,8 +1731,8 @@
   SkippedChecks.set(SanitizerKind::Null, nullCheck);
   EmitTypeCheck(CodeGenFunction::TCK_ConstructorCall,
 E->getAllocatedTypeSourceInfo()->getTypeLoc().getBeginLoc(),
-result.getPointer(), allocType, result.getAlignment(),
-SkippedChecks, numElements);
+result.getPointer(), allocType, allocAlign, SkippedChecks,
+numElements);
 
   EmitNewInitializer(*this, E, allocType, elementTy, result, numElements,
  allocSizeWithoutCookie);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114317: [clang-tidy][WIP] Do not run perfect alias checks

2022-01-08 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added inline comments.



Comment at: clang-tools-extra/clang-tidy/ClangTidy.cpp:442
+if (PrimaryCheckValue != Value) {
+  std::cout << "Alias check \"" << CheckName.str() << "\" of \""
+<< PrimaryCheckName.str() << "\""

Jeroen wrote:
> I'm not sure if you have this in for testing purpose or not, though I really 
> like to have this message. If I would be having 2 aliases active with 
> different options, it would be nice to know about that. So please keep this 
> in!
> Preferably, we would only configure it once, though that's dreaming.
Yep, all printouts are just for my own testing, but good to hear it's useful 
info for production! I'll see if I get some time and clean this up.


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

https://reviews.llvm.org/D114317

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


[PATCH] D116861: [UBSan] Fix incorrect alignment reported when global new returns an offset pointer

2022-01-08 Thread Lambert Clara via Phabricator via cfe-commits
belkiss updated this revision to Diff 398350.
belkiss added a comment.

Squash commits, for some reason update dropped the first commit (first time 
using arcanist...).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116861

Files:
  clang/lib/CodeGen/CGExprCXX.cpp
  compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp


Index: compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp
===
--- /dev/null
+++ compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp
@@ -0,0 +1,34 @@
+// RUN: %clangxx -fsanitize=alignment %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not="runtime error" 
-allow-empty
+// Disable with msan and tsan because they also override global new
+// UNSUPPORTED: ubsan-msan, ubsan-tsan
+
+#include 
+#include 
+#include 
+
+void *operator new(std::size_t count) {
+  constexpr const size_t offset = 8;
+
+  // allocate a bit more so we can safely offset it
+  void *ptr = std::malloc(count + offset);
+
+  // verify malloc returned 16 bytes aligned mem
+  static_assert(__STDCPP_DEFAULT_NEW_ALIGNMENT__ == 16,
+"Global new doesn't return 16 bytes aligned memory!");
+  assert(((std::ptrdiff_t)ptr & (__STDCPP_DEFAULT_NEW_ALIGNMENT__ - 1)) == 0);
+
+  return (char *)ptr + offset;
+}
+
+struct Param {
+  void *_cookie1;
+  void *_cookie2;
+};
+
+static_assert(alignof(Param) == 8, "Param struct alignment must be 8 bytes!");
+
+int main() {
+  // CHECK-NOT: runtime error: constructor call on misaligned address 
[[PTR:0x[0-9a-f]*]] for type 'Param', which requires 16 byte alignment
+  Param *p = new Param;
+}
Index: clang/lib/CodeGen/CGExprCXX.cpp
===
--- clang/lib/CodeGen/CGExprCXX.cpp
+++ clang/lib/CodeGen/CGExprCXX.cpp
@@ -1731,7 +1731,7 @@
   SkippedChecks.set(SanitizerKind::Null, nullCheck);
   EmitTypeCheck(CodeGenFunction::TCK_ConstructorCall,
 E->getAllocatedTypeSourceInfo()->getTypeLoc().getBeginLoc(),
-result.getPointer(), allocType, result.getAlignment(),
+result.getPointer(), allocType, allocAlign,
 SkippedChecks, numElements);
 
   EmitNewInitializer(*this, E, allocType, elementTy, result, numElements,


Index: compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp
===
--- /dev/null
+++ compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp
@@ -0,0 +1,34 @@
+// RUN: %clangxx -fsanitize=alignment %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not="runtime error" -allow-empty
+// Disable with msan and tsan because they also override global new
+// UNSUPPORTED: ubsan-msan, ubsan-tsan
+
+#include 
+#include 
+#include 
+
+void *operator new(std::size_t count) {
+  constexpr const size_t offset = 8;
+
+  // allocate a bit more so we can safely offset it
+  void *ptr = std::malloc(count + offset);
+
+  // verify malloc returned 16 bytes aligned mem
+  static_assert(__STDCPP_DEFAULT_NEW_ALIGNMENT__ == 16,
+"Global new doesn't return 16 bytes aligned memory!");
+  assert(((std::ptrdiff_t)ptr & (__STDCPP_DEFAULT_NEW_ALIGNMENT__ - 1)) == 0);
+
+  return (char *)ptr + offset;
+}
+
+struct Param {
+  void *_cookie1;
+  void *_cookie2;
+};
+
+static_assert(alignof(Param) == 8, "Param struct alignment must be 8 bytes!");
+
+int main() {
+  // CHECK-NOT: runtime error: constructor call on misaligned address [[PTR:0x[0-9a-f]*]] for type 'Param', which requires 16 byte alignment
+  Param *p = new Param;
+}
Index: clang/lib/CodeGen/CGExprCXX.cpp
===
--- clang/lib/CodeGen/CGExprCXX.cpp
+++ clang/lib/CodeGen/CGExprCXX.cpp
@@ -1731,7 +1731,7 @@
   SkippedChecks.set(SanitizerKind::Null, nullCheck);
   EmitTypeCheck(CodeGenFunction::TCK_ConstructorCall,
 E->getAllocatedTypeSourceInfo()->getTypeLoc().getBeginLoc(),
-result.getPointer(), allocType, result.getAlignment(),
+result.getPointer(), allocType, allocAlign,
 SkippedChecks, numElements);
 
   EmitNewInitializer(*this, E, allocType, elementTy, result, numElements,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116861: [UBSan] Fix incorrect alignment reported when global new returns an offset pointer

2022-01-08 Thread Lambert Clara via Phabricator via cfe-commits
belkiss updated this revision to Diff 398346.
belkiss added a comment.

Disable the test in ubsan-msan and ubsan-tsan since they also override global 
new, causing link error.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116861

Files:
  compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp


Index: compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp
===
--- compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp
+++ compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp
@@ -1,5 +1,7 @@
 // RUN: %clangxx -fsanitize=alignment %s -o %t
 // RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not="runtime error" 
-allow-empty
+// Disable with msan and tsan because they also override global new
+// UNSUPPORTED: ubsan-msan, ubsan-tsan
 
 #include 
 #include 


Index: compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp
===
--- compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp
+++ compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp
@@ -1,5 +1,7 @@
 // RUN: %clangxx -fsanitize=alignment %s -o %t
 // RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not="runtime error" -allow-empty
+// Disable with msan and tsan because they also override global new
+// UNSUPPORTED: ubsan-msan, ubsan-tsan
 
 #include 
 #include 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114317: [clang-tidy][WIP] Do not run perfect alias checks

2022-01-08 Thread Jeroen Van Antwerpen via Phabricator via cfe-commits
Jeroen added inline comments.



Comment at: clang-tools-extra/clang-tidy/ClangTidy.cpp:442
+if (PrimaryCheckValue != Value) {
+  std::cout << "Alias check \"" << CheckName.str() << "\" of \""
+<< PrimaryCheckName.str() << "\""

I'm not sure if you have this in for testing purpose or not, though I really 
like to have this message. If I would be having 2 aliases active with different 
options, it would be nice to know about that. So please keep this in!
Preferably, we would only configure it once, though that's dreaming.


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

https://reviews.llvm.org/D114317

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


[PATCH] D116638: [clang-format] Fix ignoring JavaScriptWrapImport when ColumnWidth: 0

2022-01-08 Thread Stanisław Małolepszy via Phabricator via cfe-commits
stasm added a comment.

The reporter of issue 52935  
here. Thanks, @andmis, for your work.  Thinking about the `ColumnLimit: 0` and 
`JavaScriptWrapImports: false` case, it seems that there are two issues in the 
current implementation that could be solved separately.

1. Single-line imports get force-wrapped despite `JavaScriptWrapImports: 
false`. This seems to be a clear bug in `clang-format`. The expected behavior 
in this case should be to not touch the import line at all. Instead, the 
current behavior is the following:

  import {aaa, bbb, ccc} from "def";



  import {aaa,
  bbb,
  ccc} from "def";



2. It's not clear what `JavaScriptWrapImports: false` should do to multiline 
imports when `ColumnLimit: 0`. Should it
  - force-unwrap to a single line, or
  - leave the import as-is (i.e. //not force-wrap// it)?

Since the expected behavior is not clear there might indeed be different 
groups of users expecting one behavior or the other. To reduce the ambiguity an 
enum option like the one proposed by @MyDeveloperDay  would be helpful.

I'd personally would love to see both of these issues addressed (and I'd be a 
happy user of `JavaScriptWrapImports: Never` if it's available), but just 
fixing the first bug would go a long way in making `ColumnLimit: 0` a viable 
setting for JavaScript for me.


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

https://reviews.llvm.org/D116638

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


[PATCH] D116833: [clang] Introduce support for disabling warnings in system macros

2022-01-08 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 398339.
carlosgalvezp retitled this revision from "[clang][Sema] Introduce support for 
disabling warnings in system macros" to "[clang] Introduce support for 
disabling warnings in system macros".
carlosgalvezp added a comment.
Herald added a subscriber: kadircet.
Herald added a project: clang-tools-extra.

Update DIAG in clang-tools-extra/Diagnostics


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116833

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang/include/clang/Basic/Diagnostic.td
  clang/include/clang/Basic/DiagnosticAST.h
  clang/include/clang/Basic/DiagnosticAnalysis.h
  clang/include/clang/Basic/DiagnosticComment.h
  clang/include/clang/Basic/DiagnosticCrossTU.h
  clang/include/clang/Basic/DiagnosticDriver.h
  clang/include/clang/Basic/DiagnosticFrontend.h
  clang/include/clang/Basic/DiagnosticIDs.h
  clang/include/clang/Basic/DiagnosticLex.h
  clang/include/clang/Basic/DiagnosticParse.h
  clang/include/clang/Basic/DiagnosticRefactoring.h
  clang/include/clang/Basic/DiagnosticSema.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/DiagnosticSerialization.h
  clang/lib/Basic/DiagnosticIDs.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/warn-sysheader-macro.cpp
  clang/test/TableGen/DiagnosticBase.inc
  clang/test/TableGen/deferred-diag.td
  clang/tools/diagtool/DiagnosticNames.cpp
  clang/utils/TableGen/ClangDiagnosticsEmitter.cpp

Index: clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
===
--- clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -1311,6 +1311,11 @@
 else
   OS << ", false";
 
+if (R.getValueAsBit("ShowInSystemMacro"))
+  OS << ", true";
+else
+  OS << ", false";
+
 if (R.getValueAsBit("Deferrable"))
   OS << ", true";
 else
Index: clang/tools/diagtool/DiagnosticNames.cpp
===
--- clang/tools/diagtool/DiagnosticNames.cpp
+++ clang/tools/diagtool/DiagnosticNames.cpp
@@ -27,9 +27,9 @@
 // FIXME: Is it worth having two tables, especially when this one can get
 // out of sync easily?
 static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
-#define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP,   \
- SFINAE,NOWERROR,SHOWINSYSHEADER,DEFER,CATEGORY)\
-  { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) },
+#define DIAG(ENUM, CLASS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR,  \
+ SHOWINSYSHEADER, SHOWINSYSMACRO, DEFER, CATEGORY) \
+  {#ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t)},
 #include "clang/Basic/DiagnosticCommonKinds.inc"
 #include "clang/Basic/DiagnosticCrossTUKinds.inc"
 #include "clang/Basic/DiagnosticDriverKinds.inc"
Index: clang/test/TableGen/deferred-diag.td
===
--- clang/test/TableGen/deferred-diag.td
+++ clang/test/TableGen/deferred-diag.td
@@ -5,23 +5,23 @@
 // Test usage of Deferrable and NonDeferrable in diagnostics.
 
 def test_default : Error<"This error is non-deferrable by default">;
-// CHECK-DAG: DIAG(test_default, {{.*}}SFINAE_SubstitutionFailure, false, true, false, 0)
+// CHECK-DAG: DIAG(test_default, {{.*}}SFINAE_SubstitutionFailure, false, true, true, false, 0)
 
 def test_deferrable : Error<"This error is deferrable">, Deferrable;
-// CHECK-DAG: DIAG(test_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, true, true, 0)
+// CHECK-DAG: DIAG(test_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, true, true, true, 0)
 
 def test_non_deferrable : Error<"This error is non-deferrable">, NonDeferrable;
-// CHECK-DAG: DIAG(test_non_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, true, false, 0)
+// CHECK-DAG: DIAG(test_non_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, true, true, false, 0)
 
 let Deferrable = 1 in {
 
 def test_let : Error<"This error is deferrable by let">;
-// CHECK-DAG: DIAG(test_let, {{.*}} SFINAE_SubstitutionFailure, false, true, true, 0)
+// CHECK-DAG: DIAG(test_let, {{.*}} SFINAE_SubstitutionFailure, false, true, true, true, 0)
 
 // Make sure TextSubstitution is allowed in the let Deferrable block.
 def textsub : TextSubstitution<"%select{text1|text2}0">;
 
 def test_let2 : Error<"This error is deferrable by let %sub{textsub}0">;
-// CHECK-DAG: DIAG(test_let2, {{.*}} SFINAE_SubstitutionFailure, false, true, true, 0)
+// CHECK-DAG: DIAG(test_let2, {{.*}} SFINAE_SubstitutionFailure, false, true, true, true, 0)
 
-}
\ No newline at end of file
+}
Index: clang/test/TableGen/DiagnosticBase.inc
===
--- clang/test/TableGen/DiagnosticBase.inc
+++ clang/test/TableGen/DiagnosticBase.inc
@@ -76,6 +76,7 @@
   bit

[clang] 6ee589e - [CGObjCMac] Use castAs<> instead of getAs<> to avoid dereference of nullptr inside BuildRCBlockVarRecordLayout

2022-01-08 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2022-01-08T16:18:55Z
New Revision: 6ee589e2f563a2a5c91f9aeb2762f092dd197e32

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

LOG: [CGObjCMac] Use castAs<> instead of getAs<> to avoid dereference of 
nullptr inside BuildRCBlockVarRecordLayout

This will assert the cast is correct instead of returning nullptr (UnionType is 
a subtype of RecordType so this should be clean).

Added: 


Modified: 
clang/lib/CodeGen/CGObjCMac.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index d769574c1f5ef..d07524be127bb 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -2487,7 +2487,7 @@ void CGObjCCommonMac::BuildRCRecordLayout(const 
llvm::StructLayout *RecLayout,
   if (FQT->isUnionType())
 HasUnion = true;
 
-  BuildRCBlockVarRecordLayout(FQT->getAs(),
+  BuildRCBlockVarRecordLayout(FQT->castAs(),
   BytePos + FieldOffset, HasUnion);
   continue;
 }



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


[PATCH] D116861: [UBSan] Fix incorrect alignment reported when global new returns an offset pointer

2022-01-08 Thread Lambert Clara via Phabricator via cfe-commits
belkiss created this revision.
belkiss requested review of this revision.
Herald added projects: clang, Sanitizers.
Herald added subscribers: Sanitizers, cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116861

Files:
  clang/lib/CodeGen/CGExprCXX.cpp
  compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp


Index: compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp
===
--- /dev/null
+++ compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp
@@ -0,0 +1,32 @@
+// RUN: %clangxx -fsanitize=alignment %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not="runtime error" 
-allow-empty
+
+#include 
+#include 
+#include 
+
+void *operator new(std::size_t count) {
+  constexpr const size_t offset = 8;
+
+  // allocate a bit more so we can safely offset it
+  void *ptr = std::malloc(count + offset);
+
+  // verify malloc returned 16 bytes aligned mem
+  static_assert(__STDCPP_DEFAULT_NEW_ALIGNMENT__ == 16,
+"Global new doesn't return 16 bytes aligned memory!");
+  assert(((std::ptrdiff_t)ptr & (__STDCPP_DEFAULT_NEW_ALIGNMENT__ - 1)) == 0);
+
+  return (char *)ptr + offset;
+}
+
+struct Param {
+  void *_cookie1;
+  void *_cookie2;
+};
+
+static_assert(alignof(Param) == 8, "Param struct alignment must be 8 bytes!");
+
+int main() {
+  // CHECK-NOT: runtime error: constructor call on misaligned address 
[[PTR:0x[0-9a-f]*]] for type 'Param', which requires 16 byte alignment
+  Param *p = new Param;
+}
Index: clang/lib/CodeGen/CGExprCXX.cpp
===
--- clang/lib/CodeGen/CGExprCXX.cpp
+++ clang/lib/CodeGen/CGExprCXX.cpp
@@ -1731,7 +1731,7 @@
   SkippedChecks.set(SanitizerKind::Null, nullCheck);
   EmitTypeCheck(CodeGenFunction::TCK_ConstructorCall,
 E->getAllocatedTypeSourceInfo()->getTypeLoc().getBeginLoc(),
-result.getPointer(), allocType, result.getAlignment(),
+result.getPointer(), allocType, allocAlign,
 SkippedChecks, numElements);
 
   EmitNewInitializer(*this, E, allocType, elementTy, result, numElements,


Index: compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp
===
--- /dev/null
+++ compiler-rt/test/ubsan/TestCases/TypeCheck/global-new-alignment.cpp
@@ -0,0 +1,32 @@
+// RUN: %clangxx -fsanitize=alignment %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not="runtime error" -allow-empty
+
+#include 
+#include 
+#include 
+
+void *operator new(std::size_t count) {
+  constexpr const size_t offset = 8;
+
+  // allocate a bit more so we can safely offset it
+  void *ptr = std::malloc(count + offset);
+
+  // verify malloc returned 16 bytes aligned mem
+  static_assert(__STDCPP_DEFAULT_NEW_ALIGNMENT__ == 16,
+"Global new doesn't return 16 bytes aligned memory!");
+  assert(((std::ptrdiff_t)ptr & (__STDCPP_DEFAULT_NEW_ALIGNMENT__ - 1)) == 0);
+
+  return (char *)ptr + offset;
+}
+
+struct Param {
+  void *_cookie1;
+  void *_cookie2;
+};
+
+static_assert(alignof(Param) == 8, "Param struct alignment must be 8 bytes!");
+
+int main() {
+  // CHECK-NOT: runtime error: constructor call on misaligned address [[PTR:0x[0-9a-f]*]] for type 'Param', which requires 16 byte alignment
+  Param *p = new Param;
+}
Index: clang/lib/CodeGen/CGExprCXX.cpp
===
--- clang/lib/CodeGen/CGExprCXX.cpp
+++ clang/lib/CodeGen/CGExprCXX.cpp
@@ -1731,7 +1731,7 @@
   SkippedChecks.set(SanitizerKind::Null, nullCheck);
   EmitTypeCheck(CodeGenFunction::TCK_ConstructorCall,
 E->getAllocatedTypeSourceInfo()->getTypeLoc().getBeginLoc(),
-result.getPointer(), allocType, result.getAlignment(),
+result.getPointer(), allocType, allocAlign,
 SkippedChecks, numElements);
 
   EmitNewInitializer(*this, E, allocType, elementTy, result, numElements,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115942: [X86][MS] Change the alignment of f80 to 16 bytes on Windows 32bits to match with ICC

2022-01-08 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei updated this revision to Diff 398335.
pengfei added a comment.

Missed one unittest.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115942

Files:
  clang/lib/Basic/Targets/X86.h
  clang/test/CodeGen/target-data.c
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/test/Bitcode/upgrade-datalayout3.ll
  llvm/test/CodeGen/X86/long-double-abi-align.ll
  llvm/test/CodeGen/X86/scalar-fp-to-i32.ll
  llvm/test/CodeGen/X86/scalar-fp-to-i64.ll
  llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp

Index: llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
===
--- llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
+++ llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
@@ -24,7 +24,7 @@
   EXPECT_EQ(DL1, "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64"
  "-f80:128-n8:16:32:64-S128");
   EXPECT_EQ(DL2, "e-m:w-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64"
- "-f80:32-n8:16:32-S32");
+ "-f80:128-n8:16:32-S32");
   EXPECT_EQ(DL3, "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128"
  "-n32:64-S128");
 
Index: llvm/test/CodeGen/X86/scalar-fp-to-i64.ll
===
--- llvm/test/CodeGen/X86/scalar-fp-to-i64.ll
+++ llvm/test/CodeGen/X86/scalar-fp-to-i64.ll
@@ -909,8 +909,8 @@
 ; X86-AVX512-WIN:   # %bb.0:
 ; X86-AVX512-WIN-NEXT:pushl %ebp
 ; X86-AVX512-WIN-NEXT:movl %esp, %ebp
-; X86-AVX512-WIN-NEXT:andl $-8, %esp
-; X86-AVX512-WIN-NEXT:subl $8, %esp
+; X86-AVX512-WIN-NEXT:andl $-16, %esp
+; X86-AVX512-WIN-NEXT:subl $16, %esp
 ; X86-AVX512-WIN-NEXT:fldt 8(%ebp)
 ; X86-AVX512-WIN-NEXT:flds __real@5f00
 ; X86-AVX512-WIN-NEXT:xorl %edx, %edx
@@ -985,8 +985,8 @@
 ; X86-SSE3-WIN:   # %bb.0:
 ; X86-SSE3-WIN-NEXT:pushl %ebp
 ; X86-SSE3-WIN-NEXT:movl %esp, %ebp
-; X86-SSE3-WIN-NEXT:andl $-8, %esp
-; X86-SSE3-WIN-NEXT:subl $8, %esp
+; X86-SSE3-WIN-NEXT:andl $-16, %esp
+; X86-SSE3-WIN-NEXT:subl $16, %esp
 ; X86-SSE3-WIN-NEXT:fldt 8(%ebp)
 ; X86-SSE3-WIN-NEXT:flds __real@5f00
 ; X86-SSE3-WIN-NEXT:xorl %edx, %edx
@@ -1061,8 +1061,8 @@
 ; X86-SSE2-WIN:   # %bb.0:
 ; X86-SSE2-WIN-NEXT:pushl %ebp
 ; X86-SSE2-WIN-NEXT:movl %esp, %ebp
-; X86-SSE2-WIN-NEXT:andl $-8, %esp
-; X86-SSE2-WIN-NEXT:subl $16, %esp
+; X86-SSE2-WIN-NEXT:andl $-16, %esp
+; X86-SSE2-WIN-NEXT:subl $32, %esp
 ; X86-SSE2-WIN-NEXT:fldt 8(%ebp)
 ; X86-SSE2-WIN-NEXT:flds __real@5f00
 ; X86-SSE2-WIN-NEXT:xorl %edx, %edx
@@ -1161,8 +1161,8 @@
 ; X87-WIN:   # %bb.0:
 ; X87-WIN-NEXT:pushl %ebp
 ; X87-WIN-NEXT:movl %esp, %ebp
-; X87-WIN-NEXT:andl $-8, %esp
-; X87-WIN-NEXT:subl $16, %esp
+; X87-WIN-NEXT:andl $-16, %esp
+; X87-WIN-NEXT:subl $32, %esp
 ; X87-WIN-NEXT:fldt 8(%ebp)
 ; X87-WIN-NEXT:flds __real@5f00
 ; X87-WIN-NEXT:fucom %st(1)
@@ -1235,8 +1235,8 @@
 ; X86-AVX512-WIN:   # %bb.0:
 ; X86-AVX512-WIN-NEXT:pushl %ebp
 ; X86-AVX512-WIN-NEXT:movl %esp, %ebp
-; X86-AVX512-WIN-NEXT:andl $-8, %esp
-; X86-AVX512-WIN-NEXT:subl $8, %esp
+; X86-AVX512-WIN-NEXT:andl $-16, %esp
+; X86-AVX512-WIN-NEXT:subl $16, %esp
 ; X86-AVX512-WIN-NEXT:fldt 8(%ebp)
 ; X86-AVX512-WIN-NEXT:fisttpll (%esp)
 ; X86-AVX512-WIN-NEXT:movl (%esp), %eax
@@ -1275,8 +1275,8 @@
 ; X86-SSE3-WIN:   # %bb.0:
 ; X86-SSE3-WIN-NEXT:pushl %ebp
 ; X86-SSE3-WIN-NEXT:movl %esp, %ebp
-; X86-SSE3-WIN-NEXT:andl $-8, %esp
-; X86-SSE3-WIN-NEXT:subl $8, %esp
+; X86-SSE3-WIN-NEXT:andl $-16, %esp
+; X86-SSE3-WIN-NEXT:subl $16, %esp
 ; X86-SSE3-WIN-NEXT:fldt 8(%ebp)
 ; X86-SSE3-WIN-NEXT:fisttpll (%esp)
 ; X86-SSE3-WIN-NEXT:movl (%esp), %eax
@@ -1315,8 +1315,8 @@
 ; X86-SSE2-WIN:   # %bb.0:
 ; X86-SSE2-WIN-NEXT:pushl %ebp
 ; X86-SSE2-WIN-NEXT:movl %esp, %ebp
-; X86-SSE2-WIN-NEXT:andl $-8, %esp
-; X86-SSE2-WIN-NEXT:subl $16, %esp
+; X86-SSE2-WIN-NEXT:andl $-16, %esp
+; X86-SSE2-WIN-NEXT:subl $32, %esp
 ; X86-SSE2-WIN-NEXT:fldt 8(%ebp)
 ; X86-SSE2-WIN-NEXT:fnstcw {{[0-9]+}}(%esp)
 ; X86-SSE2-WIN-NEXT:movzwl {{[0-9]+}}(%esp), %eax
@@ -1379,8 +1379,8 @@
 ; X87-WIN:   # %bb.0:
 ; X87-WIN-NEXT:pushl %ebp
 ; X87-WIN-NEXT:movl %esp, %ebp
-; X87-WIN-NEXT:andl $-8, %esp
-; X87-WIN-NEXT:subl $16, %esp
+; X87-WIN-NEXT:andl $-16, %esp
+; X87-WIN-NEXT:subl $32, %esp
 ; X87-WIN-NEXT:fldt 8(%ebp)
 ; X87-WIN-NEXT:fnstcw {{[0-9]+}}(%esp)
 ; X87-WIN-NEXT:movzwl {{[0-9]+}}(%esp), %eax
Index: llvm/test/CodeGen/X86/scalar-fp-to-i32.ll
===
--- llvm/test/CodeGen/X86/scalar-fp-to-i32.ll
+++ llvm/test/CodeGen/X86/scalar-fp-to-i32.ll
@@ -344,8 +344,8 @@
 ; 

[clang] 06e9733 - [CGExpr] Use castAs<> instead of getAs<> to avoid dereference of nullptr

2022-01-08 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2022-01-08T14:26:09Z
New Revision: 06e9733fec8ddafb4c830853c198204def8a091a

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

LOG: [CGExpr] Use castAs<> instead of getAs<> to avoid dereference of nullptr

This will assert the cast is correct instead of returning nullptr

Added: 


Modified: 
clang/lib/CodeGen/CGExpr.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 34b4951a7f721..66079328f8d7d 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -1931,7 +1931,7 @@ RValue CodeGenFunction::EmitLoadOfLValue(LValue LV, 
SourceLocation Loc) {
   if (LV.isMatrixElt()) {
 llvm::Value *Idx = LV.getMatrixIdx();
 if (CGM.getCodeGenOpts().OptimizationLevel > 0) {
-  const auto *const MatTy = LV.getType()->getAs();
+  const auto *const MatTy = LV.getType()->castAs();
   llvm::MatrixBuilder MB(Builder);
   MB.CreateIndexAssumption(Idx, MatTy->getNumElementsFlattened());
 }
@@ -2077,7 +2077,7 @@ void CodeGenFunction::EmitStoreThroughLValue(RValue Src, 
LValue Dst,
 if (Dst.isMatrixElt()) {
   llvm::Value *Idx = Dst.getMatrixIdx();
   if (CGM.getCodeGenOpts().OptimizationLevel > 0) {
-const auto *const MatTy = Dst.getType()->getAs();
+const auto *const MatTy = Dst.getType()->castAs();
 llvm::MatrixBuilder MB(Builder);
 MB.CreateIndexAssumption(Idx, MatTy->getNumElementsFlattened());
   }



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


[PATCH] D115942: [X86][MS] Change the alignment of f80 to 16 bytes on Windows 32bits to match with ICC

2022-01-08 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei updated this revision to Diff 398334.
pengfei added a comment.
Herald added a subscriber: dexonsmith.

> However, do we need to make changes to `llvm::UpgradeDataLayoutString`? 
> Otherwise, I believe old bitcode for MSVC targets will no longer be able to 
> be loaded for LTO.

Makes sense. Done, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115942

Files:
  clang/lib/Basic/Targets/X86.h
  clang/test/CodeGen/target-data.c
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/test/Bitcode/upgrade-datalayout3.ll
  llvm/test/CodeGen/X86/long-double-abi-align.ll
  llvm/test/CodeGen/X86/scalar-fp-to-i32.ll
  llvm/test/CodeGen/X86/scalar-fp-to-i64.ll

Index: llvm/test/CodeGen/X86/scalar-fp-to-i64.ll
===
--- llvm/test/CodeGen/X86/scalar-fp-to-i64.ll
+++ llvm/test/CodeGen/X86/scalar-fp-to-i64.ll
@@ -909,8 +909,8 @@
 ; X86-AVX512-WIN:   # %bb.0:
 ; X86-AVX512-WIN-NEXT:pushl %ebp
 ; X86-AVX512-WIN-NEXT:movl %esp, %ebp
-; X86-AVX512-WIN-NEXT:andl $-8, %esp
-; X86-AVX512-WIN-NEXT:subl $8, %esp
+; X86-AVX512-WIN-NEXT:andl $-16, %esp
+; X86-AVX512-WIN-NEXT:subl $16, %esp
 ; X86-AVX512-WIN-NEXT:fldt 8(%ebp)
 ; X86-AVX512-WIN-NEXT:flds __real@5f00
 ; X86-AVX512-WIN-NEXT:xorl %edx, %edx
@@ -985,8 +985,8 @@
 ; X86-SSE3-WIN:   # %bb.0:
 ; X86-SSE3-WIN-NEXT:pushl %ebp
 ; X86-SSE3-WIN-NEXT:movl %esp, %ebp
-; X86-SSE3-WIN-NEXT:andl $-8, %esp
-; X86-SSE3-WIN-NEXT:subl $8, %esp
+; X86-SSE3-WIN-NEXT:andl $-16, %esp
+; X86-SSE3-WIN-NEXT:subl $16, %esp
 ; X86-SSE3-WIN-NEXT:fldt 8(%ebp)
 ; X86-SSE3-WIN-NEXT:flds __real@5f00
 ; X86-SSE3-WIN-NEXT:xorl %edx, %edx
@@ -1061,8 +1061,8 @@
 ; X86-SSE2-WIN:   # %bb.0:
 ; X86-SSE2-WIN-NEXT:pushl %ebp
 ; X86-SSE2-WIN-NEXT:movl %esp, %ebp
-; X86-SSE2-WIN-NEXT:andl $-8, %esp
-; X86-SSE2-WIN-NEXT:subl $16, %esp
+; X86-SSE2-WIN-NEXT:andl $-16, %esp
+; X86-SSE2-WIN-NEXT:subl $32, %esp
 ; X86-SSE2-WIN-NEXT:fldt 8(%ebp)
 ; X86-SSE2-WIN-NEXT:flds __real@5f00
 ; X86-SSE2-WIN-NEXT:xorl %edx, %edx
@@ -1161,8 +1161,8 @@
 ; X87-WIN:   # %bb.0:
 ; X87-WIN-NEXT:pushl %ebp
 ; X87-WIN-NEXT:movl %esp, %ebp
-; X87-WIN-NEXT:andl $-8, %esp
-; X87-WIN-NEXT:subl $16, %esp
+; X87-WIN-NEXT:andl $-16, %esp
+; X87-WIN-NEXT:subl $32, %esp
 ; X87-WIN-NEXT:fldt 8(%ebp)
 ; X87-WIN-NEXT:flds __real@5f00
 ; X87-WIN-NEXT:fucom %st(1)
@@ -1235,8 +1235,8 @@
 ; X86-AVX512-WIN:   # %bb.0:
 ; X86-AVX512-WIN-NEXT:pushl %ebp
 ; X86-AVX512-WIN-NEXT:movl %esp, %ebp
-; X86-AVX512-WIN-NEXT:andl $-8, %esp
-; X86-AVX512-WIN-NEXT:subl $8, %esp
+; X86-AVX512-WIN-NEXT:andl $-16, %esp
+; X86-AVX512-WIN-NEXT:subl $16, %esp
 ; X86-AVX512-WIN-NEXT:fldt 8(%ebp)
 ; X86-AVX512-WIN-NEXT:fisttpll (%esp)
 ; X86-AVX512-WIN-NEXT:movl (%esp), %eax
@@ -1275,8 +1275,8 @@
 ; X86-SSE3-WIN:   # %bb.0:
 ; X86-SSE3-WIN-NEXT:pushl %ebp
 ; X86-SSE3-WIN-NEXT:movl %esp, %ebp
-; X86-SSE3-WIN-NEXT:andl $-8, %esp
-; X86-SSE3-WIN-NEXT:subl $8, %esp
+; X86-SSE3-WIN-NEXT:andl $-16, %esp
+; X86-SSE3-WIN-NEXT:subl $16, %esp
 ; X86-SSE3-WIN-NEXT:fldt 8(%ebp)
 ; X86-SSE3-WIN-NEXT:fisttpll (%esp)
 ; X86-SSE3-WIN-NEXT:movl (%esp), %eax
@@ -1315,8 +1315,8 @@
 ; X86-SSE2-WIN:   # %bb.0:
 ; X86-SSE2-WIN-NEXT:pushl %ebp
 ; X86-SSE2-WIN-NEXT:movl %esp, %ebp
-; X86-SSE2-WIN-NEXT:andl $-8, %esp
-; X86-SSE2-WIN-NEXT:subl $16, %esp
+; X86-SSE2-WIN-NEXT:andl $-16, %esp
+; X86-SSE2-WIN-NEXT:subl $32, %esp
 ; X86-SSE2-WIN-NEXT:fldt 8(%ebp)
 ; X86-SSE2-WIN-NEXT:fnstcw {{[0-9]+}}(%esp)
 ; X86-SSE2-WIN-NEXT:movzwl {{[0-9]+}}(%esp), %eax
@@ -1379,8 +1379,8 @@
 ; X87-WIN:   # %bb.0:
 ; X87-WIN-NEXT:pushl %ebp
 ; X87-WIN-NEXT:movl %esp, %ebp
-; X87-WIN-NEXT:andl $-8, %esp
-; X87-WIN-NEXT:subl $16, %esp
+; X87-WIN-NEXT:andl $-16, %esp
+; X87-WIN-NEXT:subl $32, %esp
 ; X87-WIN-NEXT:fldt 8(%ebp)
 ; X87-WIN-NEXT:fnstcw {{[0-9]+}}(%esp)
 ; X87-WIN-NEXT:movzwl {{[0-9]+}}(%esp), %eax
Index: llvm/test/CodeGen/X86/scalar-fp-to-i32.ll
===
--- llvm/test/CodeGen/X86/scalar-fp-to-i32.ll
+++ llvm/test/CodeGen/X86/scalar-fp-to-i32.ll
@@ -344,8 +344,8 @@
 ; X86-AVX512-WIN:   # %bb.0:
 ; X86-AVX512-WIN-NEXT:pushl %ebp
 ; X86-AVX512-WIN-NEXT:movl %esp, %ebp
-; X86-AVX512-WIN-NEXT:andl $-8, %esp
-; X86-AVX512-WIN-NEXT:subl $8, %esp
+; X86-AVX512-WIN-NEXT:andl $-16, %esp
+; X86-AVX512-WIN-NEXT:subl $16, %esp
 ; X86-AVX512-WIN-NEXT:fldt 8(%ebp)
 ; X86-AVX512-WIN-NEXT:fisttpll (%esp)
 ; X86-AVX512-WIN-NEXT:movl (%esp), %eax
@@ -382,8 +382,8 @@
 ; X86-SSE3-WIN:   # %bb.0:
 ; 

[PATCH] D116859: Fix for: clang-format: break added to macro define with ColumnLimit: 0

2022-01-08 Thread Armen Khachkinaev via Phabricator via cfe-commits
futuarmo created this revision.
futuarmo added reviewers: djasper, MyDeveloperDay.
futuarmo requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix for #49164  issue.
Alse added test for this case


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116859

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -4804,6 +4804,14 @@
Style);
 }
 
+TEST_F(FormatTest, FormatMacroWithZeroColumnWidth) {
+  FormatStyle ZeroColumn = getLLVMStyleWithColumns(0);
+
+  verifyFormat("#define STRINGIFY(t) #t\n"
+   "#define MAKEVERSIONSTRING(x, y, z, build) STRINGIFY(x) \".\" 
STRINGIFY(y) \".\" STRINGIFY(z) \".\" STRINGIFY(build)\n",
+   ZeroColumn);
+}
+
 TEST_F(FormatTest, LayoutMacroDefinitionsStatementsSpanningBlocks) {
   verifyFormat("#define A \\\n"
"  f({ \\\n"
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -485,7 +485,8 @@
 // different LineFormatter would be used otherwise.
 if (Previous.ClosesTemplateDeclaration)
   return Style.AlwaysBreakTemplateDeclarations != FormatStyle::BTDS_No;
-if (Previous.is(TT_FunctionAnnotationRParen))
+if (Previous.is(TT_FunctionAnnotationRParen) &&
+State.Line->Type != LT_PreprocessorDirective)
   return true;
 if (Previous.is(TT_LeadingJavaAnnotation) && Current.isNot(tok::l_paren) &&
 Current.isNot(TT_LeadingJavaAnnotation))


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -4804,6 +4804,14 @@
Style);
 }
 
+TEST_F(FormatTest, FormatMacroWithZeroColumnWidth) {
+  FormatStyle ZeroColumn = getLLVMStyleWithColumns(0);
+
+  verifyFormat("#define STRINGIFY(t) #t\n"
+   "#define MAKEVERSIONSTRING(x, y, z, build) STRINGIFY(x) \".\" STRINGIFY(y) \".\" STRINGIFY(z) \".\" STRINGIFY(build)\n",
+   ZeroColumn);
+}
+
 TEST_F(FormatTest, LayoutMacroDefinitionsStatementsSpanningBlocks) {
   verifyFormat("#define A \\\n"
"  f({ \\\n"
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -485,7 +485,8 @@
 // different LineFormatter would be used otherwise.
 if (Previous.ClosesTemplateDeclaration)
   return Style.AlwaysBreakTemplateDeclarations != FormatStyle::BTDS_No;
-if (Previous.is(TT_FunctionAnnotationRParen))
+if (Previous.is(TT_FunctionAnnotationRParen) &&
+State.Line->Type != LT_PreprocessorDirective)
   return true;
 if (Previous.is(TT_LeadingJavaAnnotation) && Current.isNot(tok::l_paren) &&
 Current.isNot(TT_LeadingJavaAnnotation))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116833: [clang][Sema] Introduce support for disabling warnings in system macros

2022-01-08 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 398325.
carlosgalvezp added a comment.

Keep 80 char limit in .td file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116833

Files:
  clang/include/clang/Basic/Diagnostic.td
  clang/include/clang/Basic/DiagnosticAST.h
  clang/include/clang/Basic/DiagnosticAnalysis.h
  clang/include/clang/Basic/DiagnosticComment.h
  clang/include/clang/Basic/DiagnosticCrossTU.h
  clang/include/clang/Basic/DiagnosticDriver.h
  clang/include/clang/Basic/DiagnosticFrontend.h
  clang/include/clang/Basic/DiagnosticIDs.h
  clang/include/clang/Basic/DiagnosticLex.h
  clang/include/clang/Basic/DiagnosticParse.h
  clang/include/clang/Basic/DiagnosticRefactoring.h
  clang/include/clang/Basic/DiagnosticSema.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/DiagnosticSerialization.h
  clang/lib/Basic/DiagnosticIDs.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/warn-sysheader-macro.cpp
  clang/test/TableGen/DiagnosticBase.inc
  clang/test/TableGen/deferred-diag.td
  clang/tools/diagtool/DiagnosticNames.cpp
  clang/utils/TableGen/ClangDiagnosticsEmitter.cpp

Index: clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
===
--- clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -1311,6 +1311,11 @@
 else
   OS << ", false";
 
+if (R.getValueAsBit("ShowInSystemMacro"))
+  OS << ", true";
+else
+  OS << ", false";
+
 if (R.getValueAsBit("Deferrable"))
   OS << ", true";
 else
Index: clang/tools/diagtool/DiagnosticNames.cpp
===
--- clang/tools/diagtool/DiagnosticNames.cpp
+++ clang/tools/diagtool/DiagnosticNames.cpp
@@ -27,9 +27,9 @@
 // FIXME: Is it worth having two tables, especially when this one can get
 // out of sync easily?
 static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
-#define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP,   \
- SFINAE,NOWERROR,SHOWINSYSHEADER,DEFER,CATEGORY)\
-  { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) },
+#define DIAG(ENUM, CLASS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR,  \
+ SHOWINSYSHEADER, SHOWINSYSMACRO, DEFER, CATEGORY) \
+  {#ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t)},
 #include "clang/Basic/DiagnosticCommonKinds.inc"
 #include "clang/Basic/DiagnosticCrossTUKinds.inc"
 #include "clang/Basic/DiagnosticDriverKinds.inc"
Index: clang/test/TableGen/deferred-diag.td
===
--- clang/test/TableGen/deferred-diag.td
+++ clang/test/TableGen/deferred-diag.td
@@ -5,23 +5,23 @@
 // Test usage of Deferrable and NonDeferrable in diagnostics.
 
 def test_default : Error<"This error is non-deferrable by default">;
-// CHECK-DAG: DIAG(test_default, {{.*}}SFINAE_SubstitutionFailure, false, true, false, 0)
+// CHECK-DAG: DIAG(test_default, {{.*}}SFINAE_SubstitutionFailure, false, true, true, false, 0)
 
 def test_deferrable : Error<"This error is deferrable">, Deferrable;
-// CHECK-DAG: DIAG(test_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, true, true, 0)
+// CHECK-DAG: DIAG(test_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, true, true, true, 0)
 
 def test_non_deferrable : Error<"This error is non-deferrable">, NonDeferrable;
-// CHECK-DAG: DIAG(test_non_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, true, false, 0)
+// CHECK-DAG: DIAG(test_non_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, true, true, false, 0)
 
 let Deferrable = 1 in {
 
 def test_let : Error<"This error is deferrable by let">;
-// CHECK-DAG: DIAG(test_let, {{.*}} SFINAE_SubstitutionFailure, false, true, true, 0)
+// CHECK-DAG: DIAG(test_let, {{.*}} SFINAE_SubstitutionFailure, false, true, true, true, 0)
 
 // Make sure TextSubstitution is allowed in the let Deferrable block.
 def textsub : TextSubstitution<"%select{text1|text2}0">;
 
 def test_let2 : Error<"This error is deferrable by let %sub{textsub}0">;
-// CHECK-DAG: DIAG(test_let2, {{.*}} SFINAE_SubstitutionFailure, false, true, true, 0)
+// CHECK-DAG: DIAG(test_let2, {{.*}} SFINAE_SubstitutionFailure, false, true, true, true, 0)
 
-}
\ No newline at end of file
+}
Index: clang/test/TableGen/DiagnosticBase.inc
===
--- clang/test/TableGen/DiagnosticBase.inc
+++ clang/test/TableGen/DiagnosticBase.inc
@@ -76,6 +76,7 @@
   bitAccessControl = 0;
   bitWarningNoWerror = 0;
   bitShowInSystemHeader = 0;
+  bitShowInSystemMacro = 1;
   bitDeferrable = 0;
   Severity   DefaultSeverity = defaultmapping;
   DiagGroup  Group;
@@ -100,6 +101,14 @@
   bit ShowInSystemHeader = 0;
 }
 
+class 

[PATCH] D116833: [clang][Sema] Introduce support for disabling warnings in system macros

2022-01-08 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Updated according to your feedback, let me know what you think! I've run `ninja 
check-clang` successfully, let me know if there's any other test I should run. 
Personally I think this `ShowInSystemMacro` should be OFF by default (to be 
consistent with `ShowInSystemHeader`), but I think this can be done in a 
separate patch if wanted. Otherwise there's ~15 tests to fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116833

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


[PATCH] D116833: [clang][Sema] Introduce support for disabling warnings in system macros

2022-01-08 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 398324.
carlosgalvezp retitled this revision from "[clang][Sema] Disable 
-Wc++20-designator in system macros" to "[clang][Sema] Introduce support for 
disabling warnings in system macros".
carlosgalvezp edited the summary of this revision.
carlosgalvezp added a comment.
Herald added subscribers: usaxena95, arphaman.

Introduce centralized framework for suppressing warnings,
to avoid code duplication for each check.

Clean up the code for -Wshadow and -Wold-style-cast, which
was introduced together with their unit tests in 
https://github.com/llvm/llvm-project/commit/15ab37321cbdb8c38e30cf8bd59bad52f4497580


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116833

Files:
  clang/include/clang/Basic/Diagnostic.td
  clang/include/clang/Basic/DiagnosticAST.h
  clang/include/clang/Basic/DiagnosticAnalysis.h
  clang/include/clang/Basic/DiagnosticComment.h
  clang/include/clang/Basic/DiagnosticCrossTU.h
  clang/include/clang/Basic/DiagnosticDriver.h
  clang/include/clang/Basic/DiagnosticFrontend.h
  clang/include/clang/Basic/DiagnosticIDs.h
  clang/include/clang/Basic/DiagnosticLex.h
  clang/include/clang/Basic/DiagnosticParse.h
  clang/include/clang/Basic/DiagnosticRefactoring.h
  clang/include/clang/Basic/DiagnosticSema.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/DiagnosticSerialization.h
  clang/lib/Basic/DiagnosticIDs.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/warn-sysheader-macro.cpp
  clang/test/TableGen/DiagnosticBase.inc
  clang/test/TableGen/deferred-diag.td
  clang/tools/diagtool/DiagnosticNames.cpp
  clang/utils/TableGen/ClangDiagnosticsEmitter.cpp

Index: clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
===
--- clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -1311,6 +1311,11 @@
 else
   OS << ", false";
 
+if (R.getValueAsBit("ShowInSystemMacro"))
+  OS << ", true";
+else
+  OS << ", false";
+
 if (R.getValueAsBit("Deferrable"))
   OS << ", true";
 else
Index: clang/tools/diagtool/DiagnosticNames.cpp
===
--- clang/tools/diagtool/DiagnosticNames.cpp
+++ clang/tools/diagtool/DiagnosticNames.cpp
@@ -27,9 +27,9 @@
 // FIXME: Is it worth having two tables, especially when this one can get
 // out of sync easily?
 static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
-#define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP,   \
- SFINAE,NOWERROR,SHOWINSYSHEADER,DEFER,CATEGORY)\
-  { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) },
+#define DIAG(ENUM, CLASS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR,  \
+ SHOWINSYSHEADER, SHOWINSYSMACRO, DEFER, CATEGORY) \
+  {#ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t)},
 #include "clang/Basic/DiagnosticCommonKinds.inc"
 #include "clang/Basic/DiagnosticCrossTUKinds.inc"
 #include "clang/Basic/DiagnosticDriverKinds.inc"
Index: clang/test/TableGen/deferred-diag.td
===
--- clang/test/TableGen/deferred-diag.td
+++ clang/test/TableGen/deferred-diag.td
@@ -5,23 +5,23 @@
 // Test usage of Deferrable and NonDeferrable in diagnostics.
 
 def test_default : Error<"This error is non-deferrable by default">;
-// CHECK-DAG: DIAG(test_default, {{.*}}SFINAE_SubstitutionFailure, false, true, false, 0)
+// CHECK-DAG: DIAG(test_default, {{.*}}SFINAE_SubstitutionFailure, false, true, true, false, 0)
 
 def test_deferrable : Error<"This error is deferrable">, Deferrable;
-// CHECK-DAG: DIAG(test_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, true, true, 0)
+// CHECK-DAG: DIAG(test_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, true, true, true, 0)
 
 def test_non_deferrable : Error<"This error is non-deferrable">, NonDeferrable;
-// CHECK-DAG: DIAG(test_non_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, true, false, 0)
+// CHECK-DAG: DIAG(test_non_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, true, true, false, 0)
 
 let Deferrable = 1 in {
 
 def test_let : Error<"This error is deferrable by let">;
-// CHECK-DAG: DIAG(test_let, {{.*}} SFINAE_SubstitutionFailure, false, true, true, 0)
+// CHECK-DAG: DIAG(test_let, {{.*}} SFINAE_SubstitutionFailure, false, true, true, true, 0)
 
 // Make sure TextSubstitution is allowed in the let Deferrable block.
 def textsub : TextSubstitution<"%select{text1|text2}0">;
 
 def test_let2 : Error<"This error is deferrable by let %sub{textsub}0">;
-// CHECK-DAG: DIAG(test_let2, {{.*}} SFINAE_SubstitutionFailure, false, true, true, 0)
+// CHECK-DAG: DIAG(test_let2, {{.*}} SFINAE_SubstitutionFailure, false, true, true, true, 0)
 
-}
\ No newline at end of file
+}
Index: 

[PATCH] D99484: Use `GNUInstallDirs` to support custom installation dirs.

2022-01-08 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 updated this revision to Diff 398318.
Ericson2314 added a comment.

Rebase on top of fixed polly


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99484

Files:
  clang-tools-extra/clang-doc/tool/CMakeLists.txt
  clang-tools-extra/clang-include-fixer/find-all-symbols/tool/CMakeLists.txt
  clang-tools-extra/clang-include-fixer/tool/CMakeLists.txt
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/tool/CMakeLists.txt
  clang-tools-extra/modularize/CMakeLists.txt
  clang/CMakeLists.txt
  clang/cmake/modules/AddClang.cmake
  clang/tools/c-index-test/CMakeLists.txt
  clang/tools/clang-format/CMakeLists.txt
  clang/tools/clang-nvlink-wrapper/CMakeLists.txt
  clang/tools/clang-rename/CMakeLists.txt
  clang/tools/libclang/CMakeLists.txt
  clang/tools/scan-build-py/CMakeLists.txt
  clang/tools/scan-build/CMakeLists.txt
  clang/tools/scan-view/CMakeLists.txt
  clang/utils/hmaptool/CMakeLists.txt
  compiler-rt/cmake/base-config-ix.cmake
  libc/CMakeLists.txt
  libcxx/CMakeLists.txt
  libcxx/cmake/Modules/HandleLibCXXABI.cmake
  libcxxabi/CMakeLists.txt
  libunwind/CMakeLists.txt
  llvm/cmake/modules/LLVMInstallSymlink.cmake
  mlir/CMakeLists.txt
  mlir/cmake/modules/AddMLIR.cmake
  openmp/CMakeLists.txt
  openmp/libompd/src/CMakeLists.txt
  openmp/runtime/src/CMakeLists.txt
  openmp/tools/multiplex/CMakeLists.txt
  polly/CMakeLists.txt
  polly/cmake/CMakeLists.txt
  polly/lib/External/CMakeLists.txt
  pstl/CMakeLists.txt

Index: pstl/CMakeLists.txt
===
--- pstl/CMakeLists.txt
+++ pstl/CMakeLists.txt
@@ -7,6 +7,8 @@
 #===--===##
 cmake_minimum_required(VERSION 3.13.4)
 
+include(GNUInstallDirs)
+
 set(PARALLELSTL_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/include/pstl/internal/pstl_config.h")
 file(STRINGS "${PARALLELSTL_VERSION_FILE}" PARALLELSTL_VERSION_SOURCE REGEX "#define _PSTL_VERSION .*$")
 string(REGEX REPLACE "#define _PSTL_VERSION (.*)$" "\\1" PARALLELSTL_VERSION_SOURCE "${PARALLELSTL_VERSION_SOURCE}")
@@ -90,10 +92,10 @@
   "${CMAKE_CURRENT_BINARY_DIR}/ParallelSTLConfigVersion.cmake"
 DESTINATION lib/cmake/ParallelSTL)
 install(DIRECTORY include/
-DESTINATION include
+DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
 PATTERN "*.in" EXCLUDE)
 install(FILES "${PSTL_CONFIG_SITE_PATH}"
-DESTINATION include)
+DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
 
 add_custom_target(install-pstl
   COMMAND "${CMAKE_COMMAND}" -P "${PROJECT_BINARY_DIR}/cmake_install.cmake" -DCOMPONENT=ParallelSTL)
Index: polly/lib/External/CMakeLists.txt
===
--- polly/lib/External/CMakeLists.txt
+++ polly/lib/External/CMakeLists.txt
@@ -290,7 +290,7 @@
 install(DIRECTORY
   ${ISL_SOURCE_DIR}/include/
   ${ISL_BINARY_DIR}/include/
-  DESTINATION include/polly
+  DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/polly"
   FILES_MATCHING
   PATTERN "*.h"
   PATTERN "CMakeFiles" EXCLUDE
Index: polly/cmake/CMakeLists.txt
===
--- polly/cmake/CMakeLists.txt
+++ polly/cmake/CMakeLists.txt
@@ -1,5 +1,6 @@
 # Keep this in sync with llvm/cmake/CMakeLists.txt!
 
+include(ExtendPath)
 include(FindPrefixFromConfig)
 
 set(LLVM_INSTALL_PACKAGE_DIR "lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
@@ -83,17 +84,18 @@
 # Generate PollyConfig.cmake for the install tree.
 unset(POLLY_EXPORTS)
 find_prefix_from_config(POLLY_CONFIG_CODE POLLY_INSTALL_PREFIX "${POLLY_INSTALL_PACKAGE_DIR}")
-set(POLLY_CONFIG_LLVM_CMAKE_DIR "\${POLLY_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}")
-set(POLLY_CONFIG_CMAKE_DIR "\${POLLY_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}")
-set(POLLY_CONFIG_LIBRARY_DIRS "\${POLLY_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}")
+extend_path(POLLY_CONFIG_LLVM_CMAKE_DIR "\${POLLY_INSTALL_PREFIX}" "${LLVM_INSTALL_PACKAGE_DIR}")
+extend_path(POLLY_CONFIG_CMAKE_DIR "\${POLLY_INSTALL_PREFIX}" "${POLLY_INSTALL_PACKAGE_DIR}")
+extend_path(POLLY_CONFIG_LIBRARY_DIRS "\${POLLY_INSTALL_PREFIX}" "lib${LLVM_LIBDIR_SUFFIX}")
+extend_path(base_includedir "\${POLLY_INSTALL_PREFIX}" "${CMAKE_INSTALL_INCLUDEDIR}")
 if (POLLY_BUNDLED_ISL)
   set(POLLY_CONFIG_INCLUDE_DIRS
-"\${POLLY_INSTALL_PREFIX}/include"
-"\${POLLY_INSTALL_PREFIX}/include/polly"
+"${base_includedir}"
+"${base_includedir}/polly"
 )
 else()
   set(POLLY_CONFIG_INCLUDE_DIRS
-"\${POLLY_INSTALL_PREFIX}/include"
+"${base_includedir}"
 ${ISL_INCLUDE_DIRS}
 )
 endif()
@@ -110,12 +112,12 @@
 foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS)
   get_target_property(tgt_type ${tgt} TYPE)
   if (tgt_type STREQUAL "EXECUTABLE")
-set(tgt_prefix "bin/")
+set(tgt_prefix "${CMAKE_INSTALL_BINDIR}/")
   else()
-

[PATCH] D116856: [docs] Fix documentation of -fno-strict-float-cast-overflow after D115804.

2022-01-08 Thread Nikita Popov via Phabricator via cfe-commits
nikic accepted this revision.
nikic added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116856

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