[llvm] [NFC] Fix evaluation order dependency in call arguments (PR #141366)
Michael Jabbour via llvm-commits
llvm-commits at lists.llvm.org
Sat May 24 12:15:05 PDT 2025
https://github.com/michael-jabbour-sonarsource created https://github.com/llvm/llvm-project/pull/141366
The code in `ARMAsmParser::parseDirectiveReq` passes both `parseRegister(Reg, SRegLoc, ERegLoc)` and `SRegLoc` as arguments to `check()`. Since function arguments are indeterminately sequenced per C++17 [expr.call]/5, a compiler can evaluate `SRegLoc` before `parseRegister()` executes. This means `check()` receives a null location instead of the actual parsed source location for error reporting.
The fix separates the calls to establish explicit sequencing, ensuring `check()` receives the correct source location.
This issue was detected by the CFamily analyzer for SonarQube. I'm happy to provide any additional information or clarification as needed.
>From bee799c329e0f53904ac4e97758b8e739acd1d33 Mon Sep 17 00:00:00 2001
From: Michael Jabbour <michael.jabbour at sonarsource.com>
Date: Sat, 24 May 2025 20:41:01 +0200
Subject: [PATCH] [NFC] Fix evaluation order dependency in call arguments
The code assumes parseRegister() executes before the standalone SRegLoc
argument to check(). Since function arguments are indeterminately sequenced
per C++17 [expr.call]/5, check() may receive a null location instead of
the actual parsed source location.
Detected by the CFamily analyzer for SonarQube.
https://docs.sonarsource.com/sonarqube-cloud/advanced-setup/languages/c-family/overview/
---
llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
index 85b107c6085d3..ee3dc7d8a3618 100644
--- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
+++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
@@ -11788,9 +11788,8 @@ bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
Parser.Lex(); // Eat the '.req' token.
MCRegister Reg;
SMLoc SRegLoc, ERegLoc;
- if (check(parseRegister(Reg, SRegLoc, ERegLoc), SRegLoc,
- "register name expected") ||
- parseEOL())
+ const bool parseResult = parseRegister(Reg, SRegLoc, ERegLoc);
+ if (check(parseResult, SRegLoc, "register name expected") || parseEOL())
return true;
if (RegisterReqs.insert(std::make_pair(Name, Reg)).first->second != Reg)
More information about the llvm-commits
mailing list