Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

暗黙的cast する ノード にマッチする matcher を作成 #36

Merged
merged 12 commits into from
Jan 16, 2023
Merged
Prev Previous commit
Next Next commit
feat: 関数呼び出し時 暗黙の型cast matcher を追加
  • Loading branch information
Ran350 committed Jan 16, 2023
commit 469de84af93050b89d037da43b3f08fd114f578e
20 changes: 20 additions & 0 deletions clang-query/downcast-bug/func-arg-imp-downcast.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <time.h>

void timet_to_int(int n) {
printf("%d\n", n);
return;
}

int main(void) {
time_t t = INT_MAX + 1;
timet_to_int(t);
timet_to_int((time_t)INT_MAX + 1);

return 0;
}
20 changes: 20 additions & 0 deletions clang-query/downcast-bug/func-arg-imp-downcast.matcher
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
set bind-root true
set print-matcher true
enable output dump

matcher callExpr(hasAnyArgument(implicitCastExpr(hasImplicitDestinationType(asString("int")),has(expr(hasType(anyOf(asString("time_t"),asString("__time_t"),asString("long"))))))))

# 引数のいずれかが int 型の関数の呼び出し式のうち、引数に time_t 型の式を代入している式 への Matcher

# callExpr(
# hasAnyArgument(implicitCastExpr(
# hasImplicitDestinationType(asString("int")),
# has(expr(
# hasType(anyOf(
# asString("time_t"),
# asString("__time_t"),
# asString("long")
# ))
# ))
# )
# ))