Skip to content

Commit

Permalink
formatting fixes, suppress expected warnings and fix things our imple…
Browse files Browse the repository at this point in the history
…mentation does not support
  • Loading branch information
nlsandler committed Oct 26, 2023
1 parent a66e839 commit 6b474d4
Show file tree
Hide file tree
Showing 60 changed files with 807 additions and 570 deletions.
2 changes: 1 addition & 1 deletion expected_results.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions generate_expected_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def main() -> None:

parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group()
group.add_argument("--since_commit", default=None)
group.add_argument("--since-commit", default=None)
group.add_argument("--all", action="store_true")

args = parser.parse_args()
Expand Down Expand Up @@ -160,7 +160,6 @@ def main() -> None:
result = basic.gcc_compile_and_run(source_files, opts)

# record the result

result_dict: dict[str, Any] = {"return_code": result.returncode}
if result.stdout:
result_dict["stdout"] = result.stdout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "global_struct.h"

void update_struct(void) {
global.arr[1] = global.arr[0]*2;
global.arr[1] = global.arr[0] * 2;
global.d = 5.0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ int main(void) {
if (global.arr[1] != 4) {
return 1;
}
if (global.d != 4.0) {
if (global.d != 5.0) {
return 2;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
int validate_full_initialization(struct s *ptr) {
if (strcmp(ptr->one_msg, "I'm a struct!") || ptr->two_arr[0] != 's' ||
ptr->two_arr[1] != 'u' || ptr->two_arr[2] != 'p' ||
ptr->three_self_ptr != ptr || ptr->four_d != 2e12 || *ptr->five_d_ptr != 2e12) {
ptr->three_self_ptr != ptr || ptr->four_d != 2e12 ||
*ptr->five_d_ptr != 2e12) {
return 0;
}

Expand Down Expand Up @@ -56,7 +57,8 @@ int validate_two_structs(struct s *ptr1, struct s *ptr2) {
ptr2->two_arr[0] != 'x' || ptr2->two_arr[1] != 'y' ||
ptr2->three_self_ptr !=
ptr1 || // ptr2->three_self_ptr is ptr1, not to itself
ptr2->four_d != 150.0 || *ptr1->five_d_ptr != 123.4) {
ptr2->four_d != 150.0 ||
*ptr1->five_d_ptr != 123.4) {
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ int strcmp(char *s1, char *s2);
void *malloc(unsigned long size);
void *calloc(unsigned long nmemb, unsigned long size);


// struct type def
struct s {
char *one_msg;
Expand All @@ -30,7 +29,6 @@ struct s {
double *five_d_ptr;
};


// validation functions defined in library
int validate_full_initialization(struct s *ptr);
int validate_partial_initialization(struct s *ptr, char *expected_msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

#include "auto_struct_initializers.h"

double get_double() {
#ifdef SUPPRESS_WARNINGS
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#endif

double get_double(void) {
return 2e12;
}

Expand All @@ -17,9 +21,10 @@ int test_full_initialization(void) {
struct s full = {
// use string literals to initialize both pointers and arrays
"I'm a struct!", "sup",
&full, // initialize member with pointer to self
get_double(), // initialize member with result of function call
&(full.four_d) // initialize member with pointer to other member in self
&full, // initialize member with pointer to self
get_double(), // initialize member with result of function call
&(full.four_d) // initialize member with pointer to other member in
// self
};

return validate_full_initialization(&full);
Expand Down Expand Up @@ -57,7 +62,8 @@ int test_implicit_type_conversions(void) {

// case 4: initialize with single expression instead of compound initiailizer
int test_single_exp_initializer(void) {
struct s s1 = {"Yet another string", "xy", &s1, 150.0};
double d = 123.4;
struct s s1 = {"Yet another string", "xy", &s1, 150.0, &d};
struct s s2 = s1;

return validate_two_structs(&s1, &s2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

#include "nested_auto_struct_initializers.h"

#ifdef SUPPRESS_WARNINGS
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#ifdef __clang__
#pragma clang diagnostic ignored "-Wliteral-conversion"
#endif
#endif

// case 1: fully initialized struct (include some implicit conversions while
// we're at it)
int test_full_initialization(void) {
Expand All @@ -28,7 +35,6 @@ int test_partial_initialization(void) {
},
"Partial"}; // leave four_d uninitialized


return validate_partial_initialization(&partial);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ int test_uninitialized(void) {
}

// validate elements in struct inner
if (all_zeros.two_struct.one_i ||
all_zeros.two_struct.two_arr[0] | all_zeros.two_struct.two_arr[1] ||
all_zeros.two_struct.two_arr[2] || all_zeros.two_struct.three_u) {
if (all_zeros.two_struct.one_i || all_zeros.two_struct.two_arr[0] ||
all_zeros.two_struct.two_arr[1] || all_zeros.two_struct.two_arr[2] ||
all_zeros.two_struct.three_u) {
return 0;
}

Expand All @@ -35,8 +35,6 @@ int test_uninitialized(void) {
"Hello!"}; // leave d uninitialized
*/
int test_partially_initialized(void) {


// validate elements in struct outer
if (partial.one_l != 100l || strcmp(partial.three_msg, "Hello!")) {
return 0;
Expand Down Expand Up @@ -104,7 +102,6 @@ int test_fully_intialized(void) {
};
*/
int test_implicit_conversions(void) {

// validate elements in struct outer
if (converted.one_l != 10l || converted.three_msg != 0 ||
converted.four_d != 9223372036854777856.0) {
Expand All @@ -129,7 +126,6 @@ int test_implicit_conversions(void) {
{6, {7, "cd", 8}, "Message", 9}};
*/
int test_array_of_structs(void) {

// leave last element uninitialized

// validate outer members of array element 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@

#include "nested_static_struct_initializers.h"


#ifdef SUPPRESS_WARNINGS
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#ifdef __clang__
#pragma clang diagnostic ignored "-Wconstant-conversion"
#pragma clang diagnostic ignored "-Wimplicit-const-int-float-conversion"
#pragma clang diagnostic ignored "-Wliteral-conversion"
#else
#pragma GCC diagnostic ignored "-Woverflow"
#endif
#endif

// structs defined here
// validation functions defined in library

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// case 1: struct with no explicit initializer should be all zeros
// struct s uninitialized;
int test_uninitialized(void) {

// make sure all elements are zero
if (uninitialized.one_d || uninitialized.two_msg ||
uninitialized.three_arr[0] || uninitialized.three_arr[1] ||
Expand Down Expand Up @@ -42,10 +41,11 @@ int test_partially_initialized(void) {
// case 3: partially initialized array w/in struct
// struct s partial with_array = {3.0, "!", {1}, 2};
int test_partial_inner_init(void) {

// validate explicitly initialzed elements
if (partial_with_array.one_d != 3.0 || strcmp(partial_with_array.two_msg, "!") ||
partial_with_array.three_arr[0] != 1 || partial_with_array.four_i != 2) {
if (partial_with_array.one_d != 3.0 ||
strcmp(partial_with_array.two_msg, "!") ||
partial_with_array.three_arr[0] != 1 ||
partial_with_array.four_i != 2) {
return 0;
}

Expand All @@ -67,8 +67,6 @@ int test_partial_inner_init(void) {
};
*/
int test_implicit_conversion(void) {


// validate elements
if (converted.one_d != 1152921504606846976.0 || converted.two_msg ||
converted.three_arr[0] != 'a' || converted.three_arr[1] != 'b' ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@

#include "static_struct_initializers.h"

#ifdef SUPPRESS_WARNINGS
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#ifdef __clang__
#pragma clang diagnostic ignored "-Wconstant-conversion"
#pragma clang diagnostic ignored "-Wimplicit-const-int-float-conversion"
#else
#pragma GCC diagnostic ignored "-Woverflow"
#endif
#endif

// case 1: struct with no explicit initializer should be all zeros
struct s uninitialized;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@
* the client; this is a common idiom for hiding a library's implementation
* details */

#ifdef SUPPRESS_WARNINGS
#ifdef __clang__
#pragma clang diagnostic ignored "-Wincompatible-library-redeclaration"
#else
#pragma GCC diagnostic ignored "-Wbuiltin-declaration-mismatch"
#endif
#endif

// library functoins
int strcmp(char *s1, char *s2);
int puts(char *s);
void *malloc(unsigned long size);

struct s {
int member1;
double member2;
char *member3;
};


// make a struct
struct s *create_struct(int i, double d, char *s) {
struct s *ptr = malloc(sizeof(struct s));
Expand All @@ -20,15 +30,13 @@ struct s *create_struct(int i, double d, char *s) {
return ptr;
}


// modify a struct
void increment_struct(struct s *ptr) {
ptr->member1 = ptr->member1 + 1;
ptr->member2 = ptr->member2 + 1;
ptr->member3 = ptr->member3;
}


// read struct members
int check_struct(struct s *ptr, int expected_i, double expected_d,
char *expected_s) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#include "param_struct_pointer.h"

int access_members_through_pointer(struct outer *ptr, char expected_a, char expected_b, double expected_d, int expected_i) {
int access_members_through_pointer(struct outer *ptr, char expected_a,
char expected_b, double expected_d,
int expected_i) {
if (ptr->a != expected_a) {
return 0;
}
Expand All @@ -19,10 +21,11 @@ int access_members_through_pointer(struct outer *ptr, char expected_a, char expe
return 0;
}

return 1; // success
return 1; // success
}

void update_members_through_pointer(struct outer *ptr, char a, char b, struct inner *inner_ptr) {
void update_members_through_pointer(struct outer *ptr, char a, char b,
struct inner *inner_ptr) {
ptr->a = a;
ptr->b = b;
ptr->substruct = *inner_ptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ int main(void) {
return 2;
}

return 0; // success
return 0; // success
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ int test_update_member_thru_retval(void) {
return 1; // success
}


// case 4: update whole structure member through pointer returned by funcall
int test_update_nested_struct_thru_retval(void) {
struct inner small = {12.0, 13};
Expand All @@ -72,7 +71,7 @@ int test_update_nested_struct_thru_retval(void) {
return 0;
}

return 1; // success
return 1; // success
}

int main(void) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// postfix operators have higher precedence than prefix
struct inner {
int inner_arr[3];
int inner_arr[3];
};

struct outer {
int a;
struct inner b;
int a;
struct inner b;
};

int main(void) {
struct outer array[4] = {{1, {{2, 3, 4}}},
{5, {{6, 7, 8}}},
{9, {{10, 11, 12}}},
{13, {{14, 15, 16}}}};
struct outer array[4] = {{1, {{2, 3, 4}}},
{5, {{6, 7, 8}}},
{9, {{10, 11, 12}}},
{13, {{14, 15, 16}}}};

int i = -array[2].b.inner_arr[1];
return i == -11;
int i = -array[2].b.inner_arr[1];
return i == -11;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
struct s {
int a;
int a;
};
int main(void) {
// struct member operator (.) can be separate by whitespace from
// both struct and field name
struct s foo;
foo. a=10;
int b = foo .a ;
// struct member operator (.) can be separate by whitespace from
// both struct and field name
struct s foo;
foo .a = 10;
int b = foo .a;

return foo . a == b;
return foo . a == b;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
struct s {
int E10;
int E10;
};

int main(void) {
struct s x1 = {3};
return x1.E10; // lex correctly, recognizing that 1.E10 is not a constant
struct s x1 = {3};
return x1.E10; // lex correctly, recognizing that 1.E10 is not a constant
}
Loading

0 comments on commit 6b474d4

Please sign in to comment.