diff options
author | OverMighty <its.overmighty@gmail.com> | 2024-02-28 22:46:06 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-28 14:46:06 -0800 |
commit | fc8d48106387b8b79531902788ef93571f924da7 (patch) | |
tree | 7a93ac49de5ad3cc08bed1662450af0253a1c836 /clang/lib/Sema/SemaChecking.cpp | |
parent | e3b93a16201d96745a2c64523801a2b1eb43b4c0 (diff) | |
download | llvm-fc8d48106387b8b79531902788ef93571f924da7.zip llvm-fc8d48106387b8b79531902788ef93571f924da7.tar.gz llvm-fc8d48106387b8b79531902788ef93571f924da7.tar.bz2 |
[clang] Fix __builtin_popcountg not matching GCC (#83313)
Our implementation previously accepted signed arguments and performed
integer promotion on the argument. GCC's implementation requires an
unsigned argument and does not perform integer promotion on it.
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 0de76ee..979b638 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -2190,17 +2190,23 @@ static bool SemaBuiltinCpu(Sema &S, const TargetInfo &TI, CallExpr *TheCall, } /// Checks that __builtin_popcountg was called with a single argument, which is -/// an integer. +/// an unsigned integer. static bool SemaBuiltinPopcountg(Sema &S, CallExpr *TheCall) { if (checkArgCount(S, TheCall, 1)) return true; - Expr *Arg = TheCall->getArg(0); + ExprResult ArgRes = S.DefaultLvalueConversion(TheCall->getArg(0)); + if (ArgRes.isInvalid()) + return true; + + Expr *Arg = ArgRes.get(); + TheCall->setArg(0, Arg); + QualType ArgTy = Arg->getType(); - if (!ArgTy->isIntegerType()) { + if (!ArgTy->isUnsignedIntegerType()) { S.Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type) - << 1 << /*integer ty*/ 7 << ArgTy; + << 1 << /*unsigned integer ty*/ 7 << ArgTy; return true; } return false; |