Skip to content
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

Do not report -Wasm-operand-widths for Aarch64 ilp32 operands #73385

Closed
wants to merge 1 commit into from

Conversation

joyhou-hw
Copy link
Contributor

Since width of pointer type is 32 bits in ILP32 while memory instruction shall 'x' registers. msr/mrs likewise.

Now Wasm-operand-widths in ILP32 will warning below asm code with a WRONG massage.

void atomicAdd32(int *ptr, int lIncr)
{
  int  result = 0;
  unsigned int tmp = 0;

  __asm__ volatile(
     "1: ldxr   %w0, [%2]        \n\t"
     "   add    %w0, %w0, %w3    \n\t"
     "   stxr   %w1, %w0, [%2]   \n\t"
     "   cbnz   %w1, 1b          \n\t"
     : "=&r"(result), "=&r"(tmp)
     : "r"(ptr), "Ir"(lIncr)
     :"memory","cc"
  );
}

The [%2] shall be 'x' rregister for ldxr inst., not the %w2.

warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]
        : "r"(ptr), "Ir"(lIncr)
              ^
: note: use constraint modifier "w"
        "1: ldxr   %w0, [%2]        \n\t"
                         ^~
                         %w2

Since width of pointer type is 32 bits in ILP32 while memory instruction shall 'x' registers.
msr/mrs likewise.
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:AArch64 clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Nov 25, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 25, 2023

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-aarch64

Author: None (joyhou-hw)

Changes

Since width of pointer type is 32 bits in ILP32 while memory instruction shall 'x' registers. msr/mrs likewise.

Now Wasm-operand-widths in ILP32 will warning below asm code with a WRONG massage.

void atomicAdd32(int *ptr, int lIncr)
{
  int  result = 0;
  unsigned int tmp = 0;

  __asm__ volatile(
     "1: ldxr   %w0, [%2]        \n\t"
     "   add    %w0, %w0, %w3    \n\t"
     "   stxr   %w1, %w0, [%2]   \n\t"
     "   cbnz   %w1, 1b          \n\t"
     : "=&r"(result), "=&r"(tmp)
     : "r"(ptr), "Ir"(lIncr)
     :"memory","cc"
  );
}

The [%2] shall be 'x' rregister for ldxr inst., not the %w2.

warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]
        : "r"(ptr), "Ir"(lIncr)
              ^
: note: use constraint modifier "w"
        "1: ldxr   %w0, [%2]        \n\t"
                         ^~
                         %w2

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

1 Files Affected:

  • (modified) clang/lib/Basic/Targets/AArch64.cpp (+4)
diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp
index c31f2e0bee54393..180c5f17d7835a4 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1362,6 +1362,10 @@ bool AArch64TargetInfo::validateAsmConstraint(
 bool AArch64TargetInfo::validateConstraintModifier(
     StringRef Constraint, char Modifier, unsigned Size,
     std::string &SuggestedModifier) const {
+  // Ignore in ILP32 since width of pointer type is 32 bits
+  // while memory instruction shall 'x' registers.
+  if (getTriple().getEnvironment() == llvm::Triple::GNUILP32)
+    return true;
   // Strip off constraint modifiers.
   while (Constraint[0] == '=' || Constraint[0] == '+' || Constraint[0] == '&')
     Constraint = Constraint.substr(1);

@joyhou-hw joyhou-hw closed this Feb 2, 2024
@joyhou-hw joyhou-hw deleted the asm-operand-widths branch February 2, 2024 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AArch64 clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants