-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "[-Wunsafe-buffer-usage] Handle unevaluated contexts t…
…hat contain unsafe buffer usages"" This reverts commit 7bf5f46 and adding -frtti flag to support PS4/PS5 builds.
- Loading branch information
MalavikaSamak
committed
Apr 19, 2023
1 parent
a2d1611
commit 9516419
Showing
4 changed files
with
198 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-unevaluated-context.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -fdiagnostics-parseable-fixits -fsyntax-only %s 2>&1 | FileCheck %s | ||
|
||
namespace std { | ||
class type_info; | ||
class bad_cast; | ||
class bad_typeid; | ||
} | ||
using size_t = __typeof(sizeof(int)); | ||
void *malloc(size_t); | ||
|
||
void foo(...); | ||
int bar(int *ptr); | ||
|
||
void uneval_context_fix_pointer_dereference() { | ||
auto p = new int[10]; | ||
// CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span<int> p" | ||
// CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{" | ||
// CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}" | ||
|
||
int tmp = p[5]; | ||
typeid(foo(*p)); | ||
// CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:14-[[@LINE-1]]:15}:"" | ||
// CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:16}:"[0]" | ||
_Generic(*p, int: 2, float: 3); | ||
// CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:12-[[@LINE-1]]:13}:"" | ||
// CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:14-[[@LINE-2]]:14}:"[0]" | ||
} | ||
|
||
void uneval_context_fix_pointer_array_access() { | ||
auto p = new int[10]; | ||
// CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span<int> p" | ||
// CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{" | ||
// CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}" | ||
|
||
int tmp = p[5]; | ||
typeid(foo(p[5])); | ||
_Generic(p[2], int: 2, float: 3); | ||
} | ||
|
||
void uneval_context_fix_pointer_reference() { | ||
auto p = new int[10]; | ||
// CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span<int> p" | ||
// CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{" | ||
// CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}" | ||
|
||
int tmp = p[5]; | ||
typeid(bar(p)); | ||
// CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:15-[[@LINE-1]]:15}:".data()" | ||
} | ||
|
||
// The FixableGagdtes are not working in the following scenarios: | ||
// 1. sizeof(DRE) | ||
// 2. typeid(DRE) | ||
// 3. __typeof(DRE) | ||
// 4. _Generic(expr, type_1: DRE, type_2:) | ||
// 5. decltype(DRE) var = y; | ||
// 6. noexcept(DRE); | ||
// This is becauste the UPC and ULC context matchers do not handle these contexts | ||
// and almost all FixableGagdets currently depend on these matchers. | ||
|
||
// FIXME: Emit fixits for each of the below use. | ||
void uneval_context_fix_pointer_dereference_not_handled() { | ||
auto p = new int[10]; | ||
int tmp = p[5]; | ||
|
||
foo(sizeof(*p), sizeof(decltype(*p))); | ||
__typeof(*p) x; | ||
int *q = (int *)malloc(sizeof(*p)); | ||
int y = sizeof(*p); | ||
__is_pod(__typeof(*p)); | ||
__is_trivially_constructible(__typeof(*p), decltype(*p)); | ||
_Generic(*p, int: 2, float: 3); | ||
_Generic(1, int: *p, float: 3); | ||
_Generic(1, int: 2, float: *p); | ||
decltype(*p) var = y; | ||
noexcept(*p); | ||
typeid(*p); | ||
} | ||
|
50 changes: 50 additions & 0 deletions
50
clang/test/SemaCXX/warn-unsafe-buffer-usage-warning-unevaluated-context.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// RUN: %clang_cc1 -std=c++20 -Wno-all -Wunsafe-buffer-usage -fblocks -include %s -verify %s | ||
|
||
// RUN: %clang -x c++ -frtti -fsyntax-only -fblocks -include %s %s 2>&1 | FileCheck --allow-empty %s | ||
// RUN: %clang_cc1 -std=c++11 -fblocks -include %s %s 2>&1 | FileCheck --allow-empty %s | ||
// RUN: %clang_cc1 -std=c++20 -fblocks -include %s %s 2>&1 | FileCheck --allow-empty %s | ||
// CHECK-NOT: [-Wunsafe-buffer-usage] | ||
|
||
#ifndef INCLUDED | ||
#define INCLUDED | ||
#pragma clang system_header | ||
|
||
// no spanification warnings for system headers | ||
void foo(...); // let arguments of `foo` to hold testing expressions | ||
#else | ||
|
||
namespace std { | ||
class type_info; | ||
class bad_cast; | ||
class bad_typeid; | ||
} | ||
using size_t = __typeof(sizeof(int)); | ||
void *malloc(size_t); | ||
|
||
void foo(int v) { | ||
} | ||
|
||
void foo(int *p){} | ||
|
||
void uneval_context_fix() { | ||
auto p = new int[10]; // expected-warning{{'p' is an unsafe pointer used for buffer access}} | ||
|
||
// Warn on the following DREs | ||
_Generic(1, int: p[2], float: 3); // expected-note{{used in buffer access here}} | ||
|
||
// Do not warn for following DREs | ||
auto q = new int[10]; | ||
foo(sizeof(q[1]), // no-note | ||
sizeof(decltype(q[1]))); // no-note | ||
__typeof(q[5]) x; // no-note | ||
int *r = (int *)malloc(sizeof(q[5])); // no-note | ||
int y = sizeof(q[5]); // no-note | ||
__is_pod(__typeof(q[5])); // no-note | ||
__is_trivially_constructible(__typeof(q[5]), decltype(q[5])); // no-note | ||
_Generic(q[1], int: 2, float: 3); // no-note | ||
_Generic(1, int: 2, float: q[3]); // no-note | ||
decltype(q[2]) var = y; // no-note | ||
noexcept(q[2]); // no-note | ||
typeid(q[3]); // no-note | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters