[frontend] Add tests of using single field struct

Summary:
When a single field struct is initialized with "type x{v}" form, the translated result is not straightforward.  For example,

```
struct t {
  int val_;
};

void foo(t x) {
  t y{x};
}
```
calls the copy constructor with `x`.  This is good.

```
void foo(int n) {
  t y{n};
}
```
assigns the integer `n` to `y.val_`.  This is good.

```
t get_v();

void foo() {
  t y{get_v()};
}
```

assigns return value of `get_v` to `y.val_`, rather than calling the copy constructor.  This is not
good, but doesn't matter for actual running; `&y.val_` is the same to `&y` and `t` value is the same
to `int` value.

Reviewed By: jvillard

Differential Revision: D26146578

fbshipit-source-id: 8a81bb1db
master
Sungkeun Cho 4 years ago committed by Facebook GitHub Bot
parent 12bcf119c8
commit 89c8e25deb

@ -203,4 +203,42 @@ void not_boolean_bad() {
}
}
struct double_fields_struct {
int v;
int a;
};
double_fields_struct get_double_fields_struct() {
double_fields_struct b;
b.v = 42;
b.a = 42;
return b;
}
void init_double_fields_struct_ok() {
double_fields_struct y{get_double_fields_struct()};
if (y.v != 42) {
int* p = nullptr;
*p = 42;
}
}
struct single_field_struct {
int v;
};
single_field_struct get_single_field_struct() {
single_field_struct b;
b.v = 42;
return b;
}
void FP_init_single_field_struct_ok() {
single_field_struct y{get_single_field_struct()};
if (y.v != 42) {
int* p = nullptr;
*p = 42;
}
}
} // namespace frontend

@ -32,6 +32,7 @@ codetoanalyze/cpp/pulse/deduplication.cpp, deduplication::templated_function_bad
codetoanalyze/cpp/pulse/deduplication.cpp, deduplication::templated_function_bad<int>, 3, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,passed as argument to `new` (modelled),return from call to `new` (modelled),assigned,when calling `deduplication::templated_delete_function<int>` here,parameter `a` of deduplication::templated_delete_function<int>,was invalidated by `delete`,use-after-lifetime part of the trace starts here,passed as argument to `new` (modelled),return from call to `new` (modelled),assigned,when calling `deduplication::templated_access_function<int>` here,parameter `a` of deduplication::templated_access_function<int>,invalid access occurs here]
codetoanalyze/cpp/pulse/exit_test.cpp, store_exit_null_bad, 0, NULLPTR_DEREFERENCE, no_bucket, ERROR, [invalidation part of the trace starts here,assigned,is the null pointer,use-after-lifetime part of the trace starts here,when calling `store_exit` here,parameter `x` of store_exit,invalid access occurs here]
codetoanalyze/cpp/pulse/folly_DestructorGuard.cpp, UsingDelayedDestruction::double_delete_bad, 2, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `this` of UsingDelayedDestruction::double_delete_bad,was invalidated by `delete`,use-after-lifetime part of the trace starts here,parameter `this` of UsingDelayedDestruction::double_delete_bad,invalid access occurs here]
codetoanalyze/cpp/pulse/frontend.cpp, frontend::FP_init_single_field_struct_ok, 4, NULLPTR_DEREFERENCE, no_bucket, ERROR, [invalidation part of the trace starts here,assigned,is the null pointer,use-after-lifetime part of the trace starts here,assigned,invalid access occurs here]
codetoanalyze/cpp/pulse/frontend.cpp, frontend::call_Frontend_constructor2_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [invalidation part of the trace starts here,assigned,is the null pointer,use-after-lifetime part of the trace starts here,assigned,invalid access occurs here]
codetoanalyze/cpp/pulse/frontend.cpp, frontend::call_Frontend_constructor_bad, 4, NULLPTR_DEREFERENCE, no_bucket, ERROR, [invalidation part of the trace starts here,assigned,is the null pointer,use-after-lifetime part of the trace starts here,assigned,invalid access occurs here]
codetoanalyze/cpp/pulse/frontend.cpp, frontend::call_set_field_via_local_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [invalidation part of the trace starts here,assigned,is the null pointer,use-after-lifetime part of the trace starts here,assigned,invalid access occurs here]

Loading…
Cancel
Save