[PATCH] D123198: [LibCalls] Add argument extension attributes to more functions.
Jonas Paulsson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 20 10:05:28 PDT 2022
jonpa added a comment.
It seems that the failing test case (Transforms/InstCombine/pr39177.ll) is a bit peculiar in that it contains an fwrite *alias*:
fwrite = alias i64 (i8*, i64, i64, %struct._IO_FILE*), i64 (i8*, i64, i64, %struct._IO_FILE*)* @__fwrite_alias
It defines the @__fwrite_alias() function, and then has a foo() function containing a call to @fprintf() which SimplifyLibCalls is trying to replace with a call to fwrite(). This is when it crashes because of a nullptr as discovered by the sanitizer.
I am not sure what the idea is here with having an fwrite alias, but it is clear that BuildLibCalls is getting confused:
FunctionCallee llvm::getOrInsertLibFunc(Module *M, const TargetLibraryInfo &TLI,
LibFunc TheLibFunc, FunctionType *T,
AttributeList AttributeList) {
assert(TLI.has(TheLibFunc) &&
"Creating call to non-existing library function.");
StringRef Name = TLI.getName(TheLibFunc);
=>FunctionCallee C = M->getOrInsertFunction(Name, T, AttributeList);
at this point M returns the alias:
(gdb) p C.Callee->dump()
@fwrite = alias i64 (i8*, i64, i64, %struct._IO_FILE*), i64 (i8*, i64, i64, %struct._IO_FILE*)* @__fwrite_alias
This is a GlobalAlias and not a Function, which is why getFunction() returned nullptr:
Function &F = *M->getFunction(Name);
Looking at the test case, it seems to be valid to write your own fwrite and expect the compiler use it as a replacement for the standard fwrite call..? I guess this means that getOrInsertLibFunc() should also be able to handle a GlobalAlias?
================
Comment at: llvm/include/llvm/Transforms/Utils/BuildLibCalls.h:46
+ Type *RetTy, ArgsTy... Args) {
+ SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
+ return getOrInsertLibFunc(M, TLI, TheLibFunc,
----------------
MaskRay wrote:
> Consider using a plain array.
Do you have anything special in mind? This was copied from getOrInsertFunction().
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D123198/new/
https://reviews.llvm.org/D123198
More information about the llvm-commits
mailing list