[PATCH] D123085: CGExprCXX: emit allocptr attributes for operator delete

2022-04-04 Thread Augie Fackler via Phabricator via cfe-commits
durin42 created this revision.
Herald added a project: All.
durin42 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

With this change, we're almost ready to drop the entire table out of
MemoryBuiltins.cpp and rely solely on attributes to detect allocator
functions.

Depends on D123084 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123085

Files:
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/test/CodeGenCXX/cxx1y-sized-deallocation.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
  clang/test/CodeGenCXX/delete-two-arg.cpp
  clang/test/CodeGenCXX/delete.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/microsoft-abi-structors.cpp

STAMPS
actor(@durin42) application(Differential) author(@durin42) herald(H343) 
herald(H423) herald(H576) herald(H678) herald(H864) monogram(D123085) 
object-type(DREV) phid(PHID-DREV-cgee2pk3uj3hbw3hynvx) revision-repository(rG) 
revision-status(needs-review) subscriber(@cfe-commits) tag(#all) tag(#clang) 
via(conduit)

Index: clang/test/CodeGenCXX/microsoft-abi-structors.cpp
===
--- clang/test/CodeGenCXX/microsoft-abi-structors.cpp
+++ clang/test/CodeGenCXX/microsoft-abi-structors.cpp
@@ -57,7 +57,7 @@
 //
 // DTORS:  [[CALL_DELETE_LABEL]]
 // DTORS-NEXT:   %[[THIS_AS_VOID:[0-9a-z]+]] = bitcast %"struct.basic::C"* %[[THIS]] to i8*
-// DTORS-NEXT:   call void @"??3@YAXPAX@Z"(i8* %[[THIS_AS_VOID]])
+// DTORS-NEXT:   call void @"??3@YAXPAX@Z"(i8* allocptr %[[THIS_AS_VOID]])
 // DTORS-NEXT:   br label %[[CONTINUE_LABEL]]
 //
 // DTORS:  [[CONTINUE_LABEL]]
@@ -119,7 +119,7 @@
 // CHECK-NEXT:   %[[PVDTOR:.*]] = getelementptr inbounds i8* (%"struct.basic::C"*, i32)*, i8* (%"struct.basic::C"*, i32)** %[[VTABLE]], i64 0
 // CHECK-NEXT:   %[[VDTOR:.*]] = load i8* (%"struct.basic::C"*, i32)*, i8* (%"struct.basic::C"*, i32)** %[[PVDTOR]]
 // CHECK-NEXT:   %[[CALL:.*]] = call x86_thiscallcc i8* %[[VDTOR]](%"struct.basic::C"* {{[^,]*}} %[[OBJ_PTR_VALUE]], i32 0)
-// CHECK-NEXT:   call void @"??3@YAXPAX@Z"(i8* %[[CALL]])
+// CHECK-NEXT:   call void @"??3@YAXPAX@Z"(i8* allocptr %[[CALL]])
 // CHECK:  ret void
 }
 
Index: clang/test/CodeGenCXX/exceptions.cpp
===
--- clang/test/CodeGenCXX/exceptions.cpp
+++ clang/test/CodeGenCXX/exceptions.cpp
@@ -37,7 +37,7 @@
 // CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
 // CHECK-NEXT: invoke void @_ZN5test11AC1Ei([[A]]* {{[^,]*}} [[CAST]], i32 5)
 // CHECK:  ret [[A]]* [[CAST]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(5);
   }
 
@@ -48,7 +48,7 @@
 // CHECK-NEXT: [[FOO:%.*]] = invoke i32 @_ZN5test13fooEv()
 // CHECK:  invoke void @_ZN5test11AC1Ei([[A]]* {{[^,]*}} [[CAST]], i32 [[FOO]])
 // CHECK:  ret [[A]]* [[CAST]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 extern int foo();
 return new A(foo());
   }
@@ -74,7 +74,7 @@
 // CHECK:  ret [[A]]* [[CAST]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(B().x);
   }
 
@@ -102,7 +102,7 @@
 // CHECK:  ret [[A]]* [[CAST]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(B());
   }
 
@@ -128,7 +128,7 @@
 // CHECK:  ret [[A]]* [[CAST]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(B(), B());
   }
   A *f() {
@@ -165,7 +165,7 @@
 // CHECK:  ret [[A]]* [[RET]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 A *x;
 return (x = new A(makeB()), makeB(), x);
   }
@@ -458,7 +458,7 @@
   }
   // CHECK: define{{.*}} {{%.*}}* @_ZN5test94testEv
   // CHECK: [[TEST9_NEW:%.*]] = call noalias nonnull i8* @_Znam
-  // CHECK: call void @_ZdaPv(i8* [[TEST9_NEW]])
+  // CHECK: call void @_ZdaPv(i8* allocptr [[TEST9_NEW]])
 }
 
 // In a destructor with a function-try-block, a return statement in a
Index: clang/test/CodeGenCXX/delete.cpp
===
--- clang/test/CodeGenCXX/delete.cpp
+++ clang/test/CodeGenCXX/delete.cpp
@@ -100,7 +100,7 @@
 // CHECK-NEXT: c

[PATCH] D119271: clang: emit allocalign to LLVM for alloc_align attributes

2022-04-05 Thread Augie Fackler via Phabricator via cfe-commits
durin42 planned changes to this revision.
durin42 added a comment.

I have some reworking to do on this after my latest round of llvm-side work 
that I'll try and get out later this week.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

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


[PATCH] D123085: CGExprCXX: emit allocptr attributes for operator delete

2022-04-06 Thread Augie Fackler via Phabricator via cfe-commits
durin42 edited the summary of this revision.
durin42 updated this revision to Diff 420854.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123085

Files:
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/test/CodeGenCXX/cxx1y-sized-deallocation.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
  clang/test/CodeGenCXX/delete-two-arg.cpp
  clang/test/CodeGenCXX/delete.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/microsoft-abi-structors.cpp

Index: clang/test/CodeGenCXX/microsoft-abi-structors.cpp
===
--- clang/test/CodeGenCXX/microsoft-abi-structors.cpp
+++ clang/test/CodeGenCXX/microsoft-abi-structors.cpp
@@ -57,7 +57,7 @@
 //
 // DTORS:  [[CALL_DELETE_LABEL]]
 // DTORS-NEXT:   %[[THIS_AS_VOID:[0-9a-z]+]] = bitcast %"struct.basic::C"* %[[THIS]] to i8*
-// DTORS-NEXT:   call void @"??3@YAXPAX@Z"(i8* %[[THIS_AS_VOID]])
+// DTORS-NEXT:   call void @"??3@YAXPAX@Z"(i8* allocptr %[[THIS_AS_VOID]])
 // DTORS-NEXT:   br label %[[CONTINUE_LABEL]]
 //
 // DTORS:  [[CONTINUE_LABEL]]
@@ -119,7 +119,7 @@
 // CHECK-NEXT:   %[[PVDTOR:.*]] = getelementptr inbounds i8* (%"struct.basic::C"*, i32)*, i8* (%"struct.basic::C"*, i32)** %[[VTABLE]], i64 0
 // CHECK-NEXT:   %[[VDTOR:.*]] = load i8* (%"struct.basic::C"*, i32)*, i8* (%"struct.basic::C"*, i32)** %[[PVDTOR]]
 // CHECK-NEXT:   %[[CALL:.*]] = call x86_thiscallcc i8* %[[VDTOR]](%"struct.basic::C"* {{[^,]*}} %[[OBJ_PTR_VALUE]], i32 0)
-// CHECK-NEXT:   call void @"??3@YAXPAX@Z"(i8* %[[CALL]])
+// CHECK-NEXT:   call void @"??3@YAXPAX@Z"(i8* allocptr %[[CALL]])
 // CHECK:  ret void
 }
 
Index: clang/test/CodeGenCXX/exceptions.cpp
===
--- clang/test/CodeGenCXX/exceptions.cpp
+++ clang/test/CodeGenCXX/exceptions.cpp
@@ -37,7 +37,7 @@
 // CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
 // CHECK-NEXT: invoke void @_ZN5test11AC1Ei([[A]]* {{[^,]*}} [[CAST]], i32 5)
 // CHECK:  ret [[A]]* [[CAST]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(5);
   }
 
@@ -48,7 +48,7 @@
 // CHECK-NEXT: [[FOO:%.*]] = invoke i32 @_ZN5test13fooEv()
 // CHECK:  invoke void @_ZN5test11AC1Ei([[A]]* {{[^,]*}} [[CAST]], i32 [[FOO]])
 // CHECK:  ret [[A]]* [[CAST]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 extern int foo();
 return new A(foo());
   }
@@ -74,7 +74,7 @@
 // CHECK:  ret [[A]]* [[CAST]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(B().x);
   }
 
@@ -102,7 +102,7 @@
 // CHECK:  ret [[A]]* [[CAST]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(B());
   }
 
@@ -128,7 +128,7 @@
 // CHECK:  ret [[A]]* [[CAST]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(B(), B());
   }
   A *f() {
@@ -165,7 +165,7 @@
 // CHECK:  ret [[A]]* [[RET]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 A *x;
 return (x = new A(makeB()), makeB(), x);
   }
@@ -458,7 +458,7 @@
   }
   // CHECK: define{{.*}} {{%.*}}* @_ZN5test94testEv
   // CHECK: [[TEST9_NEW:%.*]] = call noalias nonnull i8* @_Znam
-  // CHECK: call void @_ZdaPv(i8* [[TEST9_NEW]])
+  // CHECK: call void @_ZdaPv(i8* allocptr [[TEST9_NEW]])
 }
 
 // In a destructor with a function-try-block, a return statement in a
Index: clang/test/CodeGenCXX/delete.cpp
===
--- clang/test/CodeGenCXX/delete.cpp
+++ clang/test/CodeGenCXX/delete.cpp
@@ -100,7 +100,7 @@
 // CHECK-NEXT: call void @_ZN5test11AD1Ev([[A]]* {{[^,]*}} [[CUR]])
 // CHECK-NEXT: [[ISDONE:%.*]] = icmp eq [[A]]* [[CUR]], [[BEGIN]]
 // CHECK-NEXT: br i1 [[ISDONE]]
-// CHECK:  call void @_ZdaPv(i8* noundef [[ALLOC]])
+// CHECK:  call void @_ZdaPv(i8* allocptr noundef [[ALLOC]])
   }
 }
 
@@ -146,7 +146,7 @@
 // CHECK-NEXT: [[DTOR:%.*]] = load void ([[X]]*)*, void ([[X]]*)** [[T0]]
 // CHECK-NEXT: call void [[DTOR]]([[X]]* {{[^,]*}} [[OBJ:%.*]])
 //   Call the global operator delete.
-// CHECK-NEXT: call void @_Z

[PATCH] D123085: CGExprCXX: emit allocptr attributes for operator delete

2022-04-06 Thread Augie Fackler via Phabricator via cfe-commits
durin42 updated this revision to Diff 420915.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123085

Files:
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/test/CodeGenCXX/cxx1y-sized-deallocation.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
  clang/test/CodeGenCXX/delete-two-arg.cpp
  clang/test/CodeGenCXX/delete.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/microsoft-abi-structors.cpp

Index: clang/test/CodeGenCXX/microsoft-abi-structors.cpp
===
--- clang/test/CodeGenCXX/microsoft-abi-structors.cpp
+++ clang/test/CodeGenCXX/microsoft-abi-structors.cpp
@@ -57,7 +57,7 @@
 //
 // DTORS:  [[CALL_DELETE_LABEL]]
 // DTORS-NEXT:   %[[THIS_AS_VOID:[0-9a-z]+]] = bitcast %"struct.basic::C"* %[[THIS]] to i8*
-// DTORS-NEXT:   call void @"??3@YAXPAX@Z"(i8* %[[THIS_AS_VOID]])
+// DTORS-NEXT:   call void @"??3@YAXPAX@Z"(i8* allocptr %[[THIS_AS_VOID]])
 // DTORS-NEXT:   br label %[[CONTINUE_LABEL]]
 //
 // DTORS:  [[CONTINUE_LABEL]]
@@ -119,7 +119,7 @@
 // CHECK-NEXT:   %[[PVDTOR:.*]] = getelementptr inbounds i8* (%"struct.basic::C"*, i32)*, i8* (%"struct.basic::C"*, i32)** %[[VTABLE]], i64 0
 // CHECK-NEXT:   %[[VDTOR:.*]] = load i8* (%"struct.basic::C"*, i32)*, i8* (%"struct.basic::C"*, i32)** %[[PVDTOR]]
 // CHECK-NEXT:   %[[CALL:.*]] = call x86_thiscallcc i8* %[[VDTOR]](%"struct.basic::C"* {{[^,]*}} %[[OBJ_PTR_VALUE]], i32 0)
-// CHECK-NEXT:   call void @"??3@YAXPAX@Z"(i8* %[[CALL]])
+// CHECK-NEXT:   call void @"??3@YAXPAX@Z"(i8* allocptr %[[CALL]])
 // CHECK:  ret void
 }
 
Index: clang/test/CodeGenCXX/exceptions.cpp
===
--- clang/test/CodeGenCXX/exceptions.cpp
+++ clang/test/CodeGenCXX/exceptions.cpp
@@ -37,7 +37,7 @@
 // CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
 // CHECK-NEXT: invoke void @_ZN5test11AC1Ei([[A]]* {{[^,]*}} [[CAST]], i32 5)
 // CHECK:  ret [[A]]* [[CAST]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(5);
   }
 
@@ -48,7 +48,7 @@
 // CHECK-NEXT: [[FOO:%.*]] = invoke i32 @_ZN5test13fooEv()
 // CHECK:  invoke void @_ZN5test11AC1Ei([[A]]* {{[^,]*}} [[CAST]], i32 [[FOO]])
 // CHECK:  ret [[A]]* [[CAST]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 extern int foo();
 return new A(foo());
   }
@@ -74,7 +74,7 @@
 // CHECK:  ret [[A]]* [[CAST]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(B().x);
   }
 
@@ -102,7 +102,7 @@
 // CHECK:  ret [[A]]* [[CAST]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(B());
   }
 
@@ -128,7 +128,7 @@
 // CHECK:  ret [[A]]* [[CAST]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(B(), B());
   }
   A *f() {
@@ -165,7 +165,7 @@
 // CHECK:  ret [[A]]* [[RET]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 A *x;
 return (x = new A(makeB()), makeB(), x);
   }
@@ -458,7 +458,7 @@
   }
   // CHECK: define{{.*}} {{%.*}}* @_ZN5test94testEv
   // CHECK: [[TEST9_NEW:%.*]] = call noalias nonnull i8* @_Znam
-  // CHECK: call void @_ZdaPv(i8* [[TEST9_NEW]])
+  // CHECK: call void @_ZdaPv(i8* allocptr [[TEST9_NEW]])
 }
 
 // In a destructor with a function-try-block, a return statement in a
Index: clang/test/CodeGenCXX/delete.cpp
===
--- clang/test/CodeGenCXX/delete.cpp
+++ clang/test/CodeGenCXX/delete.cpp
@@ -100,7 +100,7 @@
 // CHECK-NEXT: call void @_ZN5test11AD1Ev([[A]]* {{[^,]*}} [[CUR]])
 // CHECK-NEXT: [[ISDONE:%.*]] = icmp eq [[A]]* [[CUR]], [[BEGIN]]
 // CHECK-NEXT: br i1 [[ISDONE]]
-// CHECK:  call void @_ZdaPv(i8* noundef [[ALLOC]])
+// CHECK:  call void @_ZdaPv(i8* allocptr noundef [[ALLOC]])
   }
 }
 
@@ -146,7 +146,7 @@
 // CHECK-NEXT: [[DTOR:%.*]] = load void ([[X]]*)*, void ([[X]]*)** [[T0]]
 // CHECK-NEXT: call void [[DTOR]]([[X]]* {{[^,]*}} [[OBJ:%.*]])
 //   Call the global operator delete.
-// CHECK-NEXT: call void @_ZdlPv(i8* noundef [[ALLOCATED]]) [[NUW:#[0-9]+

[PATCH] D123085: CGExprCXX: emit allocptr attributes for operator delete

2022-04-06 Thread Augie Fackler via Phabricator via cfe-commits
durin42 planned changes to this revision.
durin42 added a comment.

I'll hold off on this one until the other LLVM patches are done, then mail out 
the clang work as its own logical unit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123085

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


[PATCH] D121629: clang: also check alloc_alignment claims in return

2022-03-14 Thread Augie Fackler via Phabricator via cfe-commits
durin42 created this revision.
Herald added a project: All.
durin42 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Prior to this patch, we only check alloc_alignment claims in the caller.
I'm about to add some extra logic that threads alloc_alignment
information down into LLVM, which would then have a chance to defeat the
sanitizer checks by performing optimizations. To avoid that, we also
check alignment claims in the called function prior to return.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121629

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp

Index: clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
===
--- clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
+++ clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
@@ -8,15 +8,38 @@
 
 char **__attribute__((alloc_align(2)))
 passthrough(char **x, unsigned long alignment) {
-  // CHECK:  define{{.*}} i8** @[[PASSTHROUGH:.*]](i8** noundef %[[X:.*]], i64 noundef %[[ALIGNMENT:.*]])
-  // CHECK-NEXT: entry:
-  // CHECK-NEXT:   %[[X_ADDR:.*]] = alloca i8**, align 8
-  // CHECK-NEXT:   %[[ALIGNMENT_ADDR:.*]] = alloca i64, align 8
-  // CHECK-NEXT:   store i8** %[[X]], i8*** %[[X_ADDR]], align 8
-  // CHECK-NEXT:   store i64 %[[ALIGNMENT]], i64* %[[ALIGNMENT_ADDR]], align 8
-  // CHECK-NEXT:   %[[X_RELOADED:.*]] = load i8**, i8*** %[[X_ADDR]], align 8
-  // CHECK-NEXT:   ret i8** %[[X_RELOADED]]
-  // CHECK-NEXT: }
+  // CHECK:define{{.*}} i8** @[[PASSTHROUGH:.*]](i8** noundef %[[X:.*]], i64 noundef %[[ALIGNMENT:.*]])
+  // CHECK-NEXT:   entry:
+  // CHECK-SANITIZE-NEXT:%return.sloc.ptr = alloca i8*, align 8
+  // CHECK-NEXT: %[[X_ADDR:.*]] = alloca i8**, align 8
+  // CHECK-NEXT: %[[ALIGNMENT_ADDR:.*]] = alloca i64, align 8
+  // CHECK-SANITIZE-NEXT:store i8* null, i8** %return.sloc.ptr, align 8
+  // CHECK-NEXT: store i8** %[[X]], i8*** %[[X_ADDR]], align 8
+  // CHECK-NEXT: store i64 %[[ALIGNMENT]], i64* %[[ALIGNMENT_ADDR]], align 8
+  // CHECK-SANITIZE-NEXT:store i8* bitcast ({ [151 x i8]*, i32, i32 }* @0 to i8*), i8** %return.sloc.ptr, align 8
+  // CHECK-NEXT: %[[X_RELOADED:.*]] = load i8**, i8*** %[[X_ADDR]], align 8
+  // CHECK-SANITIZE-NEXT:%ptrint = ptrtoint i8** %0 to i64
+  // CHECK-SANITIZE-NEXT:%1 = sub i64 %alignment, 1
+  // CHECK-SANITIZE-NEXT:%maskedptr = and i64 %ptrint, %1
+  // CHECK-SANITIZE-NEXT:%maskcond = icmp eq i64 %maskedptr, 0
+  // CHECK-SANITIZE-NEXT:%2 = ptrtoint i8** %0 to i64, !nosanitize !2
+  // CHECK-SANITIZE-ANYRECOVER-NEXT: br i1 %maskcond, label %cont, label %handler.alignment_assumption, !prof !3, !nosanitize !2
+  // CHECK-SANITIZE-TRAP-NEXT:   br i1 %maskcond, label %cont, label %trap, !nosanitize !2
+
+  // CHECK-SANITIZE-ANYRECOVER:handler.alignment_assumption:
+  // CHECK-SANITIZE-NORECOVER-NEXT:  call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ { [151 x i8]*, i32, i32 }, { [151 x i8]*, i32, i32 }, { i16, i16, [10 x i8] }* }* @2 to i8*), i64 %2, i64 %alignment, i64 0) #3, !nosanitize !2
+  // CHECK-SANITIZE-NORECOVER-NEXT:  unreachable, !nosanitize !2
+  // CHECK-SANITIZE-RECOVER-NEXT:call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ { [151 x i8]*, i32, i32 }, { [151 x i8]*, i32, i32 }, { i16, i16, [10 x i8] }* }* @2 to i8*), i64 %2, i64 %alignment, i64 0) #3, !nosanitize !2
+  // CHECK-SANITIZE-RECOVER-NEXT:br label %cont, !nosanitize !2
+
+  // CHECK-SANITIZE-TRAP:  trap:
+  // CHECK-SANITIZE-TRAP-NEXT:   call void @llvm.ubsantrap(i8 23) #3, !nosanitize !2
+  // CHECK-SANITIZE-TRAP-NEXT:   unreachable, !nosanitize !2
+
+  // CHECK-SANITIZE:   cont:
+  // CHECK-SANITIZE-NEXT:call void @llvm.assume(i1 true) [ "align"(i8** %[[X_RELOADED]], i64 %[[ALIGNMENT]]) ]
+  // CHECK-NEXT: ret i8** %[[X_RELOADED]]
+  // CHECK-NEXT:   }
   return x;
 }
 
Index: clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
===
--- clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
+++ clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cp

[PATCH] D121629: clang: also check alloc_alignment claims in return

2022-03-14 Thread Augie Fackler via Phabricator via cfe-commits
durin42 added a comment.

In D121629#3380175 , @lebedev.ri 
wrote:

> Please can you pose the next patch itself?
> I suspect that propagation should simply not be done when sanitizer is 
> enabled.

I'm working on the next patch. Sadly we can't omit `allocalign`s into the IR 
layer when sanitizers are enabled because nothing will (when I'm done cleaning 
up MemoryBuiltins.cpp) have a way to know anything about the alignment of 
returned pointers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121629

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


[PATCH] D121629: clang: also check alloc_alignment claims in return

2022-03-14 Thread Augie Fackler via Phabricator via cfe-commits
durin42 updated this revision to Diff 415226.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121629

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp

Index: clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
===
--- clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
+++ clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
@@ -8,15 +8,38 @@
 
 char **__attribute__((alloc_align(2)))
 passthrough(char **x, unsigned long alignment) {
-  // CHECK:  define{{.*}} i8** @[[PASSTHROUGH:.*]](i8** noundef %[[X:.*]], i64 noundef %[[ALIGNMENT:.*]])
-  // CHECK-NEXT: entry:
-  // CHECK-NEXT:   %[[X_ADDR:.*]] = alloca i8**, align 8
-  // CHECK-NEXT:   %[[ALIGNMENT_ADDR:.*]] = alloca i64, align 8
-  // CHECK-NEXT:   store i8** %[[X]], i8*** %[[X_ADDR]], align 8
-  // CHECK-NEXT:   store i64 %[[ALIGNMENT]], i64* %[[ALIGNMENT_ADDR]], align 8
-  // CHECK-NEXT:   %[[X_RELOADED:.*]] = load i8**, i8*** %[[X_ADDR]], align 8
-  // CHECK-NEXT:   ret i8** %[[X_RELOADED]]
-  // CHECK-NEXT: }
+  // CHECK:define{{.*}} i8** @[[PASSTHROUGH:.*]](i8** noundef %[[X:.*]], i64 noundef %[[ALIGNMENT:.*]])
+  // CHECK-NEXT:   entry:
+  // CHECK-SANITIZE-NEXT:%return.sloc.ptr = alloca i8*, align 8
+  // CHECK-NEXT: %[[X_ADDR:.*]] = alloca i8**, align 8
+  // CHECK-NEXT: %[[ALIGNMENT_ADDR:.*]] = alloca i64, align 8
+  // CHECK-SANITIZE-NEXT:store i8* null, i8** %return.sloc.ptr, align 8
+  // CHECK-NEXT: store i8** %[[X]], i8*** %[[X_ADDR]], align 8
+  // CHECK-NEXT: store i64 %[[ALIGNMENT]], i64* %[[ALIGNMENT_ADDR]], align 8
+  // CHECK-SANITIZE-NEXT:store i8* bitcast ({ [151 x i8]*, i32, i32 }* @0 to i8*), i8** %return.sloc.ptr, align 8
+  // CHECK-NEXT: %[[X_RELOADED:.*]] = load i8**, i8*** %[[X_ADDR]], align 8
+  // CHECK-SANITIZE-NEXT:%ptrint = ptrtoint i8** %0 to i64
+  // CHECK-SANITIZE-NEXT:%1 = sub i64 %alignment, 1
+  // CHECK-SANITIZE-NEXT:%maskedptr = and i64 %ptrint, %1
+  // CHECK-SANITIZE-NEXT:%maskcond = icmp eq i64 %maskedptr, 0
+  // CHECK-SANITIZE-NEXT:%2 = ptrtoint i8** %0 to i64, !nosanitize !2
+  // CHECK-SANITIZE-ANYRECOVER-NEXT: br i1 %maskcond, label %cont, label %handler.alignment_assumption, !prof !3, !nosanitize !2
+  // CHECK-SANITIZE-TRAP-NEXT:   br i1 %maskcond, label %cont, label %trap, !nosanitize !2
+
+  // CHECK-SANITIZE-ANYRECOVER:handler.alignment_assumption:
+  // CHECK-SANITIZE-NORECOVER-NEXT:  call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ { [151 x i8]*, i32, i32 }, { [151 x i8]*, i32, i32 }, { i16, i16, [10 x i8] }* }* @2 to i8*), i64 %2, i64 %alignment, i64 0) #3, !nosanitize !2
+  // CHECK-SANITIZE-NORECOVER-NEXT:  unreachable, !nosanitize !2
+  // CHECK-SANITIZE-RECOVER-NEXT:call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ { [151 x i8]*, i32, i32 }, { [151 x i8]*, i32, i32 }, { i16, i16, [10 x i8] }* }* @2 to i8*), i64 %2, i64 %alignment, i64 0) #3, !nosanitize !2
+  // CHECK-SANITIZE-RECOVER-NEXT:br label %cont, !nosanitize !2
+
+  // CHECK-SANITIZE-TRAP:  trap:
+  // CHECK-SANITIZE-TRAP-NEXT:   call void @llvm.ubsantrap(i8 23) #3, !nosanitize !2
+  // CHECK-SANITIZE-TRAP-NEXT:   unreachable, !nosanitize !2
+
+  // CHECK-SANITIZE:   cont:
+  // CHECK-SANITIZE-NEXT:call void @llvm.assume(i1 true) [ "align"(i8** %[[X_RELOADED]], i64 %[[ALIGNMENT]]) ]
+  // CHECK-NEXT: ret i8** %[[X_RELOADED]]
+  // CHECK-NEXT:   }
   return x;
 }
 
Index: clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
===
--- clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
+++ clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
@@ -8,15 +8,37 @@
 
 char **__attribute__((alloc_align(2)))
 passthrough(char **x, unsigned long alignment) {
-  // CHECK:  define{{.*}} i8** @[[PASSTHROUGH:.*]](i8** noundef %[[X:.*]], i64 noundef %[[ALIGNMENT:.*]])
-  // CHECK-NEXT: entry:
-  // CHECK-NEXT:   %[[X_ADDR:.*]] = alloca i8**, align 8
-  // CHECK-NEXT:   %[[ALIGNMENT_ADDR:.*]] = alloca i64, align 8
-  // CHECK-NEXT:   store i8** %[

[PATCH] D119271: clang: emit allocalign to LLVM for alloc_align attributes

2022-03-14 Thread Augie Fackler via Phabricator via cfe-commits
durin42 retitled this revision from "CGCall: also emit LLVM `allocalign` 
attribute when handling AllocAlign" to "clang: emit allocalign to LLVM for 
alloc_align attributes".
durin42 edited the summary of this revision.
durin42 updated this revision to Diff 415230.
Herald added a project: All.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/alloc-align-attr.c
  clang/test/CodeGen/alloc-fns-alignment.c
  clang/test/CodeGen/assume-aligned-and-alloc-align-attributes.c
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
  clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
  clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp

Index: clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
===
--- clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
+++ clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
@@ -27,10 +27,10 @@
 struct OVERALIGNED A { A(); int n[128]; };
 
 // CHECK-LABEL: define {{.*}} @_Z2a0v()
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a0@@YAPEAXXZ"()
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK-MS: cleanuppad
 // CHECK-MS: call void @"??3@YAXPEAXW4align_val_t@std@@@Z"(i8* noundef %[[ALLOC]], i64 noundef 32)
 void *a0() { return new A; }
@@ -39,13 +39,13 @@
 // The size is known.
 //
 // CHECK-LABEL: define {{.*}} @_Z2a1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1AC1Ev(
 // CHECK: call void @_ZdaPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a1@@YAPEAXJ@Z"(
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-MS-NOT: store
 // CHECK-MS: invoke noundef %struct.A* @"??0A@@QEAA@XZ"(
@@ -84,7 +84,7 @@
 void *b0() { return new B; }
 
 // CHECK-LABEL: define {{.*}} @_Z2b1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1BC1Ev(
@@ -169,7 +169,7 @@
 
 #ifndef UNALIGNED
 // CHECK-LABEL: define {{.*}} @_Z2e0v(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 4)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 4)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 4)
 void *e0() { return new (std::align_val_t(4)) A; }
 
Index: clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
===
--- clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
+++ clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
@@ -47,7 +47,7 @@
 
 // CHECK-LABEL: define{{.*}} void @test_aligned_alloc(
 extern "C" void test_aligned_alloc() {
-  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
+  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 allocalign noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
   // CHECK: call void @_ZdlPvSt11align_val_t({{.*}}, i64 noundef 4) [[ATTR_BUILTIN_DELETE:#[^ ]*]]
   __builtin_operator_delete(__builtin_operator_new(4, std::align_val_t(4)), std::align_val_t(4));
 }
Index: clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
=

[PATCH] D121629: clang: also check alloc_alignment claims in return

2022-03-14 Thread Augie Fackler via Phabricator via cfe-commits
durin42 added a comment.

In D121629#3380191 , @durin42 wrote:

> In D121629#3380175 , @lebedev.ri 
> wrote:
>
>> Please can you pose the next patch itself?
>> I suspect that propagation should simply not be done when sanitizer is 
>> enabled.
>
> I'm working on the next patch. Sadly we can't omit `allocalign`s into the IR 
> layer when sanitizers are enabled because nothing will (when I'm done 
> cleaning up MemoryBuiltins.cpp) have a way to know anything about the 
> alignment of returned pointers.

The rest of the stack is now implemented and uploaded.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121629

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


[PATCH] D119271: clang: emit allocalign to LLVM for alloc_align attributes

2022-03-14 Thread Augie Fackler via Phabricator via cfe-commits
durin42 added inline comments.



Comment at: 
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp:55
   // CHECK-NEXT:%[[ALIGNMENT_RELOADED:.*]] = load i64, 
i64* %[[ALIGNMENT_ADDR]], align 8
-  // CHECK-NEXT:%[[X_RETURNED:.*]] = call noundef i8** 
@[[PASSTHROUGH]](i8** noundef %[[X_RELOADED]], i64 noundef 
%[[ALIGNMENT_RELOADED]])
-  // CHECK-SANITIZE-NEXT:   %[[PTRINT:.*]] = ptrtoint i8** 
%[[X_RETURNED]] to i64
-  // CHECK-SANITIZE-NEXT:   %[[MASK:.*]] = sub i64 
%[[ALIGNMENT_RELOADED]], 1
-  // CHECK-SANITIZE-NEXT:   %[[MASKEDPTR:.*]] = and i64 
%[[PTRINT]], %[[MASK]]
-  // CHECK-SANITIZE-NEXT:   %[[MASKCOND:.*]] = icmp eq i64 
%[[MASKEDPTR]], 0
-  // CHECK-SANITIZE-NEXT:   %[[PTRINT_DUP:.*]] = ptrtoint i8** 
%[[X_RETURNED]] to i64, !nosanitize
-  // CHECK-SANITIZE-NEXT:   br i1 %[[MASKCOND]], label 
%[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
-  // CHECK-SANITIZE:  [[HANDLER_ALIGNMENT_ASSUMPTION]]:
-  // CHECK-SANITIZE-NORECOVER-NEXT: call void 
@__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, 
{{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], 
i64 %[[ALIGNMENT_RELOADED]], i64 0){{.*}}, !nosanitize
-  // CHECK-SANITIZE-RECOVER-NEXT:   call void 
@__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, 
{{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], 
i64 %[[ALIGNMENT_RELOADED]], i64 0){{.*}}, !nosanitize
-  // CHECK-SANITIZE-TRAP-NEXT:  call void @llvm.ubsantrap(i8 
23){{.*}}, !nosanitize
-  // CHECK-SANITIZE-UNREACHABLE-NEXT:   unreachable, !nosanitize
-  // CHECK-SANITIZE:  [[CONT]]:
-  // CHECK-NEXT:call void @llvm.assume(i1 true) [ 
"align"(i8** %[[X_RETURNED]], i64 %1) ]
+  // CHECK-NEXT:%[[X_RETURNED:.*]] = call noundef i8** 
@[[PASSTHROUGH]](i8** noundef %[[X_RELOADED]], i64 allocalign noundef 
%[[ALIGNMENT_RELOADED]])
   // CHECK-NEXT:ret i8** %[[X_RETURNED]]

lebedev.ri wrote:
> This is a regression, the old behavior was correct.
I don't think so: we now (as of D121629) check the alignment of the returned 
pointer in the callee instead of the caller, and LLVM knows about allocalign 
implying an alignment at the callsite. So I think it's correctly optimizing 
away the sanitizer checks here.

You or @jyknight will need to correct me if my understanding is incorrect here, 
but my understanding was that this change was what motivated D121629 in the 
first place.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

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


[PATCH] D119271: clang: emit allocalign to LLVM for alloc_align attributes

2022-03-14 Thread Augie Fackler via Phabricator via cfe-commits
durin42 added inline comments.



Comment at: 
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp:55
   // CHECK-NEXT:%[[ALIGNMENT_RELOADED:.*]] = load i64, 
i64* %[[ALIGNMENT_ADDR]], align 8
-  // CHECK-NEXT:%[[X_RETURNED:.*]] = call noundef i8** 
@[[PASSTHROUGH]](i8** noundef %[[X_RELOADED]], i64 noundef 
%[[ALIGNMENT_RELOADED]])
-  // CHECK-SANITIZE-NEXT:   %[[PTRINT:.*]] = ptrtoint i8** 
%[[X_RETURNED]] to i64
-  // CHECK-SANITIZE-NEXT:   %[[MASK:.*]] = sub i64 
%[[ALIGNMENT_RELOADED]], 1
-  // CHECK-SANITIZE-NEXT:   %[[MASKEDPTR:.*]] = and i64 
%[[PTRINT]], %[[MASK]]
-  // CHECK-SANITIZE-NEXT:   %[[MASKCOND:.*]] = icmp eq i64 
%[[MASKEDPTR]], 0
-  // CHECK-SANITIZE-NEXT:   %[[PTRINT_DUP:.*]] = ptrtoint i8** 
%[[X_RETURNED]] to i64, !nosanitize
-  // CHECK-SANITIZE-NEXT:   br i1 %[[MASKCOND]], label 
%[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
-  // CHECK-SANITIZE:  [[HANDLER_ALIGNMENT_ASSUMPTION]]:
-  // CHECK-SANITIZE-NORECOVER-NEXT: call void 
@__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, 
{{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], 
i64 %[[ALIGNMENT_RELOADED]], i64 0){{.*}}, !nosanitize
-  // CHECK-SANITIZE-RECOVER-NEXT:   call void 
@__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, 
{{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], 
i64 %[[ALIGNMENT_RELOADED]], i64 0){{.*}}, !nosanitize
-  // CHECK-SANITIZE-TRAP-NEXT:  call void @llvm.ubsantrap(i8 
23){{.*}}, !nosanitize
-  // CHECK-SANITIZE-UNREACHABLE-NEXT:   unreachable, !nosanitize
-  // CHECK-SANITIZE:  [[CONT]]:
-  // CHECK-NEXT:call void @llvm.assume(i1 true) [ 
"align"(i8** %[[X_RETURNED]], i64 %1) ]
+  // CHECK-NEXT:%[[X_RETURNED:.*]] = call noundef i8** 
@[[PASSTHROUGH]](i8** noundef %[[X_RELOADED]], i64 allocalign noundef 
%[[ALIGNMENT_RELOADED]])
   // CHECK-NEXT:ret i8** %[[X_RETURNED]]

lebedev.ri wrote:
> durin42 wrote:
> > lebedev.ri wrote:
> > > This is a regression, the old behavior was correct.
> > I don't think so: we now (as of D121629) check the alignment of the 
> > returned pointer in the callee instead of the caller, and LLVM knows about 
> > allocalign implying an alignment at the callsite. So I think it's correctly 
> > optimizing away the sanitizer checks here.
> > 
> > You or @jyknight will need to correct me if my understanding is incorrect 
> > here, but my understanding was that this change was what motivated D121629 
> > in the first place.
> I'm saying that as the author of said test and it's behavior.
How is this wrong though? Are you concerned because the `allocalign` isn't 
being asserted upon by the sanitizer in the caller? How this a problem given 
that the callee code now does the assertions in sanitizer mode?

(If I'm not understanding please elaborate: this is my first nontrivial work on 
LLVM, so I'm going to need more than "I wrote this, and you are wrong" by way 
of help understanding my error.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

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


[PATCH] D119271: CGCall: also emit LLVM `allocalign` attribute when handling AllocAlign

2022-02-08 Thread Augie Fackler via Phabricator via cfe-commits
durin42 created this revision.
Herald added a subscriber: jdoerfert.
durin42 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

LLVM is growing knowledge of this, so we should inform it when we have
the information available.

Depends on D118263 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119271

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/alloc-align-attr.c
  clang/test/CodeGen/alloc-fns-alignment.c
  clang/test/CodeGen/assume-aligned-and-alloc-align-attributes.c
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
  clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
  clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp

Index: clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
===
--- clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
+++ clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
@@ -27,10 +27,10 @@
 struct OVERALIGNED A { A(); int n[128]; };
 
 // CHECK-LABEL: define {{.*}} @_Z2a0v()
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a0@@YAPEAXXZ"()
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK-MS: cleanuppad
 // CHECK-MS: call void @"??3@YAXPEAXW4align_val_t@std@@@Z"(i8* noundef %[[ALLOC]], i64 noundef 32)
 void *a0() { return new A; }
@@ -39,13 +39,13 @@
 // The size is known.
 //
 // CHECK-LABEL: define {{.*}} @_Z2a1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1AC1Ev(
 // CHECK: call void @_ZdaPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a1@@YAPEAXJ@Z"(
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-MS-NOT: store
 // CHECK-MS: invoke noundef %struct.A* @"??0A@@QEAA@XZ"(
@@ -84,7 +84,7 @@
 void *b0() { return new B; }
 
 // CHECK-LABEL: define {{.*}} @_Z2b1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1BC1Ev(
@@ -169,7 +169,7 @@
 
 #ifndef UNALIGNED
 // CHECK-LABEL: define {{.*}} @_Z2e0v(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 4)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 4)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 4)
 void *e0() { return new (std::align_val_t(4)) A; }
 
Index: clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
===
--- clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
+++ clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
@@ -47,7 +47,7 @@
 
 // CHECK-LABEL: define{{.*}} void @test_aligned_alloc(
 extern "C" void test_aligned_alloc() {
-  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
+  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 allocalign noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
   // CHECK: call void @_ZdlPvSt11align_val_t({{.*}}, i64 noundef 4) [[ATTR_BUILTIN_DELETE:#[^ ]*]]
   __builtin_operator_delete(__builtin_operator_new(4, std::align_val_t(4)), std::align_val_t(4));
 }
Index: clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
===
-

[PATCH] D119271: CGCall: also emit LLVM `allocalign` attribute when handling AllocAlign

2022-02-10 Thread Augie Fackler via Phabricator via cfe-commits
durin42 added inline comments.



Comment at: clang/test/CodeGen/alloc-align-attr.c:14
 // CHECK-NEXT:[[CASTED_ALIGN:%.*]] = zext i32 [[TMP0]] to i64
 // CHECK-NEXT:call void @llvm.assume(i1 true) [ "align"(i32* [[CALL]], i64 
[[CASTED_ALIGN]]) ]
 // CHECK-NEXT:[[TMP1:%.*]] = load i32, i32* [[CALL]], align 4

xbolva00 wrote:
> now this llvm.assume is redudant and should be removed?
I don't think so? Right now allocalign doesn't mean a whole lot (it really just 
answers some questions that used to be inferred from function name by 
MemoryBuiltins.cpp) so I'd rather leave the llvm.assume given that I doubt it's 
hurting anyone?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

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


[PATCH] D119271: CGCall: also emit LLVM `allocalign` attribute when handling AllocAlign

2022-02-11 Thread Augie Fackler via Phabricator via cfe-commits
durin42 added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:4605
+  TryEmitAsCallSiteAttribute(const llvm::AttributeList &Attrs) {
+llvm::AttributeList NewAttrs = Attrs;
+if (AA)

jyknight wrote:
> We do need to fallback to an assume for 
> "if(CGF.SanOpts.has(SanitizerKind::Alignment)" however -- and NOT emit an 
> allocalign (nor an align) attribute in that case.
> 
> This is necessary so that clang can emit explicit misalignment checks FIRST 
> (and abort with a message if they fail), before letting LLVM assume the 
> specified alignment. In order for the ubsan alignment check to work properly, 
> we need to not trigger misalignment-UB before the check executes! 
> 
> See 
> clang/test/CodeGen/catch-alignment-assumption-attribute-assume_aligned-on-function.cpp
>  -- note how in the sanitized mode, it doesn't have an the "align 128" on the 
> call result, but instead emits a bunch of code to test alignment, and branch 
> to an ubsan abort on failure -- followed by the llvm.assume only on the 
> successful branch. Although the test-case is only testing assume_aligned, the 
> same behavior should be applicable to allocalign.
> 
> (Which shows that we clearly need a sanitized allocalign test-case, too)
It sounds like (between this comment and the one below) I should just abandon 
the code-sharing between AllocAlignAttrEmitter and AssumeAlignedAttrEmitter - 
is that right?

Also, should I be making a new test case or adding to an existing one for a 
sanitized allocalign test case? Is that an llvm-level thing or a clang-level 
thing?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

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


[PATCH] D119271: CGCall: also emit LLVM `allocalign` attribute when handling AllocAlign

2022-02-11 Thread Augie Fackler via Phabricator via cfe-commits
durin42 edited the summary of this revision.
durin42 updated this revision to Diff 408019.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/alloc-align-attr.c
  clang/test/CodeGen/alloc-fns-alignment.c
  clang/test/CodeGen/assume-aligned-and-alloc-align-attributes.c
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
  clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
  clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp

Index: clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
===
--- clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
+++ clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
@@ -27,10 +27,10 @@
 struct OVERALIGNED A { A(); int n[128]; };
 
 // CHECK-LABEL: define {{.*}} @_Z2a0v()
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a0@@YAPEAXXZ"()
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK-MS: cleanuppad
 // CHECK-MS: call void @"??3@YAXPEAXW4align_val_t@std@@@Z"(i8* noundef %[[ALLOC]], i64 noundef 32)
 void *a0() { return new A; }
@@ -39,13 +39,13 @@
 // The size is known.
 //
 // CHECK-LABEL: define {{.*}} @_Z2a1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1AC1Ev(
 // CHECK: call void @_ZdaPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a1@@YAPEAXJ@Z"(
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-MS-NOT: store
 // CHECK-MS: invoke noundef %struct.A* @"??0A@@QEAA@XZ"(
@@ -84,7 +84,7 @@
 void *b0() { return new B; }
 
 // CHECK-LABEL: define {{.*}} @_Z2b1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1BC1Ev(
@@ -169,7 +169,7 @@
 
 #ifndef UNALIGNED
 // CHECK-LABEL: define {{.*}} @_Z2e0v(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 4)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 4)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 4)
 void *e0() { return new (std::align_val_t(4)) A; }
 
Index: clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
===
--- clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
+++ clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
@@ -47,7 +47,7 @@
 
 // CHECK-LABEL: define{{.*}} void @test_aligned_alloc(
 extern "C" void test_aligned_alloc() {
-  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
+  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 allocalign noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
   // CHECK: call void @_ZdlPvSt11align_val_t({{.*}}, i64 noundef 4) [[ATTR_BUILTIN_DELETE:#[^ ]*]]
   __builtin_operator_delete(__builtin_operator_new(4, std::align_val_t(4)), std::align_val_t(4));
 }
Index: clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
===
--- clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
+++ clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
@@ -8,7 +8,7 @@
 // CHECK-NEXT:[[ALIGN_ADDR:%.*]] = a

[PATCH] D119271: CGCall: also emit LLVM `allocalign` attribute when handling AllocAlign

2022-02-11 Thread Augie Fackler via Phabricator via cfe-commits
durin42 updated this revision to Diff 408097.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/alloc-align-attr.c
  clang/test/CodeGen/alloc-fns-alignment.c
  clang/test/CodeGen/assume-aligned-and-alloc-align-attributes.c
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
  clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
  clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp

Index: clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
===
--- clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
+++ clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
@@ -27,10 +27,10 @@
 struct OVERALIGNED A { A(); int n[128]; };
 
 // CHECK-LABEL: define {{.*}} @_Z2a0v()
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a0@@YAPEAXXZ"()
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK-MS: cleanuppad
 // CHECK-MS: call void @"??3@YAXPEAXW4align_val_t@std@@@Z"(i8* noundef %[[ALLOC]], i64 noundef 32)
 void *a0() { return new A; }
@@ -39,13 +39,13 @@
 // The size is known.
 //
 // CHECK-LABEL: define {{.*}} @_Z2a1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1AC1Ev(
 // CHECK: call void @_ZdaPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a1@@YAPEAXJ@Z"(
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-MS-NOT: store
 // CHECK-MS: invoke noundef %struct.A* @"??0A@@QEAA@XZ"(
@@ -84,7 +84,7 @@
 void *b0() { return new B; }
 
 // CHECK-LABEL: define {{.*}} @_Z2b1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1BC1Ev(
@@ -169,7 +169,7 @@
 
 #ifndef UNALIGNED
 // CHECK-LABEL: define {{.*}} @_Z2e0v(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 4)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 4)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 4)
 void *e0() { return new (std::align_val_t(4)) A; }
 
Index: clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
===
--- clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
+++ clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
@@ -47,7 +47,7 @@
 
 // CHECK-LABEL: define{{.*}} void @test_aligned_alloc(
 extern "C" void test_aligned_alloc() {
-  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
+  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 allocalign noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
   // CHECK: call void @_ZdlPvSt11align_val_t({{.*}}, i64 noundef 4) [[ATTR_BUILTIN_DELETE:#[^ ]*]]
   __builtin_operator_delete(__builtin_operator_new(4, std::align_val_t(4)), std::align_val_t(4));
 }
Index: clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
===
--- clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
+++ clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
@@ -8,7 +8,7 @@
 // CHECK-NEXT:[[ALIGN_ADDR:%.*]] = alloca i32, align 4
 // CHECK-NEXT:store i

[PATCH] D119271: CGCall: also emit LLVM `allocalign` attribute when handling AllocAlign

2022-02-11 Thread Augie Fackler via Phabricator via cfe-commits
durin42 updated this revision to Diff 408116.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/alloc-align-attr.c
  clang/test/CodeGen/alloc-fns-alignment.c
  clang/test/CodeGen/assume-aligned-and-alloc-align-attributes.c
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
  clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
  clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp

Index: clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
===
--- clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
+++ clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
@@ -27,10 +27,10 @@
 struct OVERALIGNED A { A(); int n[128]; };
 
 // CHECK-LABEL: define {{.*}} @_Z2a0v()
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a0@@YAPEAXXZ"()
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK-MS: cleanuppad
 // CHECK-MS: call void @"??3@YAXPEAXW4align_val_t@std@@@Z"(i8* noundef %[[ALLOC]], i64 noundef 32)
 void *a0() { return new A; }
@@ -39,13 +39,13 @@
 // The size is known.
 //
 // CHECK-LABEL: define {{.*}} @_Z2a1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1AC1Ev(
 // CHECK: call void @_ZdaPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a1@@YAPEAXJ@Z"(
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-MS-NOT: store
 // CHECK-MS: invoke noundef %struct.A* @"??0A@@QEAA@XZ"(
@@ -84,7 +84,7 @@
 void *b0() { return new B; }
 
 // CHECK-LABEL: define {{.*}} @_Z2b1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1BC1Ev(
@@ -169,7 +169,7 @@
 
 #ifndef UNALIGNED
 // CHECK-LABEL: define {{.*}} @_Z2e0v(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 4)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 4)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 4)
 void *e0() { return new (std::align_val_t(4)) A; }
 
Index: clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
===
--- clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
+++ clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
@@ -47,7 +47,7 @@
 
 // CHECK-LABEL: define{{.*}} void @test_aligned_alloc(
 extern "C" void test_aligned_alloc() {
-  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
+  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 allocalign noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
   // CHECK: call void @_ZdlPvSt11align_val_t({{.*}}, i64 noundef 4) [[ATTR_BUILTIN_DELETE:#[^ ]*]]
   __builtin_operator_delete(__builtin_operator_new(4, std::align_val_t(4)), std::align_val_t(4));
 }
Index: clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
===
--- clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
+++ clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
@@ -8,7 +8,7 @@
 // CHECK-NEXT:[[ALIGN_ADDR:%.*]] = alloca i32, align 4
 // CHECK-NEXT:store i

[PATCH] D114543: Extend the `uwtable` attribute with unwind table kind

2022-02-14 Thread Augie Fackler via Phabricator via cfe-commits
durin42 added a comment.

As far as I can tell this patch broke the Rust compiler, but from the commit 
message it sounds like it shouldn't have?

https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/8358#e85ad6f3-9992-4ea1-9cd3-d8db9f45f33e
 fails with

  Attribute 'uwtable' should have an Argument
  i8* (i64, i64)* @__rust_alloc
  in function __rust_alloc
  LLVM ERROR: Broken function found, compilation aborted!

Any thoughts?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114543

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


[PATCH] D114543: Extend the `uwtable` attribute with unwind table kind

2022-02-14 Thread Augie Fackler via Phabricator via cfe-commits
durin42 added a comment.

In D114543#3319576 , @chill wrote:

> In D114543#3319347 , @durin42 wrote:
>
>> As far as I can tell this patch broke the Rust compiler, but from the commit 
>> message it sounds like it shouldn't have?
>>
>> https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/8358#e85ad6f3-9992-4ea1-9cd3-d8db9f45f33e
>>  fails with
>>
>>   Attribute 'uwtable' should have an Argument
>>   i8* (i64, i64)* @__rust_alloc
>>   in function __rust_alloc
>>   LLVM ERROR: Broken function found, compilation aborted!
>>
>> Any thoughts?
>
> Yeah, that's puzzling. The attribute has an optional argument (or else we had 
> to update ~3080 occurrences  of "uwtable" in tests), so reading it is
> a bit tricky:  
> https://github.com/llvm/llvm-project/blob/19b4e9d76ecc9a5343c093bc54d965734b996518/llvm/lib/Bitcode/Reader/BitcodeReader.cpp#L1631
> That message is output here 
> https://github.com/llvm/llvm-project/blob/19b4e9d76ecc9a5343c093bc54d965734b996518/llvm/lib/IR/Verifier.cpp#L1710
> and I can trigger this line with
>
>   $ cat x.ll
>   define void @f() uwtable {
>   ret void
>   }
>   $ ./bin/opt -S --passes=verify x.ll
>   ; ModuleID = 'x.ll'
>   source_filename = "x.ll"
>   
>   ; Function Attrs: uwtable
>   define void @f() #0 {
> ret void
>   }
>   
>   attributes #0 = { uwtable }
>   $ ./bin/opt  x.ll -o x.bc
>   $ ./bin/opt --verify  x.bc -S
>   ; ModuleID = 'x.bc'
>   source_filename = "x.ll"
>   
>   ; Function Attrs: uwtable
>   define void @f() #0 {
> ret void
>   }
>   
>   attributes #0 = { uwtable }
>   $ 
>
> Could there be a mismatch between two `llvm-project` versions, somehow?

I don't believe so: we build LLVM from HEAD and build Rust directly against 
LLVM. Is the parameter optional if uwtable is set programmatically, or only 
when we're reading IR streams?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114543

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


[PATCH] D114543: Extend the `uwtable` attribute with unwind table kind

2022-02-14 Thread Augie Fackler via Phabricator via cfe-commits
durin42 added a comment.

In D114543#3319638 , @chill wrote:

> In D114543#3319587 , @durin42 wrote:
>
>> 
>
>
>
>> Is the parameter optional if uwtable is set programmatically, or only when 
>> we're reading IR streams?
>
> No, it's not optional, the attribute is added by 
> https://github.com/llvm/llvm-project/blob/00cd6c04202acf71f74c670b2dd4343929d1f45f/llvm/include/llvm/IR/Function.h#L636
> (although seting it to `None` is semantically as not setting it at all).

Okay, that makes sense then. I think I was close to getting to that point by 
looking at this patch, but you saved me some time. Thanks!

/me off to write matching patch for Rust


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114543

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


[PATCH] D123085: CGExprCXX: emit allocptr attributes for operator delete

2023-06-07 Thread Augie Fackler via Phabricator via cfe-commits
durin42 updated this revision to Diff 529444.
durin42 requested review of this revision.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123085

Files:
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/test/CodeGen/pr53127.cpp
  clang/test/CodeGenCXX/cxx1y-sized-deallocation.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
  clang/test/CodeGenCXX/delete-two-arg.cpp
  clang/test/CodeGenCXX/delete.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/microsoft-abi-structors.cpp

Index: clang/test/CodeGenCXX/microsoft-abi-structors.cpp
===
--- clang/test/CodeGenCXX/microsoft-abi-structors.cpp
+++ clang/test/CodeGenCXX/microsoft-abi-structors.cpp
@@ -57,7 +57,7 @@
 //
 // DTORS:  [[CALL_DELETE_LABEL]]
 // DTORS-NEXT:   %[[THIS_AS_VOID:[0-9a-z]+]] = bitcast %"struct.basic::C"* %[[THIS]] to i8*
-// DTORS-NEXT:   call void @"??3@YAXPAX@Z"(i8* %[[THIS_AS_VOID]])
+// DTORS-NEXT:   call void @"??3@YAXPAX@Z"(i8* allocptr %[[THIS_AS_VOID]])
 // DTORS-NEXT:   br label %[[CONTINUE_LABEL]]
 //
 // DTORS:  [[CONTINUE_LABEL]]
@@ -119,7 +119,7 @@
 // CHECK-NEXT:   %[[PVDTOR:.*]] = getelementptr inbounds i8* (%"struct.basic::C"*, i32)*, i8* (%"struct.basic::C"*, i32)** %[[VTABLE]], i64 0
 // CHECK-NEXT:   %[[VDTOR:.*]] = load i8* (%"struct.basic::C"*, i32)*, i8* (%"struct.basic::C"*, i32)** %[[PVDTOR]]
 // CHECK-NEXT:   %[[CALL:.*]] = call x86_thiscallcc i8* %[[VDTOR]](%"struct.basic::C"* {{[^,]*}} %[[OBJ_PTR_VALUE]], i32 0)
-// CHECK-NEXT:   call void @"??3@YAXPAX@Z"(i8* %[[CALL]])
+// CHECK-NEXT:   call void @"??3@YAXPAX@Z"(i8* allocptr %[[CALL]])
 // CHECK:  ret void
 }
 
Index: clang/test/CodeGenCXX/exceptions.cpp
===
--- clang/test/CodeGenCXX/exceptions.cpp
+++ clang/test/CodeGenCXX/exceptions.cpp
@@ -37,7 +37,7 @@
 // CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
 // CHECK-NEXT: invoke void @_ZN5test11AC1Ei([[A]]* {{[^,]*}} [[CAST]], i32 5)
 // CHECK:  ret [[A]]* [[CAST]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(5);
   }
 
@@ -48,7 +48,7 @@
 // CHECK-NEXT: [[FOO:%.*]] = invoke i32 @_ZN5test13fooEv()
 // CHECK:  invoke void @_ZN5test11AC1Ei([[A]]* {{[^,]*}} [[CAST]], i32 [[FOO]])
 // CHECK:  ret [[A]]* [[CAST]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 extern int foo();
 return new A(foo());
   }
@@ -74,7 +74,7 @@
 // CHECK:  ret [[A]]* [[CAST]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(B().x);
   }
 
@@ -102,7 +102,7 @@
 // CHECK:  ret [[A]]* [[CAST]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(B());
   }
 
@@ -128,7 +128,7 @@
 // CHECK:  ret [[A]]* [[CAST]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(B(), B());
   }
   A *f() {
@@ -165,7 +165,7 @@
 // CHECK:  ret [[A]]* [[RET]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 A *x;
 return (x = new A(makeB()), makeB(), x);
   }
@@ -458,7 +458,7 @@
   }
   // CHECK: define{{.*}} {{%.*}}* @_ZN5test94testEv
   // CHECK: [[TEST9_NEW:%.*]] = call noalias nonnull i8* @_Znam
-  // CHECK: call void @_ZdaPv(i8* [[TEST9_NEW]])
+  // CHECK: call void @_ZdaPv(i8* allocptr [[TEST9_NEW]])
 }
 
 // In a destructor with a function-try-block, a return statement in a
Index: clang/test/CodeGenCXX/delete.cpp
===
--- clang/test/CodeGenCXX/delete.cpp
+++ clang/test/CodeGenCXX/delete.cpp
@@ -100,7 +100,7 @@
 // CHECK-NEXT: call void @_ZN5test11AD1Ev([[A]]* {{[^,]*}} [[CUR]])
 // CHECK-NEXT: [[ISDONE:%.*]] = icmp eq [[A]]* [[CUR]], [[BEGIN]]
 // CHECK-NEXT: br i1 [[ISDONE]]
-// CHECK:  call void @_ZdaPv(i8* noundef [[ALLOC]])
+// CHECK:  call void @_ZdaPv(i8* allocptr noundef [[ALLOC]])
   }
 }
 
@@ -146,7 +146,7 @@
 // CHECK-NEXT: [[DTOR:%.*]] = load void ([[X]]*)*, void ([[X]]*)** [[T0]]
 // CHECK-NEXT: call void [[DTOR]]([[X]]* {{[^,]*}} [[OBJ:%.*]])
 //   Call the global operator delete.
- 

[PATCH] D152400: CodeGen: hand two tests to the care of update_cc_test_checks

2023-06-07 Thread Augie Fackler via Phabricator via cfe-commits
durin42 created this revision.
Herald added a project: All.
durin42 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

These two tests were pretty challenging to manage by hand, and in
rebasing the next change in my stack I finally ran out of patience and
decided to just embrace automation. This change _only_ changes the tests
so that it's obvious what's new in the next change.

Depends on D123085 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152400

Files:
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp

Index: clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
===
--- clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
+++ clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
@@ -1,47 +1,92 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
 // RUN: %clang_cc1 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefixes=CHECK,CHECK-NOSANITIZE
-// RUN: %clang_cc1 -fsanitize=alignment -fno-sanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-NORECOVER,CHECK-SANITIZE-UNREACHABLE
-// RUN: %clang_cc1 -fsanitize=alignment -fsanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-RECOVER
-// RUN: %clang_cc1 -fsanitize=alignment -fsanitize-trap=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-TRAP,CHECK-SANITIZE-UNREACHABLE
+// RUN: %clang_cc1 -fsanitize=alignment -fno-sanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE-NORECOVER
+// RUN: %clang_cc1 -fsanitize=alignment -fsanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE-RECOVER
+// RUN: %clang_cc1 -fsanitize=alignment -fsanitize-trap=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE-TRAP
 
-// CHECK-SANITIZE-ANYRECOVER: @[[CHAR:.*]] = {{.*}} c"'char **'\00" }
-// CHECK-SANITIZE-ANYRECOVER: @[[LINE_100_ALIGNMENT_ASSUMPTION:.*]] = {{.*}}, i32 100, i32 10 }, {{.*}} @[[CHAR]] }
 
 char **__attribute__((alloc_align(2)))
+// CHECK-LABEL: define dso_local noundef ptr @_Z11passthroughPPcm
+// CHECK-SAME: (ptr noundef [[X:%.*]], i64 noundef [[ALIGNMENT:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[X_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[ALIGNMENT_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:store ptr [[X]], ptr [[X_ADDR]], align 8
+// CHECK-NEXT:store i64 [[ALIGNMENT]], ptr [[ALIGNMENT_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X_ADDR]], align 8
+// CHECK-NEXT:ret ptr [[TMP0]]
+//
 passthrough(char **x, unsigned long alignment) {
-  // CHECK:  define{{.*}} ptr @[[PASSTHROUGH:.*]](ptr noundef %[[X:.*]], i64 noundef %[[ALIGNMENT:.*]])
-  // CHECK-NEXT: entry:
-  // CHECK-NEXT:   %[[X_ADDR:.*]] = alloca ptr, align 8
-  // CHECK-NEXT:   %[[ALIGNMENT_ADDR:.*]] = alloca i64, align 8
-  // CHECK-NEXT:   store ptr %[[X]], ptr %[[X_ADDR]], align 8
-  // CHECK-NEXT:   store i64 %[[ALIGNMENT]], ptr %[[ALIGNMENT_ADDR]], align 8
-  // CHECK-NEXT:   %[[X_RELOADED:.*]] = load ptr, ptr %[[X_ADDR]], align 8
-  // CHECK-NEXT:   ret ptr %[[X_RELOADED]]
-  // CHECK-NEXT: }
   return x;
 }
 
+// CHECK-NOSANITIZE-LABEL: define dso_local noundef ptr @_Z6callerPPc
+// CHECK-NOSANITIZE-SAME: (ptr noundef [[X:%.*]]) #[[ATTR0]] {
+// CHECK-NOSANITIZE-NEXT:  entry:
+// CHECK-NOSANITIZE-NEXT:[[X_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NOSANITIZE-NEXT:store ptr [[X]], ptr [[X_ADDR]], align 8
+// CHECK-NOSANITIZE-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X_ADDR]], align 8
+// CHECK-NOSANITIZE-NEXT:[[CALL:%.*]] = call noundef align 128 ptr @_Z11passthroughPPcm(ptr noundef [[TMP0]], i64 noundef 128)
+// CHECK-NOSANITIZE-NEXT:ret ptr [[CALL]]
+//
+// CHECK-SANITIZE-NORECOVER-LABEL: define dso_local noundef ptr @_Z6callerPPc
+// CHECK-SANITIZE-NOR

[PATCH] D121629: clang: also check alloc_alignment claims in return

2023-06-07 Thread Augie Fackler via Phabricator via cfe-commits
durin42 updated this revision to Diff 529446.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121629

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp

Index: clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
===
--- clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
+++ clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
@@ -6,15 +6,87 @@
 
 
 char **__attribute__((alloc_align(2)))
-// CHECK-LABEL: define dso_local noundef ptr @_Z11passthroughPPcm
-// CHECK-SAME: (ptr noundef [[X:%.*]], i64 noundef [[ALIGNMENT:%.*]]) #[[ATTR0:[0-9]+]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[X_ADDR:%.*]] = alloca ptr, align 8
-// CHECK-NEXT:[[ALIGNMENT_ADDR:%.*]] = alloca i64, align 8
-// CHECK-NEXT:store ptr [[X]], ptr [[X_ADDR]], align 8
-// CHECK-NEXT:store i64 [[ALIGNMENT]], ptr [[ALIGNMENT_ADDR]], align 8
-// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X_ADDR]], align 8
-// CHECK-NEXT:ret ptr [[TMP0]]
+// CHECK-NOSANITIZE-LABEL: define dso_local noundef ptr @_Z11passthroughPPcm
+// CHECK-NOSANITIZE-SAME: (ptr noundef [[X:%.*]], i64 noundef [[ALIGNMENT:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NOSANITIZE-NEXT:  entry:
+// CHECK-NOSANITIZE-NEXT:[[X_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NOSANITIZE-NEXT:[[ALIGNMENT_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NOSANITIZE-NEXT:store ptr [[X]], ptr [[X_ADDR]], align 8
+// CHECK-NOSANITIZE-NEXT:store i64 [[ALIGNMENT]], ptr [[ALIGNMENT_ADDR]], align 8
+// CHECK-NOSANITIZE-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X_ADDR]], align 8
+// CHECK-NOSANITIZE-NEXT:ret ptr [[TMP0]]
+//
+// CHECK-SANITIZE-NORECOVER-LABEL: define dso_local noundef ptr @_Z11passthroughPPcm
+// CHECK-SANITIZE-NORECOVER-SAME: (ptr noundef [[X:%.*]], i64 noundef [[ALIGNMENT:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-SANITIZE-NORECOVER-NEXT:  entry:
+// CHECK-SANITIZE-NORECOVER-NEXT:[[RETURN_SLOC_PTR:%.*]] = alloca ptr, align 8
+// CHECK-SANITIZE-NORECOVER-NEXT:[[X_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-SANITIZE-NORECOVER-NEXT:[[ALIGNMENT_ADDR:%.*]] = alloca i64, align 8
+// CHECK-SANITIZE-NORECOVER-NEXT:store ptr null, ptr [[RETURN_SLOC_PTR]], align 8
+// CHECK-SANITIZE-NORECOVER-NEXT:store ptr [[X]], ptr [[X_ADDR]], align 8
+// CHECK-SANITIZE-NORECOVER-NEXT:store i64 [[ALIGNMENT]], ptr [[ALIGNMENT_ADDR]], align 8
+// CHECK-SANITIZE-NORECOVER-NEXT:store ptr @[[GLOB0:[0-9]+]], ptr [[RETURN_SLOC_PTR]], align 8
+// CHECK-SANITIZE-NORECOVER-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X_ADDR]], align 8
+// CHECK-SANITIZE-NORECOVER-NEXT:[[PTRINT:%.*]] = ptrtoint ptr [[TMP0]] to i64
+// CHECK-SANITIZE-NORECOVER-NEXT:[[TMP1:%.*]] = sub i64 [[ALIGNMENT]], 1
+// CHECK-SANITIZE-NORECOVER-NEXT:[[MASKEDPTR:%.*]] = and i64 [[PTRINT]], [[TMP1]]
+// CHECK-SANITIZE-NORECOVER-NEXT:[[MASKCOND:%.*]] = icmp eq i64 [[MASKEDPTR]], 0
+// CHECK-SANITIZE-NORECOVER-NEXT:[[TMP2:%.*]] = ptrtoint ptr [[TMP0]] to i64, !nosanitize !2
+// CHECK-SANITIZE-NORECOVER-NEXT:br i1 [[MASKCOND]], label [[CONT:%.*]], label [[HANDLER_ALIGNMENT_ASSUMPTION:%.*]], !prof [[PROF3:![0-9]+]], !nosanitize !2
+// CHECK-SANITIZE-NORECOVER:   handler.alignment_assumption:
+// CHECK-SANITIZE-NORECOVER-NEXT:call void @__ubsan_handle_alignment_assumption_abort(ptr @[[GLOB2:[0-9]+]], i64 [[TMP2]], i64 [[ALIGNMENT]], i64 0) #[[ATTR3:[0-9]+]], !nosanitize !2
+// CHECK-SANITIZE-NORECOVER-NEXT:unreachable, !nosanitize !2
+// CHECK-SANITIZE-NORECOVER:   cont:
+// CHECK-SANITIZE-NORECOVER-NEXT:call void @llvm.assume(i1 true) [ "align"(ptr [[TMP0]], i64 [[ALIGNMENT]]) ]
+// CHECK-SANITIZE-NORECOVER-NEXT:ret ptr [[TMP0]]
+//
+// CHECK-SANITIZE-RECOVER-LABEL: define dso_local noundef ptr @_Z11passthroughPPcm
+// CHECK-SANITIZE-RECOVER-SAME: (ptr noundef [[X:%.*]], i64 noundef [[ALIGNMENT:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-SANITIZE-RECOVER-NEXT:  entry:
+// CHECK-SANITIZE-RECOVER-NEXT:[[RETURN_SLOC_PTR:%.*]] = alloca ptr, align 8
+// CHECK-SANITIZE-RECOVER-NEXT:[[X_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-SANITIZE-RECOVER-NEXT:[[ALIGNMENT_ADDR:%.*]] = alloca i64, align 8
+// CHECK-SANITIZE-RECOVER-NEXT:store ptr null, ptr [[RETURN_SLOC_PTR]], align 8
+// CHECK-SANITIZE-RECOVER-NEXT:store ptr [[X]], ptr [[X_ADDR]], align 8
+// CHECK-SANITIZE-RECOVER-NEXT:store i64 [[ALIGNMENT]], ptr [[ALIGNMENT_ADDR]], align 8
+// CHECK-SANITIZE-RECOVER-NEXT:store ptr @[[GLOB0:[0-9]+]], ptr [[RETURN_SLOC_PTR]], align 8
+// CHECK-SANITIZE-RECOVER-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X_ADDR]], align 8

[PATCH] D119271: clang: emit allocalign to LLVM for alloc_align attributes

2023-06-07 Thread Augie Fackler via Phabricator via cfe-commits
durin42 updated this revision to Diff 529447.
durin42 requested review of this revision.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/alloc-align-attr.c
  clang/test/CodeGen/alloc-fns-alignment.c
  clang/test/CodeGen/assume-aligned-and-alloc-align-attributes.c
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
  clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
  clang/test/CodeGenCXX/align-avx-complete-objects.cpp
  clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp

Index: clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
===
--- clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
+++ clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
@@ -27,10 +27,10 @@
 struct OVERALIGNED A { A(); int n[128]; };
 
 // CHECK-LABEL: define {{.*}} @_Z2a0v()
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 ptr @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 ptr @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK: call void @_ZdlPvSt11align_val_t(ptr allocptr noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a0@@YAPEAXXZ"()
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 ptr @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 ptr @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK-MS: cleanuppad
 // CHECK-MS: call void @"??3@YAXPEAXW4align_val_t@std@@@Z"(ptr allocptr noundef %[[ALLOC]], i64 noundef 32)
 void *a0() { return new A; }
@@ -39,13 +39,13 @@
 // The size is known.
 //
 // CHECK-LABEL: define {{.*}} @_Z2a1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 ptr @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 ptr @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1AC1Ev(
 // CHECK: call void @_ZdaPvSt11align_val_t(ptr allocptr noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a1@@YAPEAXJ@Z"(
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 ptr @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 ptr @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-MS-NOT: store
 // CHECK-MS: invoke noundef ptr @"??0A@@QEAA@XZ"(
@@ -84,7 +84,7 @@
 void *b0() { return new B; }
 
 // CHECK-LABEL: define {{.*}} @_Z2b1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 ptr @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 ptr @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1BC1Ev(
@@ -169,7 +169,7 @@
 
 #ifndef UNALIGNED
 // CHECK-LABEL: define {{.*}} @_Z2e0v(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 ptr @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 4)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 ptr @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 4)
 // CHECK: call void @_ZdlPvSt11align_val_t(ptr allocptr noundef %[[ALLOC]], i64 noundef 4)
 void *e0() { return new (std::align_val_t(4)) A; }
 
Index: clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
===
--- clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
+++ clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
@@ -47,7 +47,7 @@
 
 // CHECK-LABEL: define{{.*}} void @test_aligned_alloc(
 extern "C" void test_aligned_alloc() {
-  // CHECK: call noalias noundef nonnull align 4 ptr @_ZnwmSt11align_val_t(i64 noundef 4, i64 noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
+  // CHECK: call noalias noundef nonnull align 4 ptr @_ZnwmSt11align_val_t(i64 noundef 4, i64 allocalign noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
   // CHECK: call void @_ZdlPvSt11align_val_t({{.*}}, i64 noundef 4) [[ATTR_BUILTIN_DELETE:#[^ ]*]]
   __builtin_operator_delete(__builtin_operator_new(4, std::align_val_t(4)), std::align_val_t(4));
 }
Index: clang/test/CodeGenCXX/align-avx-complete-objects.cpp
===
--- clang/test/CodeGenCXX/align-avx-complete-objects.cpp
+++ clang/test/CodeGenCXX/align-avx-complete-ob

[PATCH] D152401: CGExprCXX: emit family and allockind attributes

2023-06-07 Thread Augie Fackler via Phabricator via cfe-commits
durin42 created this revision.
Herald added subscribers: JDevlieghere, hiraditya.
Herald added a project: All.
durin42 requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This allows us to remove most of the special knowledge about C++
allocation from LLVM, instead trusting attributes to communicate the
important properties.

Annoyingly, clang has to grow a little bit of hard-coded knowledge about
mangled symbol names in order to actually get the most-basic-matching
::operator::new when working out the alloc-family attribute. I spent
some time trying to do this "right" by looking up the available
operators new and finding the best one, but that's super tricky and this
has the virtue of working and being pretty obviously correct when
compared to the old code.

Happily, clang now emits allocator family attributes correctly even for
custom allocators like the one on new_hot_cold.cpp, which is similar
to tcmalloc per the comments. As a result, clang/llvm should correctly
optimize custom allocators like this without needing specialized
knowledge going forward.

Depends on D119271 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152401

Files:
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
  clang/test/CodeGenCXX/new.cpp
  clang/test/CodeGenCXX/new_hot_cold.cpp
  llvm/lib/Analysis/MemoryBuiltins.cpp

Index: llvm/lib/Analysis/MemoryBuiltins.cpp
===
--- llvm/lib/Analysis/MemoryBuiltins.cpp
+++ llvm/lib/Analysis/MemoryBuiltins.cpp
@@ -110,38 +110,6 @@
 // FIXME: certain users need more information. E.g., SimplifyLibCalls needs to
 // know which functions are nounwind, noalias, nocapture parameters, etc.
 static const std::pair AllocationFnData[] = {
-{LibFunc_Znwj,  {OpNewLike,1,  0, -1, -1, MallocFamily::CPPNew}}, // new(unsigned int)
-{LibFunc_ZnwjRKSt9nothrow_t,{MallocLike,   2,  0, -1, -1, MallocFamily::CPPNew}}, // new(unsigned int, nothrow)
-{LibFunc_ZnwjSt11align_val_t,   {OpNewLike,2,  0, -1,  1, MallocFamily::CPPNewAligned}},  // new(unsigned int, align_val_t)
-{LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t, {MallocLike,   3,  0, -1,  1, MallocFamily::CPPNewAligned}},  // new(unsigned int, align_val_t, nothrow)
-{LibFunc_Znwm,  {OpNewLike,1,  0, -1, -1, MallocFamily::CPPNew}}, // new(unsigned long)
-{LibFunc_Znwm12__hot_cold_t,  {OpNewLike,2, 0,  -1, -1, MallocFamily::CPPNew}}, // new(unsigned long, __hot_cold_t)
-{LibFunc_ZnwmRKSt9nothrow_t,{MallocLike,   2,  0, -1, -1, MallocFamily::CPPNew}}, // new(unsigned long, nothrow)
-{LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t,  {MallocLike,   3, 0,  -1, -1, MallocFamily::CPPNew}}, // new(unsigned long, nothrow, __hot_cold_t)
-{LibFunc_ZnwmSt11align_val_t,   {OpNewLike,2,  0, -1,  1, MallocFamily::CPPNewAligned}},  // new(unsigned long, align_val_t)
-{LibFunc_ZnwmSt11align_val_t12__hot_cold_t,   {OpNewLike,3, 0,  -1, 1, MallocFamily::CPPNewAligned}},   // new(unsigned long, align_val_t, __hot_cold_t)
-{LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t, {MallocLike,   3,  0, -1,  1, MallocFamily::CPPNewAligned}},  // new(unsigned long, align_val_t, nothrow)
-{LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t, {MallocLike,  4, 0,  -1, 1, MallocFamily::CPPNewAligned}},// new(unsigned long, align_val_t, nothrow, __hot_cold_t)
-{LibFunc_Znaj,  {OpNewLike,1,  0, -1, -1, MallocFamily::CPPNewArray}},// new[](unsigned int)
-{LibFunc_ZnajRKSt9nothrow_t,{MallocLike,   2,  0, -1, -1, MallocFamily::CPPNewArray}},// new[](unsigned int, nothrow)
-{LibFunc_ZnajSt11align_val_t,   {OpNewLike,2,  0, -1,  1, MallocFamily::CPPNewArrayAligned}}, // new[](unsigned int, align_val_t)
-{LibFunc_ZnajSt11align_val_tRKSt9nothrow_t, {MallocLike,   3,  0, -1,  1, MallocFamily::CPPNewArrayAligned}}, // new[](unsigned int, align_val_t, nothrow)
-{LibFunc_Znam,  {OpNewLike,1,  0, -1, -1, MallocFamily::CPPNewArray}},// new[](unsigned long)
-{LibFunc_Znam12__hot_cold_t,  {OpNewLike,2, 0,  -1, -1, MallocFamily::CPPNew}}, // new[](unsigned long, __hot_cold_t)
-{LibFunc_ZnamRKSt9nothrow_t,{MallocLike,   2,  0, -1, -1, MallocFamily::CPPNewArray}},// new[](unsigned long, nothrow)
-{LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t,  {MallocLike,   3, 0,  -1, -1, MallocFamily::CPPNew}}, // new[](unsi

[PATCH] D152400: CodeGen: hand two tests to the care of update_cc_test_checks

2023-06-08 Thread Augie Fackler via Phabricator via cfe-commits
durin42 edited the summary of this revision.
durin42 updated this revision to Diff 529614.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152400

Files:
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp

Index: clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
===
--- clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
+++ clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
@@ -1,47 +1,92 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
 // RUN: %clang_cc1 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefixes=CHECK,CHECK-NOSANITIZE
-// RUN: %clang_cc1 -fsanitize=alignment -fno-sanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-NORECOVER,CHECK-SANITIZE-UNREACHABLE
-// RUN: %clang_cc1 -fsanitize=alignment -fsanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-RECOVER
-// RUN: %clang_cc1 -fsanitize=alignment -fsanitize-trap=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-TRAP,CHECK-SANITIZE-UNREACHABLE
+// RUN: %clang_cc1 -fsanitize=alignment -fno-sanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE-NORECOVER
+// RUN: %clang_cc1 -fsanitize=alignment -fsanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE-RECOVER
+// RUN: %clang_cc1 -fsanitize=alignment -fsanitize-trap=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE-TRAP
 
-// CHECK-SANITIZE-ANYRECOVER: @[[CHAR:.*]] = {{.*}} c"'char **'\00" }
-// CHECK-SANITIZE-ANYRECOVER: @[[LINE_100_ALIGNMENT_ASSUMPTION:.*]] = {{.*}}, i32 100, i32 10 }, {{.*}} @[[CHAR]] }
 
 char **__attribute__((alloc_align(2)))
+// CHECK-LABEL: define dso_local noundef ptr @_Z11passthroughPPcm
+// CHECK-SAME: (ptr noundef [[X:%.*]], i64 noundef [[ALIGNMENT:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[X_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[ALIGNMENT_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:store ptr [[X]], ptr [[X_ADDR]], align 8
+// CHECK-NEXT:store i64 [[ALIGNMENT]], ptr [[ALIGNMENT_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X_ADDR]], align 8
+// CHECK-NEXT:ret ptr [[TMP0]]
+//
 passthrough(char **x, unsigned long alignment) {
-  // CHECK:  define{{.*}} ptr @[[PASSTHROUGH:.*]](ptr noundef %[[X:.*]], i64 noundef %[[ALIGNMENT:.*]])
-  // CHECK-NEXT: entry:
-  // CHECK-NEXT:   %[[X_ADDR:.*]] = alloca ptr, align 8
-  // CHECK-NEXT:   %[[ALIGNMENT_ADDR:.*]] = alloca i64, align 8
-  // CHECK-NEXT:   store ptr %[[X]], ptr %[[X_ADDR]], align 8
-  // CHECK-NEXT:   store i64 %[[ALIGNMENT]], ptr %[[ALIGNMENT_ADDR]], align 8
-  // CHECK-NEXT:   %[[X_RELOADED:.*]] = load ptr, ptr %[[X_ADDR]], align 8
-  // CHECK-NEXT:   ret ptr %[[X_RELOADED]]
-  // CHECK-NEXT: }
   return x;
 }
 
+// CHECK-NOSANITIZE-LABEL: define dso_local noundef ptr @_Z6callerPPc
+// CHECK-NOSANITIZE-SAME: (ptr noundef [[X:%.*]]) #[[ATTR0]] {
+// CHECK-NOSANITIZE-NEXT:  entry:
+// CHECK-NOSANITIZE-NEXT:[[X_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NOSANITIZE-NEXT:store ptr [[X]], ptr [[X_ADDR]], align 8
+// CHECK-NOSANITIZE-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X_ADDR]], align 8
+// CHECK-NOSANITIZE-NEXT:[[CALL:%.*]] = call noundef align 128 ptr @_Z11passthroughPPcm(ptr noundef [[TMP0]], i64 noundef 128)
+// CHECK-NOSANITIZE-NEXT:ret ptr [[CALL]]
+//
+// CHECK-SANITIZE-NORECOVER-LABEL: define dso_local noundef ptr @_Z6callerPPc
+// CHECK-SANITIZE-NORECOVER-SAME: (ptr noundef [[X:%.*]]) #[[ATTR0]] {
+// CHECK-SANITIZE-NORECOVER-NEXT:  entry:
+// CHECK-SANITIZE-NORECOVER-NEXT:[[X_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-SANITIZE-NORECOVER-NEXT:store ptr [[X]], ptr [[X_ADDR]], align 8
+// CHECK-SANITIZE-NORECOVER-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X_ADDR]], align 8
+

[PATCH] D123085: CGExprCXX: emit allocptr attributes for operator delete

2023-06-08 Thread Augie Fackler via Phabricator via cfe-commits
durin42 updated this revision to Diff 529613.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123085

Files:
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/test/CodeGen/pr53127.cpp
  clang/test/CodeGenCXX/cxx1y-sized-deallocation.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
  clang/test/CodeGenCXX/delete-two-arg.cpp
  clang/test/CodeGenCXX/delete.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/microsoft-abi-structors.cpp

Index: clang/test/CodeGenCXX/microsoft-abi-structors.cpp
===
--- clang/test/CodeGenCXX/microsoft-abi-structors.cpp
+++ clang/test/CodeGenCXX/microsoft-abi-structors.cpp
@@ -56,7 +56,7 @@
 // DTORS-NEXT:   br i1 %[[CONDITION]], label %[[CONTINUE_LABEL:[0-9a-z._]+]], label %[[CALL_DELETE_LABEL:[0-9a-z._]+]]
 //
 // DTORS:  [[CALL_DELETE_LABEL]]
-// DTORS-NEXT:   call void @"??3@YAXPAX@Z"(ptr %[[THIS]])
+// DTORS-NEXT:   call void @"??3@YAXPAX@Z"(ptr allocptr %[[THIS]])
 // DTORS-NEXT:   br label %[[CONTINUE_LABEL]]
 //
 // DTORS:  [[CONTINUE_LABEL]]
@@ -114,7 +114,7 @@
 // CHECK-NEXT:   %[[PVDTOR:.*]] = getelementptr inbounds ptr, ptr %[[VTABLE]], i64 0
 // CHECK-NEXT:   %[[VDTOR:.*]] = load ptr, ptr %[[PVDTOR]]
 // CHECK-NEXT:   %[[CALL:.*]] = call x86_thiscallcc ptr %[[VDTOR]](ptr {{[^,]*}} %[[OBJ_PTR_VALUE]], i32 0)
-// CHECK-NEXT:   call void @"??3@YAXPAX@Z"(ptr %[[CALL]])
+// CHECK-NEXT:   call void @"??3@YAXPAX@Z"(ptr allocptr %[[CALL]])
 // CHECK:  ret void
 }
 
Index: clang/test/CodeGenCXX/exceptions.cpp
===
--- clang/test/CodeGenCXX/exceptions.cpp
+++ clang/test/CodeGenCXX/exceptions.cpp
@@ -36,7 +36,7 @@
 // CHECK:  [[NEW:%.*]] = call noalias nonnull ptr @_Znwm(i64 8)
 // CHECK-NEXT: invoke void @_ZN5test11AC1Ei(ptr {{[^,]*}} [[NEW]], i32 5)
 // CHECK:  ret ptr [[NEW]]
-// CHECK:  call void @_ZdlPv(ptr [[NEW]])
+// CHECK:  call void @_ZdlPv(ptr allocptr [[NEW]])
 return new A(5);
   }
 
@@ -46,7 +46,7 @@
 // CHECK-NEXT: [[FOO:%.*]] = invoke i32 @_ZN5test13fooEv()
 // CHECK:  invoke void @_ZN5test11AC1Ei(ptr {{[^,]*}} [[NEW]], i32 [[FOO]])
 // CHECK:  ret ptr [[NEW]]
-// CHECK:  call void @_ZdlPv(ptr [[NEW]])
+// CHECK:  call void @_ZdlPv(ptr allocptr [[NEW]])
 extern int foo();
 return new A(foo());
   }
@@ -71,7 +71,7 @@
 // CHECK:  ret ptr [[NEW]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, ptr [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(ptr [[NEW]])
+// CHECK:  call void @_ZdlPv(ptr allocptr [[NEW]])
 return new A(B().x);
   }
 
@@ -98,7 +98,7 @@
 // CHECK:  ret ptr [[NEW]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, ptr [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(ptr [[NEW]])
+// CHECK:  call void @_ZdlPv(ptr allocptr [[NEW]])
 return new A(B());
   }
 
@@ -123,7 +123,7 @@
 // CHECK:  ret ptr [[NEW]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, ptr [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(ptr [[NEW]])
+// CHECK:  call void @_ZdlPv(ptr allocptr [[NEW]])
 return new A(B(), B());
   }
   A *f() {
@@ -159,7 +159,7 @@
 // CHECK:  ret ptr [[RET]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, ptr [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(ptr [[NEW]])
+// CHECK:  call void @_ZdlPv(ptr allocptr [[NEW]])
 A *x;
 return (x = new A(makeB()), makeB(), x);
   }
@@ -445,7 +445,7 @@
   }
   // CHECK: define{{.*}} ptr @_ZN5test94testEv
   // CHECK: [[TEST9_NEW:%.*]] = call noalias nonnull ptr @_Znam
-  // CHECK: call void @_ZdaPv(ptr [[TEST9_NEW]])
+  // CHECK: call void @_ZdaPv(ptr allocptr [[TEST9_NEW]])
 }
 
 // In a destructor with a function-try-block, a return statement in a
Index: clang/test/CodeGenCXX/delete.cpp
===
--- clang/test/CodeGenCXX/delete.cpp
+++ clang/test/CodeGenCXX/delete.cpp
@@ -93,7 +93,7 @@
 // CHECK-NEXT: call void @_ZN5test11AD1Ev(ptr {{[^,]*}} [[CUR]])
 // CHECK-NEXT: [[ISDONE:%.*]] = icmp eq ptr [[CUR]], [[BEGIN]]
 // CHECK-NEXT: br i1 [[ISDONE]]
-// CHECK:  call void @_ZdaPv(ptr noundef [[ALLOC]])
+// CHECK:  call void @_ZdaPv(ptr allocptr noundef [[ALLOC]])
   }
 }
 
@@ -137,7 +137,7 @@
 // CHECK-NEXT: [[DTOR:%.*]] = load ptr, ptr [[T0]]
 // CHECK-NEXT: call void [[DTOR]](ptr {{[^,]*}} [[OBJ:%.*]])
 //   Call the global operator delete.
-// CHECK-NEXT: call void @_ZdlPv(ptr noundef [[ALLOCATED]]) [[NUW:#[0-9]+]]
+// CHECK-NEXT: call void @_ZdlPv(ptr allocptr noundef [[ALLOCATED]]) [[NUW:#[0-9]+]]
 ::delete xp;
   }
 }
Index: clang/test/CodeGenCXX/de

[PATCH] D119271: clang: emit allocalign to LLVM for alloc_align attributes

2023-06-08 Thread Augie Fackler via Phabricator via cfe-commits
durin42 updated this revision to Diff 529616.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/alloc-align-attr.c
  clang/test/CodeGen/alloc-fns-alignment.c
  clang/test/CodeGen/assume-aligned-and-alloc-align-attributes.c
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
  clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
  clang/test/CodeGenCXX/align-avx-complete-objects.cpp
  clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp

Index: clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
===
--- clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
+++ clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
@@ -27,10 +27,10 @@
 struct OVERALIGNED A { A(); int n[128]; };
 
 // CHECK-LABEL: define {{.*}} @_Z2a0v()
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 ptr @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 ptr @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK: call void @_ZdlPvSt11align_val_t(ptr allocptr noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a0@@YAPEAXXZ"()
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 ptr @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 ptr @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK-MS: cleanuppad
 // CHECK-MS: call void @"??3@YAXPEAXW4align_val_t@std@@@Z"(ptr allocptr noundef %[[ALLOC]], i64 noundef 32)
 void *a0() { return new A; }
@@ -39,13 +39,13 @@
 // The size is known.
 //
 // CHECK-LABEL: define {{.*}} @_Z2a1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 ptr @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 ptr @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1AC1Ev(
 // CHECK: call void @_ZdaPvSt11align_val_t(ptr allocptr noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a1@@YAPEAXJ@Z"(
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 ptr @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 ptr @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-MS-NOT: store
 // CHECK-MS: invoke noundef ptr @"??0A@@QEAA@XZ"(
@@ -84,7 +84,7 @@
 void *b0() { return new B; }
 
 // CHECK-LABEL: define {{.*}} @_Z2b1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 ptr @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 ptr @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1BC1Ev(
@@ -169,7 +169,7 @@
 
 #ifndef UNALIGNED
 // CHECK-LABEL: define {{.*}} @_Z2e0v(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 ptr @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 4)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 ptr @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 4)
 // CHECK: call void @_ZdlPvSt11align_val_t(ptr allocptr noundef %[[ALLOC]], i64 noundef 4)
 void *e0() { return new (std::align_val_t(4)) A; }
 
Index: clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
===
--- clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
+++ clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
@@ -47,7 +47,7 @@
 
 // CHECK-LABEL: define{{.*}} void @test_aligned_alloc(
 extern "C" void test_aligned_alloc() {
-  // CHECK: call noalias noundef nonnull align 4 ptr @_ZnwmSt11align_val_t(i64 noundef 4, i64 noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
+  // CHECK: call noalias noundef nonnull align 4 ptr @_ZnwmSt11align_val_t(i64 noundef 4, i64 allocalign noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
   // CHECK: call void @_ZdlPvSt11align_val_t({{.*}}, i64 noundef 4) [[ATTR_BUILTIN_DELETE:#[^ ]*]]
   __builtin_operator_delete(__builtin_operator_new(4, std::align_val_t(4)), std::align_val_t(4));
 }
Index: clang/test/CodeGenCXX/align-avx-complete-objects.cpp
===
--- clang/test/CodeGenCXX/align-avx-complete-objects.cpp
+++ clang/test/CodeGenCXX/align-avx-complete-objects.cpp
@@ -18,7 +18,7 @@
 
 // CHECK: [[

[PATCH] D121629: clang: also check alloc_alignment claims in return

2023-06-08 Thread Augie Fackler via Phabricator via cfe-commits
durin42 updated this revision to Diff 529615.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121629

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp

Index: clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
===
--- clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
+++ clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
@@ -6,15 +6,87 @@
 
 
 char **__attribute__((alloc_align(2)))
-// CHECK-LABEL: define dso_local noundef ptr @_Z11passthroughPPcm
-// CHECK-SAME: (ptr noundef [[X:%.*]], i64 noundef [[ALIGNMENT:%.*]]) #[[ATTR0:[0-9]+]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[X_ADDR:%.*]] = alloca ptr, align 8
-// CHECK-NEXT:[[ALIGNMENT_ADDR:%.*]] = alloca i64, align 8
-// CHECK-NEXT:store ptr [[X]], ptr [[X_ADDR]], align 8
-// CHECK-NEXT:store i64 [[ALIGNMENT]], ptr [[ALIGNMENT_ADDR]], align 8
-// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X_ADDR]], align 8
-// CHECK-NEXT:ret ptr [[TMP0]]
+// CHECK-NOSANITIZE-LABEL: define dso_local noundef ptr @_Z11passthroughPPcm
+// CHECK-NOSANITIZE-SAME: (ptr noundef [[X:%.*]], i64 noundef [[ALIGNMENT:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NOSANITIZE-NEXT:  entry:
+// CHECK-NOSANITIZE-NEXT:[[X_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NOSANITIZE-NEXT:[[ALIGNMENT_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NOSANITIZE-NEXT:store ptr [[X]], ptr [[X_ADDR]], align 8
+// CHECK-NOSANITIZE-NEXT:store i64 [[ALIGNMENT]], ptr [[ALIGNMENT_ADDR]], align 8
+// CHECK-NOSANITIZE-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X_ADDR]], align 8
+// CHECK-NOSANITIZE-NEXT:ret ptr [[TMP0]]
+//
+// CHECK-SANITIZE-NORECOVER-LABEL: define dso_local noundef ptr @_Z11passthroughPPcm
+// CHECK-SANITIZE-NORECOVER-SAME: (ptr noundef [[X:%.*]], i64 noundef [[ALIGNMENT:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-SANITIZE-NORECOVER-NEXT:  entry:
+// CHECK-SANITIZE-NORECOVER-NEXT:[[RETURN_SLOC_PTR:%.*]] = alloca ptr, align 8
+// CHECK-SANITIZE-NORECOVER-NEXT:[[X_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-SANITIZE-NORECOVER-NEXT:[[ALIGNMENT_ADDR:%.*]] = alloca i64, align 8
+// CHECK-SANITIZE-NORECOVER-NEXT:store ptr null, ptr [[RETURN_SLOC_PTR]], align 8
+// CHECK-SANITIZE-NORECOVER-NEXT:store ptr [[X]], ptr [[X_ADDR]], align 8
+// CHECK-SANITIZE-NORECOVER-NEXT:store i64 [[ALIGNMENT]], ptr [[ALIGNMENT_ADDR]], align 8
+// CHECK-SANITIZE-NORECOVER-NEXT:store ptr @[[GLOB0:[0-9]+]], ptr [[RETURN_SLOC_PTR]], align 8
+// CHECK-SANITIZE-NORECOVER-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X_ADDR]], align 8
+// CHECK-SANITIZE-NORECOVER-NEXT:[[PTRINT:%.*]] = ptrtoint ptr [[TMP0]] to i64
+// CHECK-SANITIZE-NORECOVER-NEXT:[[TMP1:%.*]] = sub i64 [[ALIGNMENT]], 1
+// CHECK-SANITIZE-NORECOVER-NEXT:[[MASKEDPTR:%.*]] = and i64 [[PTRINT]], [[TMP1]]
+// CHECK-SANITIZE-NORECOVER-NEXT:[[MASKCOND:%.*]] = icmp eq i64 [[MASKEDPTR]], 0
+// CHECK-SANITIZE-NORECOVER-NEXT:[[TMP2:%.*]] = ptrtoint ptr [[TMP0]] to i64, !nosanitize !2
+// CHECK-SANITIZE-NORECOVER-NEXT:br i1 [[MASKCOND]], label [[CONT:%.*]], label [[HANDLER_ALIGNMENT_ASSUMPTION:%.*]], !prof [[PROF3:![0-9]+]], !nosanitize !2
+// CHECK-SANITIZE-NORECOVER:   handler.alignment_assumption:
+// CHECK-SANITIZE-NORECOVER-NEXT:call void @__ubsan_handle_alignment_assumption_abort(ptr @[[GLOB2:[0-9]+]], i64 [[TMP2]], i64 [[ALIGNMENT]], i64 0) #[[ATTR3:[0-9]+]], !nosanitize !2
+// CHECK-SANITIZE-NORECOVER-NEXT:unreachable, !nosanitize !2
+// CHECK-SANITIZE-NORECOVER:   cont:
+// CHECK-SANITIZE-NORECOVER-NEXT:call void @llvm.assume(i1 true) [ "align"(ptr [[TMP0]], i64 [[ALIGNMENT]]) ]
+// CHECK-SANITIZE-NORECOVER-NEXT:ret ptr [[TMP0]]
+//
+// CHECK-SANITIZE-RECOVER-LABEL: define dso_local noundef ptr @_Z11passthroughPPcm
+// CHECK-SANITIZE-RECOVER-SAME: (ptr noundef [[X:%.*]], i64 noundef [[ALIGNMENT:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-SANITIZE-RECOVER-NEXT:  entry:
+// CHECK-SANITIZE-RECOVER-NEXT:[[RETURN_SLOC_PTR:%.*]] = alloca ptr, align 8
+// CHECK-SANITIZE-RECOVER-NEXT:[[X_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-SANITIZE-RECOVER-NEXT:[[ALIGNMENT_ADDR:%.*]] = alloca i64, align 8
+// CHECK-SANITIZE-RECOVER-NEXT:store ptr null, ptr [[RETURN_SLOC_PTR]], align 8
+// CHECK-SANITIZE-RECOVER-NEXT:store ptr [[X]], ptr [[X_ADDR]], align 8
+// CHECK-SANITIZE-RECOVER-NEXT:store i64 [[ALIGNMENT]], ptr [[ALIGNMENT_ADDR]], align 8
+// CHECK-SANITIZE-RECOVER-NEXT:store ptr @[[GLOB0:[0-9]+]], ptr [[RETURN_SLOC_PTR]], align 8
+// CHECK-SANITIZE-RECOVER-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X_ADDR]], align 8

[PATCH] D152401: CGExprCXX: emit family and allockind attributes

2023-06-08 Thread Augie Fackler via Phabricator via cfe-commits
durin42 edited the summary of this revision.
durin42 updated this revision to Diff 529617.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152401

Files:
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
  clang/test/CodeGenCXX/new.cpp
  clang/test/CodeGenCXX/new_hot_cold.cpp
  llvm/lib/Analysis/MemoryBuiltins.cpp

Index: llvm/lib/Analysis/MemoryBuiltins.cpp
===
--- llvm/lib/Analysis/MemoryBuiltins.cpp
+++ llvm/lib/Analysis/MemoryBuiltins.cpp
@@ -110,38 +110,6 @@
 // FIXME: certain users need more information. E.g., SimplifyLibCalls needs to
 // know which functions are nounwind, noalias, nocapture parameters, etc.
 static const std::pair AllocationFnData[] = {
-{LibFunc_Znwj,  {OpNewLike,1,  0, -1, -1, MallocFamily::CPPNew}}, // new(unsigned int)
-{LibFunc_ZnwjRKSt9nothrow_t,{MallocLike,   2,  0, -1, -1, MallocFamily::CPPNew}}, // new(unsigned int, nothrow)
-{LibFunc_ZnwjSt11align_val_t,   {OpNewLike,2,  0, -1,  1, MallocFamily::CPPNewAligned}},  // new(unsigned int, align_val_t)
-{LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t, {MallocLike,   3,  0, -1,  1, MallocFamily::CPPNewAligned}},  // new(unsigned int, align_val_t, nothrow)
-{LibFunc_Znwm,  {OpNewLike,1,  0, -1, -1, MallocFamily::CPPNew}}, // new(unsigned long)
-{LibFunc_Znwm12__hot_cold_t,  {OpNewLike,2, 0,  -1, -1, MallocFamily::CPPNew}}, // new(unsigned long, __hot_cold_t)
-{LibFunc_ZnwmRKSt9nothrow_t,{MallocLike,   2,  0, -1, -1, MallocFamily::CPPNew}}, // new(unsigned long, nothrow)
-{LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t,  {MallocLike,   3, 0,  -1, -1, MallocFamily::CPPNew}}, // new(unsigned long, nothrow, __hot_cold_t)
-{LibFunc_ZnwmSt11align_val_t,   {OpNewLike,2,  0, -1,  1, MallocFamily::CPPNewAligned}},  // new(unsigned long, align_val_t)
-{LibFunc_ZnwmSt11align_val_t12__hot_cold_t,   {OpNewLike,3, 0,  -1, 1, MallocFamily::CPPNewAligned}},   // new(unsigned long, align_val_t, __hot_cold_t)
-{LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t, {MallocLike,   3,  0, -1,  1, MallocFamily::CPPNewAligned}},  // new(unsigned long, align_val_t, nothrow)
-{LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t, {MallocLike,  4, 0,  -1, 1, MallocFamily::CPPNewAligned}},// new(unsigned long, align_val_t, nothrow, __hot_cold_t)
-{LibFunc_Znaj,  {OpNewLike,1,  0, -1, -1, MallocFamily::CPPNewArray}},// new[](unsigned int)
-{LibFunc_ZnajRKSt9nothrow_t,{MallocLike,   2,  0, -1, -1, MallocFamily::CPPNewArray}},// new[](unsigned int, nothrow)
-{LibFunc_ZnajSt11align_val_t,   {OpNewLike,2,  0, -1,  1, MallocFamily::CPPNewArrayAligned}}, // new[](unsigned int, align_val_t)
-{LibFunc_ZnajSt11align_val_tRKSt9nothrow_t, {MallocLike,   3,  0, -1,  1, MallocFamily::CPPNewArrayAligned}}, // new[](unsigned int, align_val_t, nothrow)
-{LibFunc_Znam,  {OpNewLike,1,  0, -1, -1, MallocFamily::CPPNewArray}},// new[](unsigned long)
-{LibFunc_Znam12__hot_cold_t,  {OpNewLike,2, 0,  -1, -1, MallocFamily::CPPNew}}, // new[](unsigned long, __hot_cold_t)
-{LibFunc_ZnamRKSt9nothrow_t,{MallocLike,   2,  0, -1, -1, MallocFamily::CPPNewArray}},// new[](unsigned long, nothrow)
-{LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t,  {MallocLike,   3, 0,  -1, -1, MallocFamily::CPPNew}}, // new[](unsigned long, nothrow, __hot_cold_t)
-{LibFunc_ZnamSt11align_val_t,   {OpNewLike,2,  0, -1,  1, MallocFamily::CPPNewArrayAligned}}, // new[](unsigned long, align_val_t)
-{LibFunc_ZnamSt11align_val_t12__hot_cold_t,   {OpNewLike,3, 0,  -1, 1, MallocFamily::CPPNewAligned}},   // new[](unsigned long, align_val_t, __hot_cold_t)
-{LibFunc_ZnamSt11align_val_tRKSt9nothrow_t, {MallocLike,   3,  0, -1,  1, MallocFamily::CPPNewArrayAligned}}, // new[](unsigned long, align_val_t, nothrow)
-{LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t, {MallocLike,  4, 0,  -1, 1, MallocFamily::CPPNewAligned}},// new[](unsigned long, align_val_t, nothrow, __hot_cold_t)
-{LibFunc_msvc_new_int,  {OpNewLike,1,  0, -1, -1, MallocFamily::MSVCNew}},// new(unsigned int)
-{LibFunc_msvc_new_int_nothrow,  {MallocLike,   2,  0, -1, -1, MallocFamily::MSVCNew}},// new(unsigned int, nothrow)
-{LibFunc_msvc_new_longlong,  

[PATCH] D152400: CodeGen: hand two tests to the care of update_cc_test_checks

2023-06-12 Thread Augie Fackler 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 rG0bd281eceff5: CodeGen: hand two tests to the care of 
update_cc_test_checks (authored by durin42).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152400

Files:
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp

Index: clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
===
--- clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
+++ clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
@@ -1,47 +1,92 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
 // RUN: %clang_cc1 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefixes=CHECK,CHECK-NOSANITIZE
-// RUN: %clang_cc1 -fsanitize=alignment -fno-sanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-NORECOVER,CHECK-SANITIZE-UNREACHABLE
-// RUN: %clang_cc1 -fsanitize=alignment -fsanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-RECOVER
-// RUN: %clang_cc1 -fsanitize=alignment -fsanitize-trap=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-TRAP,CHECK-SANITIZE-UNREACHABLE
+// RUN: %clang_cc1 -fsanitize=alignment -fno-sanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE-NORECOVER
+// RUN: %clang_cc1 -fsanitize=alignment -fsanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE-RECOVER
+// RUN: %clang_cc1 -fsanitize=alignment -fsanitize-trap=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE-TRAP
 
-// CHECK-SANITIZE-ANYRECOVER: @[[CHAR:.*]] = {{.*}} c"'char **'\00" }
-// CHECK-SANITIZE-ANYRECOVER: @[[LINE_100_ALIGNMENT_ASSUMPTION:.*]] = {{.*}}, i32 100, i32 10 }, {{.*}} @[[CHAR]] }
 
 char **__attribute__((alloc_align(2)))
+// CHECK-LABEL: define dso_local noundef ptr @_Z11passthroughPPcm
+// CHECK-SAME: (ptr noundef [[X:%.*]], i64 noundef [[ALIGNMENT:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[X_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[ALIGNMENT_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:store ptr [[X]], ptr [[X_ADDR]], align 8
+// CHECK-NEXT:store i64 [[ALIGNMENT]], ptr [[ALIGNMENT_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X_ADDR]], align 8
+// CHECK-NEXT:ret ptr [[TMP0]]
+//
 passthrough(char **x, unsigned long alignment) {
-  // CHECK:  define{{.*}} ptr @[[PASSTHROUGH:.*]](ptr noundef %[[X:.*]], i64 noundef %[[ALIGNMENT:.*]])
-  // CHECK-NEXT: entry:
-  // CHECK-NEXT:   %[[X_ADDR:.*]] = alloca ptr, align 8
-  // CHECK-NEXT:   %[[ALIGNMENT_ADDR:.*]] = alloca i64, align 8
-  // CHECK-NEXT:   store ptr %[[X]], ptr %[[X_ADDR]], align 8
-  // CHECK-NEXT:   store i64 %[[ALIGNMENT]], ptr %[[ALIGNMENT_ADDR]], align 8
-  // CHECK-NEXT:   %[[X_RELOADED:.*]] = load ptr, ptr %[[X_ADDR]], align 8
-  // CHECK-NEXT:   ret ptr %[[X_RELOADED]]
-  // CHECK-NEXT: }
   return x;
 }
 
+// CHECK-NOSANITIZE-LABEL: define dso_local noundef ptr @_Z6callerPPc
+// CHECK-NOSANITIZE-SAME: (ptr noundef [[X:%.*]]) #[[ATTR0]] {
+// CHECK-NOSANITIZE-NEXT:  entry:
+// CHECK-NOSANITIZE-NEXT:[[X_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NOSANITIZE-NEXT:store ptr [[X]], ptr [[X_ADDR]], align 8
+// CHECK-NOSANITIZE-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X_ADDR]], align 8
+// CHECK-NOSANITIZE-NEXT:[[CALL:%.*]] = call noundef align 128 ptr @_Z11passthroughPPcm(ptr noundef [[TMP0]], i64 noundef 128)
+// CHECK-NOSANITIZE-NEXT:ret ptr [[CALL]]
+//
+// CHECK-SANITIZE-NORECOVER-LABEL: define dso_local noundef ptr @_Z6callerPPc
+// CHECK-SANITIZE-NORECOVER-SAME: (ptr noundef [[X:%.*]]) #[[ATTR0]] {
+// CHECK-SANITIZE-NORECOVER-NEXT:  entry:
+// CHECK-SANITIZE-NORECOVER-NEXT:[[X_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-

[PATCH] D119271: clang: emit allocalign to LLVM for alloc_align attributes

2023-06-13 Thread Augie Fackler via Phabricator via cfe-commits
durin42 added a comment.

FYI: this is ready for review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

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


[PATCH] D123085: CGExprCXX: emit allocptr attributes for operator delete

2023-06-13 Thread Augie Fackler via Phabricator via cfe-commits
durin42 added a comment.

FYI: this is ready for review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123085

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


[PATCH] D121629: clang: also check alloc_alignment claims in return

2023-06-13 Thread Augie Fackler via Phabricator via cfe-commits
durin42 added a comment.

FYI: this is ready for review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121629

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


[PATCH] D152401: CGExprCXX: emit family and allockind attributes

2023-06-13 Thread Augie Fackler via Phabricator via cfe-commits
durin42 added a comment.

FYI: this is ready for review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152401

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


[PATCH] D119271: CGCall: also emit LLVM `allocalign` attribute when handling AllocAlign

2022-02-18 Thread Augie Fackler via Phabricator via cfe-commits
durin42 updated this revision to Diff 410058.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/alloc-align-attr.c
  clang/test/CodeGen/alloc-fns-alignment.c
  clang/test/CodeGen/assume-aligned-and-alloc-align-attributes.c
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
  clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
  clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp

Index: clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
===
--- clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
+++ clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
@@ -27,10 +27,10 @@
 struct OVERALIGNED A { A(); int n[128]; };
 
 // CHECK-LABEL: define {{.*}} @_Z2a0v()
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a0@@YAPEAXXZ"()
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK-MS: cleanuppad
 // CHECK-MS: call void @"??3@YAXPEAXW4align_val_t@std@@@Z"(i8* noundef %[[ALLOC]], i64 noundef 32)
 void *a0() { return new A; }
@@ -39,13 +39,13 @@
 // The size is known.
 //
 // CHECK-LABEL: define {{.*}} @_Z2a1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1AC1Ev(
 // CHECK: call void @_ZdaPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a1@@YAPEAXJ@Z"(
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-MS-NOT: store
 // CHECK-MS: invoke noundef %struct.A* @"??0A@@QEAA@XZ"(
@@ -84,7 +84,7 @@
 void *b0() { return new B; }
 
 // CHECK-LABEL: define {{.*}} @_Z2b1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1BC1Ev(
@@ -169,7 +169,7 @@
 
 #ifndef UNALIGNED
 // CHECK-LABEL: define {{.*}} @_Z2e0v(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 4)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 4)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 4)
 void *e0() { return new (std::align_val_t(4)) A; }
 
Index: clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
===
--- clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
+++ clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
@@ -47,7 +47,7 @@
 
 // CHECK-LABEL: define{{.*}} void @test_aligned_alloc(
 extern "C" void test_aligned_alloc() {
-  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
+  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 allocalign noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
   // CHECK: call void @_ZdlPvSt11align_val_t({{.*}}, i64 noundef 4) [[ATTR_BUILTIN_DELETE:#[^ ]*]]
   __builtin_operator_delete(__builtin_operator_new(4, std::align_val_t(4)), std::align_val_t(4));
 }
Index: clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
===
--- clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
+++ clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
@@ -8,7 +8,7 @@
 // CHECK-NEXT:[[ALIGN_ADDR:%.*]] = alloca i32, align 4
 // CHECK-NEXT:store i

[PATCH] D119271: CGCall: also emit LLVM `allocalign` attribute when handling AllocAlign

2022-02-22 Thread Augie Fackler via Phabricator via cfe-commits
durin42 updated this revision to Diff 410558.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/alloc-align-attr.c
  clang/test/CodeGen/alloc-fns-alignment.c
  clang/test/CodeGen/assume-aligned-and-alloc-align-attributes.c
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
  clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
  clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp

Index: clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
===
--- clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
+++ clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
@@ -27,10 +27,10 @@
 struct OVERALIGNED A { A(); int n[128]; };
 
 // CHECK-LABEL: define {{.*}} @_Z2a0v()
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a0@@YAPEAXXZ"()
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK-MS: cleanuppad
 // CHECK-MS: call void @"??3@YAXPEAXW4align_val_t@std@@@Z"(i8* noundef %[[ALLOC]], i64 noundef 32)
 void *a0() { return new A; }
@@ -39,13 +39,13 @@
 // The size is known.
 //
 // CHECK-LABEL: define {{.*}} @_Z2a1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1AC1Ev(
 // CHECK: call void @_ZdaPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a1@@YAPEAXJ@Z"(
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-MS-NOT: store
 // CHECK-MS: invoke noundef %struct.A* @"??0A@@QEAA@XZ"(
@@ -84,7 +84,7 @@
 void *b0() { return new B; }
 
 // CHECK-LABEL: define {{.*}} @_Z2b1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1BC1Ev(
@@ -169,7 +169,7 @@
 
 #ifndef UNALIGNED
 // CHECK-LABEL: define {{.*}} @_Z2e0v(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 4)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 4)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 4)
 void *e0() { return new (std::align_val_t(4)) A; }
 
Index: clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
===
--- clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
+++ clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
@@ -47,7 +47,7 @@
 
 // CHECK-LABEL: define{{.*}} void @test_aligned_alloc(
 extern "C" void test_aligned_alloc() {
-  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
+  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 allocalign noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
   // CHECK: call void @_ZdlPvSt11align_val_t({{.*}}, i64 noundef 4) [[ATTR_BUILTIN_DELETE:#[^ ]*]]
   __builtin_operator_delete(__builtin_operator_new(4, std::align_val_t(4)), std::align_val_t(4));
 }
Index: clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
===
--- clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
+++ clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
@@ -8,7 +8,7 @@
 // CHECK-NEXT:[[ALIGN_ADDR:%.*]] = alloca i32, align 4
 // CHECK-NEXT:store i

[PATCH] D119271: CGCall: also emit LLVM `allocalign` attribute when handling AllocAlign

2022-02-23 Thread Augie Fackler via Phabricator via cfe-commits
durin42 updated this revision to Diff 410896.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/alloc-align-attr.c
  clang/test/CodeGen/alloc-fns-alignment.c
  clang/test/CodeGen/assume-aligned-and-alloc-align-attributes.c
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
  clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
  clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp

Index: clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
===
--- clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
+++ clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
@@ -27,10 +27,10 @@
 struct OVERALIGNED A { A(); int n[128]; };
 
 // CHECK-LABEL: define {{.*}} @_Z2a0v()
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a0@@YAPEAXXZ"()
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK-MS: cleanuppad
 // CHECK-MS: call void @"??3@YAXPEAXW4align_val_t@std@@@Z"(i8* noundef %[[ALLOC]], i64 noundef 32)
 void *a0() { return new A; }
@@ -39,13 +39,13 @@
 // The size is known.
 //
 // CHECK-LABEL: define {{.*}} @_Z2a1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1AC1Ev(
 // CHECK: call void @_ZdaPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a1@@YAPEAXJ@Z"(
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-MS-NOT: store
 // CHECK-MS: invoke noundef %struct.A* @"??0A@@QEAA@XZ"(
@@ -84,7 +84,7 @@
 void *b0() { return new B; }
 
 // CHECK-LABEL: define {{.*}} @_Z2b1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1BC1Ev(
@@ -169,7 +169,7 @@
 
 #ifndef UNALIGNED
 // CHECK-LABEL: define {{.*}} @_Z2e0v(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 4)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 4)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 4)
 void *e0() { return new (std::align_val_t(4)) A; }
 
Index: clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
===
--- clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
+++ clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
@@ -47,7 +47,7 @@
 
 // CHECK-LABEL: define{{.*}} void @test_aligned_alloc(
 extern "C" void test_aligned_alloc() {
-  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
+  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 allocalign noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
   // CHECK: call void @_ZdlPvSt11align_val_t({{.*}}, i64 noundef 4) [[ATTR_BUILTIN_DELETE:#[^ ]*]]
   __builtin_operator_delete(__builtin_operator_new(4, std::align_val_t(4)), std::align_val_t(4));
 }
Index: clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
===
--- clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
+++ clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
@@ -8,7 +8,7 @@
 // CHECK-NEXT:[[ALIGN_ADDR:%.*]] = alloca i32, align 4
 // CHECK-NEXT:store i