https://gcc.gnu.org/g:a551d0330d62d8b5d28c4c9af63bae17afb3bbc4

commit r12-10629-ga551d0330d62d8b5d28c4c9af63bae17afb3bbc4
Author: Siddhesh Poyarekar <siddh...@gotplt.org>
Date:   Fri Jul 19 12:44:32 2024 -0400

    Avoid undefined behaviour in build_option_suggestions
    
    The inner loop in build_option_suggestions uses OPTION to take the
    address of OPTB and use it across iterations, which is undefined
    behaviour since OPTB is defined within the loop.  Pull it outside the
    loop to make this defined.
    
    gcc/ChangeLog:
    
            * opt-suggestions.cc
            (option_proposer::build_option_suggestions): Pull OPTB
            definition out of the innermost loop.
    
    (cherry picked from commit e0d997e913f811ecf4b3e10891e6a4aab5b38a31)

Diff:
---
 gcc/opt-suggestions.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/opt-suggestions.cc b/gcc/opt-suggestions.cc
index 33f298560a1a..92969e74d407 100644
--- a/gcc/opt-suggestions.cc
+++ b/gcc/opt-suggestions.cc
@@ -167,9 +167,9 @@ option_proposer::build_option_suggestions (const char 
*prefix)
            add_misspelling_candidates (m_option_suggestions, option,
                                        opt_text);
 
+           struct cl_option optb;
            for (int j = 0; sanitizer_opts[j].name != NULL; ++j)
              {
-               struct cl_option optb;
                /* -fsanitize=all is not valid, only -fno-sanitize=all.
                   So don't register the positive misspelling candidates
                   for it.  */

Reply via email to