Skip to content

Commit

Permalink
Conditionally define Test macro to avoid spurious rewriter warnings
Browse files Browse the repository at this point in the history
The spurious warnings are caused because we don't (and should not) rewrite the
test runner source file. See issue #439 for context.
  • Loading branch information
ayrtonm committed Oct 22, 2024
1 parent e8a6971 commit 57d55ec
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion misc/test_runner/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
add_library(ia2_test_runner STATIC test_runner.c)
target_include_directories(ia2_test_runner
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
PRIVATE ${CMAKE_SOURCE_DIR}/runtime/libia2/include)
15 changes: 13 additions & 2 deletions misc/test_runner/include/ia2_test_runner.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
#pragma once
#include <ia2.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>

#if !defined(IA2_TEST_RUNNER_SOURCE)
typedef void *ia2_test_fn;
#else
typedef void (*ia2_test_fn)(void);
#endif

struct fake_criterion_test {
void (*test)(void);
void (*init)(void);
ia2_test_fn test;
ia2_test_fn init;
int exit_code;
};

#if !defined(IA2_TEST_RUNNER_SOURCE)
#define Test(suite, name, ...) \
IA2_BEGIN_NO_WRAP \
void fake_criterion_##suite##_##name(void); \
IA2_END_NO_WRAP \
__attribute__((__section__("fake_criterion_tests"))) struct fake_criterion_test fake_criterion_##suite##_##name##_##test = { \
.test = fake_criterion_##suite##_##name, \
##__VA_ARGS__}; \
void fake_criterion_##suite##_##name(void)
#endif

#define cr_log_info(f, ...) printf(f "\n", ##__VA_ARGS__)
#define cr_log_error(f, ...) fprintf(stderr, f "\n", ##__VA_ARGS__)
Expand Down
1 change: 1 addition & 0 deletions misc/test_runner/test_runner.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define IA2_TEST_RUNNER_SOURCE
#include "include/ia2_test_runner.h"
#include <stdbool.h>
#include <stdio.h>
Expand Down
1 change: 1 addition & 0 deletions tools/rewriter/SourceRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ class FnPtrExpr : public RefactoringCallback {
auto *fn_ptr_expr = result.Nodes.getNodeAs<clang::DeclRefExpr>("fnPtrExpr");
assert(fn_ptr_expr != nullptr);

auto annotation = fn_ptr_expr->getDecl()->getAttr<clang::AnnotateAttr>();
assert(result.SourceManager != nullptr);
auto &sm = *result.SourceManager;

Expand Down

0 comments on commit 57d55ec

Please sign in to comment.