@@ -1,6 +1,5 @@ | |||
IF (ENABLE_CLANG_PLUGIN MATCHES "ON") | |||
cmake_minimum_required(VERSION 3.9) | |||
# Clang plugin for static analysis | |||
PROJECT(RspamdClangPlugin) | |||
if (NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") | |||
@@ -14,6 +13,13 @@ IF (ENABLE_CLANG_PLUGIN MATCHES "ON") | |||
ADD_DEFINITIONS(${LLVM_DEFINITIONS}) | |||
find_package(Clang REQUIRED) | |||
set(clang_libs | |||
clangAST | |||
clangBasic | |||
clangFrontend) | |||
message(STATUS "Found LibClang in: ${CLANG_INSTALL_PREFIX}") | |||
include_directories(${CLANG_INCLUDE_DIRS}) | |||
SET(CLANGPLUGINSRC plugin.cc printf_check.cc) | |||
@@ -22,7 +28,9 @@ IF (ENABLE_CLANG_PLUGIN MATCHES "ON") | |||
SET_TARGET_PROPERTIES(rspamd-clang PROPERTIES | |||
COMPILE_FLAGS "-O2 -Wall -Wextra -Wno-unused-parameter -Werror" | |||
LINKER_LANGUAGE CXX) | |||
set_property(TARGET rspamd-clang APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--no-undefined -Wl,--as-needed") | |||
IF(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") | |||
set_property(TARGET rspamd-clang APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--no-undefined -Wl,--as-needed") | |||
ENDIF() | |||
find_library(found_LLVM LLVM HINTS ${LLVM_LIBRARY_DIRS}) | |||
if(found_LLVM) | |||
@@ -33,9 +41,5 @@ IF (ENABLE_CLANG_PLUGIN MATCHES "ON") | |||
target_link_libraries(rspamd-clang PRIVATE ${llvm_libs}) | |||
endif() | |||
set(clang_libs | |||
clangAST | |||
clangBasic | |||
clangFrontend) | |||
target_link_libraries(rspamd-clang PRIVATE ${clang_libs}) | |||
ENDIF() |
@@ -590,11 +590,22 @@ namespace rspamd { | |||
size_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx) | |||
{ | |||
if (sizeof (size_t) == sizeof (long)) { | |||
return check_builtin_type (arg, | |||
ctx, | |||
{BuiltinType::Kind::ULong, | |||
BuiltinType::Kind::Long}, | |||
"%z"); | |||
if (sizeof (long long) == sizeof (long)) { | |||
return check_builtin_type (arg, | |||
ctx, | |||
{BuiltinType::Kind::ULong, | |||
BuiltinType::Kind::Long, | |||
BuiltinType::Kind::LongLong, | |||
BuiltinType::Kind::ULongLong}, | |||
"%z"); | |||
} | |||
else { | |||
return check_builtin_type (arg, | |||
ctx, | |||
{BuiltinType::Kind::ULong, | |||
BuiltinType::Kind::Long}, | |||
"%z"); | |||
} | |||
} | |||
else if (sizeof (size_t) == sizeof (int)) { | |||
return check_builtin_type (arg, |
@@ -63,7 +63,7 @@ ENDMACRO(AddModules MLIST WLIST) | |||
# Rspamd core components | |||
IF (ENABLE_CLANG_PLUGIN MATCHES "ON") | |||
SET(CMAKE_C_FLAGS | |||
"${CMAKE_C_FLAGS} -Xclang -load -Xclang ${CMAKE_CURRENT_BINARY_DIR}/../clang-plugin/librspamd-clang.so -Xclang -add-plugin -Xclang rspamd-ast") | |||
"${CMAKE_C_FLAGS} -Xclang -load -Xclang ${CMAKE_CURRENT_BINARY_DIR}/../clang-plugin/librspamd-clang${CMAKE_SHARED_LIBRARY_SUFFIX} -Xclang -add-plugin -Xclang rspamd-ast") | |||
IF(CLANG_EXTRA_PLUGINS_LIBS) | |||
FOREACH(_lib ${CLANG_EXTRA_PLUGINS_LIBS}) | |||
SET(CMAKE_C_FLAGS |
@@ -395,7 +395,7 @@ rspamd_task_load_message (struct rspamd_task *task, | |||
if (offset > (gulong)st.st_size) { | |||
msg_err_task ("invalid offset %ul (%ul available) for shm " | |||
"segment %s", offset, st.st_size, fp); | |||
"segment %s", offset, (gulong)st.st_size, fp); | |||
munmap (map, st.st_size); | |||
close (fd); | |||
@@ -412,7 +412,7 @@ rspamd_task_load_message (struct rspamd_task *task, | |||
if (shmem_size > (gulong)st.st_size) { | |||
msg_err_task ("invalid length %ul (%ul available) for %s " | |||
"segment %s", shmem_size, st.st_size, ft, fp); | |||
"segment %s", shmem_size, (gulong)st.st_size, ft, fp); | |||
munmap (map, st.st_size); | |||
close (fd); | |||