Skip to content

[NFC] Fix evaluation order dependency in call arguments #141366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

michael-jabbour-sonarsource
Copy link
Contributor

@michael-jabbour-sonarsource michael-jabbour-sonarsource commented May 24, 2025

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.

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/
@llvmbot
Copy link
Member

llvmbot commented May 24, 2025

@llvm/pr-subscribers-backend-arm

Author: Michael Jabbour (michael-jabbour-sonarsource)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/141366.diff

1 Files Affected:

  • (modified) llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp (+2-3)
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)

Copy link
Collaborator

@davemgreen davemgreen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. LGTM

@michael-jabbour-sonarsource
Copy link
Contributor Author

Thanks for the quick review! Feel free to merge this as I don't have commit access myself 😄

@ostannard ostannard merged commit 8fe33a0 into llvm:main May 27, 2025
13 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented May 27, 2025

LLVM Buildbot has detected a new failure on builder openmp-s390x-linux running on systemz-1 while building llvm at step 6 "test-openmp".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/88/builds/12116

Here is the relevant piece of the build log for the reference
Step 6 (test-openmp) failure: test (failure)
******************** TEST 'libomp :: tasking/issue-94260-2.c' FAILED ********************
Exit Code: -11

Command Output (stdout):
--
# RUN: at line 1
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/./bin/clang -fopenmp   -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test -L /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src  -fno-omit-frame-pointer -mbackchain -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/ompt /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c -o /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp -lm -latomic && /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# executed command: /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/./bin/clang -fopenmp -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test -L /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -fno-omit-frame-pointer -mbackchain -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/ompt /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c -o /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp -lm -latomic
# executed command: /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# note: command had no output on stdout or stderr
# error: command failed with exit status: -11

--

********************


@michael-jabbour-sonarsource michael-jabbour-sonarsource deleted the avoid_relying_on_indeterminately_sequenced_eval_order branch May 27, 2025 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants