Kaydet (Commit) 645583df authored tarafından Stephan Bergmann's avatar Stephan Bergmann

New compilerplugins/clang unit tests

...to check that loplugin produces warnings/errors as expected:

* Clang has a -verify switch that makes it easy to write test input .cxx files
  that list in comments all the warnings/errors that are expected, and let Clang
  check those expectations instead of generating object code.  See
  include/clang/Frontend/VerifyDiagnosticConsumer.h in the Clang source tree for
  documentation.

* Introduce a CompilerTest gbuild class that uses the existing LinkTarget class
  as much as possible.  Checking the input files is implicitly phony, as the
  compilation step doesn't generate any object files, and the link step does
  nothing because there is no gb_LinkTarget_set_targettype for CompilerTest.
  The setup at least works for Clang on Linux (will need adaptions for Clang on
  Windows; compilers other than Clang are not relevant for now given this is
  used to check compilerplugins).

* Definition of gb_CFLAGS_WERROR in solenv/gbuild/platform/com_GCC_defs.mk needs
  to be lazy ('=' vs. ':=') so that CompilerTest can override it:  The Clang
  -verify mode wants the input files to specify whether the loplugin diagnostics
  are warnings or errros, so they consistently need to be errors independent of
  --enable-werror configuration.

* A first (example) test is in compilerplugins/clang/test/salbool.cxx.  The
  corresponding gbuild CompilerTest instance is in
  solenv/CompilerTest_compilerplugins_clang.mk for now.  The reason for that odd
  split across compilerplugins/ and solenv/ is that there is no
  compilerplugins/Modules_compilerplugins.mk file, so this setup is the easiest
  hack for now (to be cleaned up).  (Another area that could be improved is that
  all test files need to be listed explicitly in the CompilerTest_*.mk file,
  instead of, say, using all .c/.cxx/.m/.mm files in a specified directory.)

* The test is run somewhat late during a top-level 'make', after loplugin has
  already been used in compilation.  But it can be run manually (e.g., 'make
  solenv') when making changes to loplugin during development.

Change-Id: I01e12fb84887d264ac03ef2484807458c2075af4
üst 10efab2b
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <sal/config.h>
#include <sal/types.h>
struct S {
sal_Bool b; // expected-error {{FieldDecl, use "bool" instead of "sal_Bool" [loplugin:salbool]}}
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; fill-column: 100 -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
$(eval $(call gb_CompilerTest_CompilerTest,compilerplugins_clang))
$(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \
compilerplugins/clang/test/salbool \
))
# vim: set noet sw=4 ts=4:
...@@ -33,4 +33,10 @@ endif ...@@ -33,4 +33,10 @@ endif
endif endif
endif endif
ifneq ($(COMPILER_PLUGINS),)
$(eval $(call gb_Module_add_check_targets,solenv, \
CompilerTest_compilerplugins_clang \
))
endif
# vim: set shiftwidth=4 tabstop=4 noexpandtab: # vim: set shiftwidth=4 tabstop=4 noexpandtab:
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; fill-column: 100 -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
define gb_CompilerTest_CompilerTest
$(call gb_CompilerTest__CompilerTest_impl,$(1),$(call gb_CompilerTest_get_linktarget,$(1)))
endef
# call gb_CompilerTest__CompilerTest_impl,compilertest,linktarget
define gb_CompilerTest__CompilerTest_impl
$(call gb_LinkTarget_LinkTarget,$(2),CompilerTest_$(1),NONE)
$(call gb_LinkTarget_get_target,$(2)): COMPILER_TEST := $(true)
$(call gb_LinkTarget_get_target,$(2)): ENABLE_WERROR := $(true)
$(call gb_CompilerTest_get_target,$(1)): $(call gb_LinkTarget_get_target,$(2))
$(call gb_CompilerTest_get_clean_target,$(1)): $(call gb_LinkTarget_get_clean_target,$(2))
$$(eval $$(call gb_Module_register_target,$(call gb_CompilerTest_get_target,$(1)),$(call gb_CompilerTest_get_clean_target,$(1))))
$(call gb_Helper_make_userfriendly_targets,$(1),CompilerTest)
endef
define gb_CompilerTest__forward_to_Linktarget
gb_CompilerTest_$(1) = $$(call gb_LinkTarget_$(1),$$(call gb_CompilerTest_get_linktarget,$$(1)),$$(2),$$(3),CompilerTest_$$(1))
endef
$(eval $(foreach method, \
add_cobject \
add_cobjects \
add_cxxobject \
add_cxxobjects \
add_exception_objects \
add_objcobject \
add_objcobjects \
add_objcxxobject \
add_objcxxobjects \
, \
$(call gb_CompilerTest__forward_to_Linktarget,$(method)) \
))
# vim: set noet sw=4 ts=4:
...@@ -135,7 +135,7 @@ $(call gb_CObject_get_target,%) : $(call gb_CObject_get_source,$(SRCDIR),%) $(gb ...@@ -135,7 +135,7 @@ $(call gb_CObject_get_target,%) : $(call gb_CObject_get_source,$(SRCDIR),%) $(gb
$(call gb_CObject__tool_command,$*,$<) $(call gb_CObject__tool_command,$*,$<)
else else
$(call gb_CObject_get_target,%) : $(call gb_CObject_get_source,$(SRCDIR),%) $(call gb_CObject_get_target,%) : $(call gb_CObject_get_source,$(SRCDIR),%)
$(call gb_Output_announce,$*.c,$(true),C ,3) $(call gb_Output_announce,$*.c,$(true),$(if $(COMPILER_TEST),C? ,C ),3)
$(call gb_CObject__command_pattern,$@,$(T_CFLAGS) $(T_CFLAGS_APPEND),$<,$(call gb_CObject_get_dep_target,$*),$(COMPILER_PLUGINS)) $(call gb_CObject__command_pattern,$@,$(T_CFLAGS) $(T_CFLAGS_APPEND),$<,$(call gb_CObject_get_dep_target,$*),$(COMPILER_PLUGINS))
endif endif
...@@ -186,7 +186,7 @@ $(call gb_CxxObject_get_target,%) : $(call gb_CxxObject_get_source,$(SRCDIR),%) ...@@ -186,7 +186,7 @@ $(call gb_CxxObject_get_target,%) : $(call gb_CxxObject_get_source,$(SRCDIR),%)
$(call gb_CxxObject__tool_command,$*,$<) $(call gb_CxxObject__tool_command,$*,$<)
else else
$(call gb_CxxObject_get_target,%) : $(call gb_CxxObject_get_source,$(SRCDIR),%) $(call gb_CxxObject_get_target,%) : $(call gb_CxxObject_get_source,$(SRCDIR),%)
$(call gb_Output_announce,$*.cxx,$(true),CXX,3) $(call gb_Output_announce,$*.cxx,$(true),$(if $(COMPILER_TEST),C??,CXX),3)
$(eval $(gb_CxxObject__set_pchflags)) $(eval $(gb_CxxObject__set_pchflags))
$(call gb_CObject__command_pattern,$@,$(T_CXXFLAGS) $(T_CXXFLAGS_APPEND),$<,$(call gb_CxxObject_get_dep_target,$*),$(COMPILER_PLUGINS)) $(call gb_CObject__command_pattern,$@,$(T_CXXFLAGS) $(T_CXXFLAGS_APPEND),$<,$(call gb_CxxObject_get_dep_target,$*),$(COMPILER_PLUGINS))
endif endif
...@@ -320,7 +320,7 @@ $(call gb_ObjCxxObject_get_target,%) : $(call gb_ObjCxxObject_get_source,$(SRCDI ...@@ -320,7 +320,7 @@ $(call gb_ObjCxxObject_get_target,%) : $(call gb_ObjCxxObject_get_source,$(SRCDI
$(call gb_ObjCxxObject__tool_command,$*,$<) $(call gb_ObjCxxObject__tool_command,$*,$<)
else else
$(call gb_ObjCxxObject_get_target,%) : $(call gb_ObjCxxObject_get_source,$(SRCDIR),%) $(call gb_ObjCxxObject_get_target,%) : $(call gb_ObjCxxObject_get_source,$(SRCDIR),%)
$(call gb_Output_announce,$*.mm,$(true),OCX,3) $(call gb_Output_announce,$*.mm,$(true),$(if $(COMPILER_TEST),O?X,OCX),3)
$(call gb_CObject__command_pattern,$@,$(T_OBJCXXFLAGS) $(T_OBJCXXFLAGS_APPEND),$<,$(call gb_ObjCxxObject_get_dep_target,$*),$(COMPILER_PLUGINS)) $(call gb_CObject__command_pattern,$@,$(T_OBJCXXFLAGS) $(T_OBJCXXFLAGS_APPEND),$<,$(call gb_ObjCxxObject_get_dep_target,$*),$(COMPILER_PLUGINS))
endif endif
...@@ -347,7 +347,7 @@ $(call gb_ObjCObject_get_target,%) : $(call gb_ObjCObject_get_source,$(SRCDIR),% ...@@ -347,7 +347,7 @@ $(call gb_ObjCObject_get_target,%) : $(call gb_ObjCObject_get_source,$(SRCDIR),%
$(call gb_ObjCObject__tool_command,$*,$<) $(call gb_ObjCObject__tool_command,$*,$<)
else else
$(call gb_ObjCObject_get_target,%) : $(call gb_ObjCObject_get_source,$(SRCDIR),%) $(call gb_ObjCObject_get_target,%) : $(call gb_ObjCObject_get_source,$(SRCDIR),%)
$(call gb_Output_announce,$*.m,$(true),OCC,3) $(call gb_Output_announce,$*.m,$(true),$(if $(COMPILER_TEST),O?C,OCC),3)
$(call gb_CObject__command_pattern,$@,$(T_OBJCFLAGS) $(T_OBJCFLAGS_APPEND),$<,$(call gb_ObjCObject_get_dep_target,$*),$(COMPILER_PLUGINS)) $(call gb_CObject__command_pattern,$@,$(T_OBJCFLAGS) $(T_OBJCFLAGS_APPEND),$<,$(call gb_ObjCObject_get_dep_target,$*),$(COMPILER_PLUGINS))
endif endif
...@@ -614,6 +614,7 @@ $(call gb_LinkTarget_get_target,$(1)) : WARNINGS_NOT_ERRORS := ...@@ -614,6 +614,7 @@ $(call gb_LinkTarget_get_target,$(1)) : WARNINGS_NOT_ERRORS :=
$(call gb_LinkTarget_get_target,$(1)) : PLUGIN_WARNINGS_AS_ERRORS := $(call gb_LinkTarget_get_target,$(1)) : PLUGIN_WARNINGS_AS_ERRORS :=
$(call gb_LinkTarget_get_target,$(1)) : EXTERNAL_CODE := $(call gb_LinkTarget_get_target,$(1)) : EXTERNAL_CODE :=
$(call gb_LinkTarget_get_target,$(1)) : SOVERSIONSCRIPT := $(call gb_LinkTarget_get_target,$(1)) : SOVERSIONSCRIPT :=
$(call gb_LinkTarget_get_target,$(1)) : COMPILER_TEST :=
ifeq ($(gb_FULLDEPS),$(true)) ifeq ($(gb_FULLDEPS),$(true))
ifeq (depcache:,$(filter depcache,$(.FEATURES)):$(gb_PARTIAL_BUILD)) ifeq (depcache:,$(filter depcache,$(.FEATURES)):$(gb_PARTIAL_BUILD))
......
...@@ -44,6 +44,7 @@ gb_CliAssemblyTarget_get_target = $(WORKDIR)/CliAssemblyTarget/$(1).done ...@@ -44,6 +44,7 @@ gb_CliAssemblyTarget_get_target = $(WORKDIR)/CliAssemblyTarget/$(1).done
gb_CliAssemblyTarget_get_assembly_target = $(WORKDIR)/CliAssemblyTarget/$(1)$(gb_CliAssemblyTarget_POLICYEXT) gb_CliAssemblyTarget_get_assembly_target = $(WORKDIR)/CliAssemblyTarget/$(1)$(gb_CliAssemblyTarget_POLICYEXT)
gb_CliConfigTarget_get_target = $(WORKDIR)/CliConfigTarget/$(1).config gb_CliConfigTarget_get_target = $(WORKDIR)/CliConfigTarget/$(1).config
gb_CliNativeLibrary_get_preparation_target = $(WORKDIR)/CliNativeLibraryTarget/$(1).prepare gb_CliNativeLibrary_get_preparation_target = $(WORKDIR)/CliNativeLibraryTarget/$(1).prepare
gb_CompilerTest_get_target = $(WORKDIR)/CompilerTest/$(1)
gb_ComponentTarget_get_target = $(WORKDIR)/ComponentTarget/$(1).component gb_ComponentTarget_get_target = $(WORKDIR)/ComponentTarget/$(1).component
gb_ComponentTarget_get_target_for_build = $(WORKDIR_FOR_BUILD)/ComponentTarget/$(1).component gb_ComponentTarget_get_target_for_build = $(WORKDIR_FOR_BUILD)/ComponentTarget/$(1).component
gb_Configuration_get_preparation_target = $(WORKDIR)/Configuration/$(1).prepared gb_Configuration_get_preparation_target = $(WORKDIR)/Configuration/$(1).prepared
...@@ -233,6 +234,7 @@ $(eval $(call gb_Helper_make_clean_targets,\ ...@@ -233,6 +234,7 @@ $(eval $(call gb_Helper_make_clean_targets,\
CliLibrary \ CliLibrary \
CliNativeLibrary \ CliNativeLibrary \
CliUnoApi \ CliUnoApi \
CompilerTest \
ComponentTarget \ ComponentTarget \
CustomPackage \ CustomPackage \
DescriptionTranslateTarget \ DescriptionTranslateTarget \
...@@ -411,6 +413,17 @@ define gb_CppunitTest_get_linktarget ...@@ -411,6 +413,17 @@ define gb_CppunitTest_get_linktarget
$(call gb_CppunitTest__get_workdir_linktargetname,$(1))<>$(call gb_CppunitTest__get_linktarget_target,$(1)) $(call gb_CppunitTest__get_workdir_linktargetname,$(1))<>$(call gb_CppunitTest__get_linktarget_target,$(1))
endef endef
define gb_CompilerTest__get_workdir_linktargetname
CompilerTest/$(1)
endef
define gb_CompilerTest__get_linktarget_target
$(WORKDIR)/LinkTarget/$(call gb_CompilerTest__get_workdir_linktargetname,$(1))
endef
# this returns a tuple of both the linktargetname, and the target file
define gb_CompilerTest_get_linktarget
$(call gb_CompilerTest__get_workdir_linktargetname,$(1))<>$(call gb_CompilerTest__get_linktarget_target,$(1))
endef
# static members declared here because they are used globally # static members declared here because they are used globally
gb_StaticLibrary_WORKDIR = $(WORKDIR)/LinkTarget/StaticLibrary gb_StaticLibrary_WORKDIR = $(WORKDIR)/LinkTarget/StaticLibrary
......
...@@ -313,6 +313,7 @@ include $(foreach class, \ ...@@ -313,6 +313,7 @@ include $(foreach class, \
AutoInstall \ AutoInstall \
PackageSet \ PackageSet \
GeneratedPackage \ GeneratedPackage \
CompilerTest \
,$(GBUILDDIR)/$(class).mk) ,$(GBUILDDIR)/$(class).mk)
$(eval $(call gb_Helper_process_executable_registrations)) $(eval $(call gb_Helper_process_executable_registrations))
......
...@@ -54,15 +54,16 @@ $(call gb_Helper_abbreviate_dirs,\ ...@@ -54,15 +54,16 @@ $(call gb_Helper_abbreviate_dirs,\
$(if $(VISIBILITY),,$(gb_VISIBILITY_FLAGS)) \ $(if $(VISIBILITY),,$(gb_VISIBILITY_FLAGS)) \
$(if $(WARNINGS_NOT_ERRORS),$(if $(ENABLE_WERROR),$(if $(PLUGIN_WARNINGS_AS_ERRORS),$(gb_COMPILER_PLUGINS_WARNINGS_AS_ERRORS))),$(gb_CFLAGS_WERROR)) \ $(if $(WARNINGS_NOT_ERRORS),$(if $(ENABLE_WERROR),$(if $(PLUGIN_WARNINGS_AS_ERRORS),$(gb_COMPILER_PLUGINS_WARNINGS_AS_ERRORS))),$(gb_CFLAGS_WERROR)) \
$(if $(5),$(gb_COMPILER_PLUGINS)) \ $(if $(5),$(gb_COMPILER_PLUGINS)) \
$(if $(COMPILER_TEST),-fsyntax-only -Xclang -verify) \
$(2) \ $(2) \
$(if $(EXTERNAL_CODE),$(gb_CXXFLAGS_Wundef),$(gb_DEFS_INTERNAL)) \ $(if $(EXTERNAL_CODE),$(gb_CXXFLAGS_Wundef),$(gb_DEFS_INTERNAL)) \
-c $(3) \ -c $(3) \
-o $(1) \ -o $(1) \
$(call gb_cxx_dep_generation_options,$(1),$(4)) \ $(if $(COMPILER_TEST),,$(call gb_cxx_dep_generation_options,$(1),$(4))) \
-I$(dir $(3)) \ -I$(dir $(3)) \
$(INCLUDE) \ $(INCLUDE) \
$(PCHFLAGS) \ $(PCHFLAGS) \
$(call gb_cxx_dep_copy,$(4)) \ $(if $(COMPILER_TEST),,$(call gb_cxx_dep_copy,$(4))) \
) )
endef endef
......
...@@ -126,7 +126,7 @@ gb_CXXFLAGS_COMMON += -fpch-preprocess -Winvalid-pch ...@@ -126,7 +126,7 @@ gb_CXXFLAGS_COMMON += -fpch-preprocess -Winvalid-pch
endif endif
endif endif
gb_CFLAGS_WERROR := $(if $(ENABLE_WERROR),-Werror) gb_CFLAGS_WERROR = $(if $(ENABLE_WERROR),-Werror)
# This is the default in non-C++11 mode # This is the default in non-C++11 mode
ifeq ($(COM_IS_CLANG),TRUE) ifeq ($(COM_IS_CLANG),TRUE)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment