From 5a431b60d1f221992e5e9f7a5c032df3b5fa35a5 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Tue, 4 Jan 2022 13:44:23 -0700 Subject: Eenable -Winvalid-memory-order for C++ [PR99612]. Resolves: PR middle-end/99612 - Remove "#pragma GCC system_header" from atomic file to warn on incorrect memory order gcc/ChangeLog: PR middle-end/99612 * builtins.c (get_memmodel): Move warning code to gimple-ssa-warn-access.cc. (expand_builtin_atomic_compare_exchange): Same. (expand_ifn_atomic_compare_exchange): Same. (expand_builtin_atomic_load): Same. (expand_builtin_atomic_store): Same. (expand_builtin_atomic_clear): Same. * doc/extend.texi (__atomic_exchange_n): Update valid memory models. * gimple-ssa-warn-access.cc (memmodel_to_uhwi): New function. (struct memmodel_pair): New struct. (memmodel_name): New function. (pass_waccess::maybe_warn_memmodel): New function. (pass_waccess::check_atomic_memmodel): New function. (pass_waccess::check_atomic_builtin): Handle memory model. * input.c (expansion_point_location_if_in_system_header): Return original location if expansion location is in a system header. gcc/testsuite/ChangeLog: PR middle-end/99612 * c-c++-common/pr83059.c: Adjust text of expected diagnostics. * gcc.dg/atomic-invalid-2.c: Same. * gcc.dg/atomic-invalid.c: Same. * c-c++-common/Winvalid-memory-model.c: New test. * g++.dg/warn/Winvalid-memory-model-2.C: New test. * g++.dg/warn/Winvalid-memory-model.C: New test. --- gcc/doc/extend.texi | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'gcc/doc') diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 5eec94e..637124a 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -12457,9 +12457,7 @@ This built-in function implements an atomic exchange operation. It writes @var{val} into @code{*@var{ptr}}, and returns the previous contents of @code{*@var{ptr}}. -The valid memory order variants are -@code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, @code{__ATOMIC_ACQUIRE}, -@code{__ATOMIC_RELEASE}, and @code{__ATOMIC_ACQ_REL}. +All memory order variants are valid. @end deftypefn -- cgit v1.1 From 0fc60c183358be2f2003b94226ab49e21c585b13 Mon Sep 17 00:00:00 2001 From: Kewen Lin Date: Tue, 4 Jan 2022 20:27:18 -0600 Subject: ipa-inline: Add target info into fn summary [PR102059] Power ISA 2.07 (Power8) introduces transactional memory feature but ISA3.1 (Power10) removes it. It exposes one troublesome issue as PR102059 shows. Users define some function with target pragma cpu=power10 then it calls one function with attribute always_inline which inherits command line option -mcpu=power8 which enables HTM implicitly. The current isa_flags check doesn't allow this inlining due to "target specific option mismatch" and error mesasge is emitted. Normally, the callee function isn't intended to exploit HTM feature, but the default flag setting make it look it has. As Richi raised in the PR, we have fp_expressions flag in function summary, and allow us to check the function actually contains any floating point expressions to avoid overkill. So this patch follows the similar idea but is more target specific, for this rs6000 port specific requirement on HTM feature check, we would like to check rs6000 specific HTM built-in functions and inline assembly, it allows targets to do their own customized checks and updates. It introduces two target hooks need_ipa_fn_target_info and update_ipa_fn_target_info. The former allows target to do some previous check and decides to collect target specific information for this function or not. For some special case, it can predict the analysis result and set it early without any scannings. The latter allows the analyze_function_body to pass gimple stmts down just like fp_expressions handlings, target can do its own tricks. I put them together as one hook initially with one boolean to indicate whether it's initial time, but the code looks a bit ugly, to separate them seems to have better readability. gcc/ChangeLog: PR ipa/102059 * config/rs6000/rs6000.c (TARGET_NEED_IPA_FN_TARGET_INFO): New macro. (TARGET_UPDATE_IPA_FN_TARGET_INFO): Likewise. (rs6000_need_ipa_fn_target_info): New function. (rs6000_update_ipa_fn_target_info): Likewise. (rs6000_can_inline_p): Adjust for ipa function summary target info. * config/rs6000/rs6000.h (RS6000_FN_TARGET_INFO_HTM): New macro. * ipa-fnsummary.c (ipa_dump_fn_summary): Adjust for ipa function summary target info. (analyze_function_body): Adjust for ipa function summary target info and call hook rs6000_need_ipa_fn_target_info and rs6000_update_ipa_fn_target_info. (ipa_merge_fn_summary_after_inlining): Adjust for ipa function summary target info. (inline_read_section): Likewise. (ipa_fn_summary_write): Likewise. * ipa-fnsummary.h (ipa_fn_summary::target_info): New member. * doc/tm.texi: Regenerate. * doc/tm.texi.in (TARGET_UPDATE_IPA_FN_TARGET_INFO): Document new hook. (TARGET_NEED_IPA_FN_TARGET_INFO): Likewise. * target.def (update_ipa_fn_target_info): New hook. (need_ipa_fn_target_info): Likewise. * targhooks.c (default_need_ipa_fn_target_info): New function. (default_update_ipa_fn_target_info): Likewise. * targhooks.h (default_update_ipa_fn_target_info): New declare. (default_need_ipa_fn_target_info): Likewise. gcc/testsuite/ChangeLog: PR ipa/102059 * gcc.dg/lto/pr102059-1_0.c: New test. * gcc.dg/lto/pr102059-1_1.c: New test. * gcc.dg/lto/pr102059-1_2.c: New test. * gcc.dg/lto/pr102059-2_0.c: New test. * gcc.dg/lto/pr102059-2_1.c: New test. * gcc.dg/lto/pr102059-2_2.c: New test. * gcc.target/powerpc/pr102059-1.c: New test. * gcc.target/powerpc/pr102059-2.c: New test. * gcc.target/powerpc/pr102059-3.c: New test. --- gcc/doc/tm.texi | 31 +++++++++++++++++++++++++++++++ gcc/doc/tm.texi.in | 4 ++++ 2 files changed, 35 insertions(+) (limited to 'gcc/doc') diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index b945d42..c934f7a 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -10713,6 +10713,37 @@ default, inlining is not allowed if the callee function has function specific target options and the caller does not use the same options. @end deftypefn +@deftypefn {Target Hook} bool TARGET_UPDATE_IPA_FN_TARGET_INFO (unsigned int& @var{info}, const gimple* @var{stmt}) +Allow target to analyze all gimple statements for the given function to +record and update some target specific information for inlining. A typical +example is that a caller with one isa feature disabled is normally not +allowed to inline a callee with that same isa feature enabled even which is +attributed by always_inline, but with the conservative analysis on all +statements of the callee if we are able to guarantee the callee does not +exploit any instructions from the mismatch isa feature, it would be safe to +allow the caller to inline the callee. +@var{info} is one @code{unsigned int} value to record information in which +one set bit indicates one corresponding feature is detected in the analysis, +@var{stmt} is the statement being analyzed. Return true if target still +need to analyze the subsequent statements, otherwise return false to stop +subsequent analysis. +The default version of this hook returns false. +@end deftypefn + +@deftypefn {Target Hook} bool TARGET_NEED_IPA_FN_TARGET_INFO (const_tree @var{decl}, unsigned int& @var{info}) +Allow target to check early whether it is necessary to analyze all gimple +statements in the given function to update target specific information for +inlining. See hook @code{update_ipa_fn_target_info} for usage example of +target specific information. This hook is expected to be invoked ahead of +the iterating with hook @code{update_ipa_fn_target_info}. +@var{decl} is the function being analyzed, @var{info} is the same as what +in hook @code{update_ipa_fn_target_info}, target can do one time update +into @var{info} without iterating for some case. Return true if target +decides to analyze all gimple statements to collect information, otherwise +return false. +The default version of this hook returns false. +@end deftypefn + @deftypefn {Target Hook} void TARGET_RELAYOUT_FUNCTION (tree @var{fndecl}) This target hook fixes function @var{fndecl} after attributes are processed. Default does nothing. On ARM, the default function's alignment is updated diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index d401bd4..d6359aa 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -7191,6 +7191,10 @@ on this implementation detail. @hook TARGET_CAN_INLINE_P +@hook TARGET_UPDATE_IPA_FN_TARGET_INFO + +@hook TARGET_NEED_IPA_FN_TARGET_INFO + @hook TARGET_RELAYOUT_FUNCTION @node Emulated TLS -- cgit v1.1 From ed8060950c64f2e449aaf90e438aa26d0d9d0b31 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 5 Jan 2022 16:33:16 -0800 Subject: x86: Rename -harden-sls=indirect-branch to -harden-sls=indirect-jmp Indirect branch also includes indirect call instructions. Rename -harden-sls=indirect-branch to -harden-sls=indirect-jmp to match its intended behavior. PR target/102952 * config/i386/i386-opts.h (harden_sls): Replace harden_sls_indirect_branch with harden_sls_indirect_jmp. * config/i386/i386.c (ix86_output_jmp_thunk_or_indirect): Likewise. (ix86_output_indirect_jmp): Likewise. (ix86_output_call_insn): Likewise. * config/i386/i386.opt: Replace indirect-branch with indirect-jmp. Replace harden_sls_indirect_branch with harden_sls_indirect_jmp. * doc/invoke.texi (-harden-sls=): Replace indirect-branch with indirect-jmp. --- gcc/doc/invoke.texi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gcc/doc') diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 0482065..6b84228 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -32507,8 +32507,8 @@ Force indirect call and jump via register. @opindex mharden-sls Generate code to mitigate against straight line speculation (SLS) with @var{choice}. The default is @samp{none} which disables all SLS -hardening. @samp{return} enables SLS hardening for function return. -@samp{indirect-branch} enables SLS hardening for indirect branch. +hardening. @samp{return} enables SLS hardening for function returns. +@samp{indirect-jmp} enables SLS hardening for indirect jumps. @samp{all} enables all SLS hardening. @item -mindirect-branch-cs-prefix -- cgit v1.1 From c1b7d28a5987e74232b7f054849f8bd8ccc7e7de Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Fri, 7 Jan 2022 13:49:28 -0500 Subject: analyzer: add region::is_named_decl_p This patch adds a debug function that I've found handy when debugging a problem with handling the decl "yy_buffer_stack" in PR analyzer/103546. gcc/analyzer/ChangeLog: * region.cc (region::is_named_decl_p): New. * region.h (region::is_named_decl_p): New decl. gcc/ChangeLog: * doc/analyzer.texi (Other Debugging Techniques): Document region::is_named_decl_p. Signed-off-by: David Malcolm --- gcc/doc/analyzer.texi | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gcc/doc') diff --git a/gcc/doc/analyzer.texi b/gcc/doc/analyzer.texi index 6577981..62faac4 100644 --- a/gcc/doc/analyzer.texi +++ b/gcc/doc/analyzer.texi @@ -545,3 +545,13 @@ and the exploded graph in compressed JSON form. One approach when tracking down where a particular bogus state is introduced into the @code{exploded_graph} is to add custom code to @code{program_state::validate}. + +The debug function @code{region::is_named_decl_p} can be used when debugging, +such as for assertions and conditional breakpoints. For example, when +tracking down a bug in handling a decl called @code{yy_buffer_stack}, I +temporarily added a: +@smallexample + gcc_assert (!m_base_region->is_named_decl_p ("yy_buffer_stack")); +@end smallexample +to @code{binding_cluster::mark_as_escaped} to trap a point where +@code{yy_buffer_stack} was mistakenly being treated as having escaped. -- cgit v1.1 From 4409152a4acaec5b58a93996088d0df9aaa779b8 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Fri, 7 Jan 2022 13:36:00 -0500 Subject: analyzer: implement __analyzer_dump_escaped PR analyzer/103546 seems to involve an issue in how the analyzer tracks which decls have escaped, so this patch adds a way to directly test this from DejaGnu. gcc/analyzer/ChangeLog: * region-model-impl-calls.cc (cmp_decls): New. (cmp_decls_ptr_ptr): New. (region_model::impl_call_analyzer_dump_escaped): New. * region-model.cc (region_model::on_stmt_pre): Handle __analyzer_dump_escaped. * region-model.h (region_model::impl_call_analyzer_dump_escaped): New decl. * store.h (binding_cluster::get_base_region): New accessor. gcc/ChangeLog: * doc/analyzer.texi (Special Functions for Debugging the Analyzer): Document __analyzer_dump_escaped. gcc/testsuite/ChangeLog: * gcc.dg/analyzer/analyzer-decls.h (__analyzer_dump_escaped): New decl. * gcc.dg/analyzer/escaping-1.c: New test. --- gcc/doc/analyzer.texi | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'gcc/doc') diff --git a/gcc/doc/analyzer.texi b/gcc/doc/analyzer.texi index 62faac4..06eb98f 100644 --- a/gcc/doc/analyzer.texi +++ b/gcc/doc/analyzer.texi @@ -487,6 +487,14 @@ will emit a warning describing the capacity of the base region of the region pointed to by the 1st argument. @smallexample +extern void __analyzer_dump_escaped (void); +@end smallexample + +will emit a warning giving the number of decls that have escaped on this +analysis path, followed by a comma-separated list of their names, +in alphabetical order. + +@smallexample __analyzer_dump_path (); @end smallexample -- cgit v1.1