Skip to content

Commit 13a2e54

Browse files
author
Brian Gaeke
committed
Dynamically get the right-sized member of a GenericValue to hold a size_t, and
use it to return the result of strlen. llvm-svn: 10433
1 parent 542d24f commit 13a2e54

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,17 @@ GenericValue lle_X_strcpy(FunctionType *M, const vector<GenericValue> &Args) {
481481
return PTOGV(strcpy((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1])));
482482
}
483483

484-
// long strlen(const char *src);
484+
// size_t strlen(const char *src);
485485
GenericValue lle_X_strlen(FunctionType *M, const vector<GenericValue> &Args) {
486486
assert(Args.size() == 1);
487+
size_t strlenResult = strlen ((char *) GVTOP (Args[0]));
487488
GenericValue Ret;
488-
Ret.LongVal = strlen((char*)GVTOP(Args[0]));
489+
if (sizeof (size_t) == sizeof (uint64_t)) {
490+
Ret.ULongVal = strlenResult;
491+
} else {
492+
assert (sizeof (size_t) == sizeof (unsigned int));
493+
Ret.UIntVal = strlenResult;
494+
}
489495
return Ret;
490496
}
491497

0 commit comments

Comments
 (0)