Skip to content

Commit

Permalink
Fix a null compare against an opaque struct.
Browse files Browse the repository at this point in the history
  • Loading branch information
sheredom committed Apr 9, 2024
1 parent bc61349 commit eb67293
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 7 deletions.
11 changes: 11 additions & 0 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,14 @@ UTEST(c, Near) {
}

UTEST(c, Todo) { UTEST_SKIP("Not yet implemented!"); }

// TODO: TCC cannot handle comparing null opaque structs at all.
#if !defined(__TINYC__)
struct Opaque;

UTEST(c, Opaque) {
struct Opaque *opaque = NULL;
EXPECT_EQ(NULL, opaque);
ASSERT_EQ(NULL, opaque);
}
#endif
11 changes: 11 additions & 0 deletions test/test11.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,14 @@ UTEST(c11, Near) {
}

UTEST(c11, Todo) { UTEST_SKIP("Not yet implemented!"); }

// TODO: TCC cannot handle comparing null opaque structs at all.
#if !defined(__TINYC__)
struct Opaque;

UTEST(c11, Opaque) {
struct Opaque *opaque = NULL;
EXPECT_EQ(NULL, opaque);
ASSERT_EQ(NULL, opaque);
}
#endif
17 changes: 17 additions & 0 deletions test/test11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,20 @@ UTEST(cpp11, Null) {
}

#endif

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
#endif

struct Opaque;

UTEST(cpp11, Opaque) {
struct Opaque *opaque = nullptr;
EXPECT_EQ(nullptr, opaque);
ASSERT_EQ(nullptr, opaque);
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif
17 changes: 17 additions & 0 deletions test/test14.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,20 @@ UTEST(cpp14, Null) {
}

#endif

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
#endif

struct Opaque;

UTEST(cpp14, Opaque) {
struct Opaque *opaque = nullptr;
EXPECT_EQ(nullptr, opaque);
ASSERT_EQ(nullptr, opaque);
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif
17 changes: 17 additions & 0 deletions test/test17.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,20 @@ UTEST(cpp17, Null) {
}

#endif

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
#endif

struct Opaque;

UTEST(cpp17, Opaque) {
struct Opaque *opaque = nullptr;
EXPECT_EQ(nullptr, opaque);
ASSERT_EQ(nullptr, opaque);
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif
11 changes: 11 additions & 0 deletions test/test99.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,14 @@ UTEST(c99, Near) {
}

UTEST(c99, Todo) { UTEST_SKIP("Not yet implemented!"); }

// TODO: TCC cannot handle comparing null opaque structs at all.
#if !defined(__TINYC__)
struct Opaque;

UTEST(c99, Opaque) {
struct Opaque *opaque = NULL;
EXPECT_EQ(NULL, opaque);
ASSERT_EQ(NULL, opaque);
}
#endif
10 changes: 3 additions & 7 deletions utest.h
Original file line number Diff line number Diff line change
Expand Up @@ -674,24 +674,20 @@ utest_type_printer(long long unsigned int i) {

#if defined(__cplusplus) && (__cplusplus >= 201103L)
#define UTEST_AUTO(x) auto
#elif !defined(__cplusplus)

#if defined(__clang__)
#elif defined(__clang__)
/* clang-format off */
/* had to disable clang-format here because it malforms the pragmas */
#define UTEST_AUTO(x) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wgnu-auto-type\"") __auto_type \
_Pragma("clang diagnostic pop")
/* clang-format on */
#elif !defined(__clang__) && defined(__GNUC__) && !defined(__cplusplus)
#define UTEST_AUTO(x) __auto_type
#else
#define UTEST_AUTO(x) __typeof__(x + 0)
#endif

#else
#define UTEST_AUTO(x) typeof(x + 0)
#endif

#if defined(__clang__)
#define UTEST_STRNCMP(x, y, size) \
_Pragma("clang diagnostic push") \
Expand Down

0 comments on commit eb67293

Please sign in to comment.