Add nonnull to return attributes when the function has ReturnsNonNullAttr (e.g. operator new), guarded by !NullPointerIsValid. Add nonnull to pointer parameters with __attribute__((nonnull)), both per-parameter and function-level forms. Thread targetDecl into constructFunctionArgumentAttributes and build a parallel ParmVarDecl array in the zip_equal loop to access parameter-level attributes without manual index arithmetic. Restrict->noalias handling has been moved to #191483.
24 lines
1.3 KiB
C
24 lines
1.3 KiB
C
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
|
|
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll
|
|
// RUN: FileCheck --check-prefix=LLVM --input-file=%t-cir.ll %s
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll
|
|
// RUN: FileCheck --check-prefix=OGCG --input-file=%t.ll %s
|
|
|
|
// __attribute__((nonnull)) on individual parameter.
|
|
void take_nonnull(int *p) __attribute__((nonnull(1)));
|
|
void take_nonnull(int *p) { *p = 42; }
|
|
// CIR: cir.func {{.*}} @take_nonnull(%arg0: !cir.ptr<!s32i>
|
|
// CIR-SAME: {llvm.nonnull, llvm.noundef}
|
|
// LLVM: define {{.*}} void @take_nonnull(ptr noundef nonnull %{{.*}})
|
|
// OGCG: define {{.*}} void @take_nonnull(ptr noundef nonnull %{{.*}})
|
|
|
|
// Function-level nonnull applying to all pointer params.
|
|
__attribute__((nonnull)) void take_all_nonnull(int *a, int *b);
|
|
void take_all_nonnull(int *a, int *b) { *a = *b; }
|
|
// CIR: cir.func {{.*}} @take_all_nonnull(
|
|
// CIR-SAME: %arg0: !cir.ptr<!s32i> {llvm.nonnull, llvm.noundef}
|
|
// CIR-SAME: %arg1: !cir.ptr<!s32i> {llvm.nonnull, llvm.noundef}
|
|
// LLVM: define {{.*}} void @take_all_nonnull(ptr noundef nonnull %{{.*}}, ptr noundef nonnull %{{.*}})
|
|
// OGCG: define {{.*}} void @take_all_nonnull(ptr noundef nonnull %{{.*}}, ptr noundef nonnull %{{.*}})
|