Also, tests and stuff
Details
Diff Detail
Event Timeline
tools/llvm-c-test/echo.cpp | ||
---|---|---|
221 | Why is this in clone_constant? It should be in llvm_echo below (and only executed once...) |
include/llvm-c/Core.h | ||
---|---|---|
483–504 | Please add a length parameter for both functions. Not all languages keep their string zero terminated and keep track of the length. For C StringRef will call strlen so the cost is the same. char *LLVMGetModuleIdentifier(LLVMModuleRef M, size_t *Length); void LLVMSetModuleIdentifier(LLVMModuleRef M, const char *ID, size_t Length); |
include/llvm-c/Core.h | ||
---|---|---|
483–504 | No other function in llvm-c currently does this. I don't see how the nonexistent benefit of being able to add a non-zero-terminated string for a human-readable identifier overweighs the drawback of making the API inconsistent. |
include/llvm-c/Core.h | ||
---|---|---|
483–504 | Actually, several function in C API do that (for instance LLVMGetAsString and LLVMGetMDString), while other use zero terminated strings. The current state is rather inconsistent. If we are going to make it consistent, I'd go for the Length as out parameter. |
tools/llvm-c-test/echo.cpp | ||
---|---|---|
221 | This has nothing to do here. |
include/llvm-c/Core.h | ||
---|---|---|
483–504 | That's reasonable. Nicole, can you please change the API as suggested? |
include/llvm-c/Core.h | ||
---|---|---|
483–504 | So, both zero terminated string and string with length as out param? Or just the latter? |
include/llvm-c/Core.h | ||
---|---|---|
483–504 | No, just the latter, it doesn't make a lot of sense to have both versions of this API when we agree that the string+length variant is the way it should all look eventually. |
include/llvm-c/Core.h | ||
---|---|---|
483–504 | Great, will change. |
include/llvm-c/Core.h | ||
---|---|---|
483–504 | Should it take an unsigned, or a size_t? A size_t would be more in keeping with what is actually meant by "length", but unsigned is more consistent with the rest of llvm. |
include/llvm-c/Core.h | ||
---|---|---|
483–504 | I think you are right, size_t is the correct type here, while I don't think it makes a big difference in practice (I don't expect anyone to get anywhere near 4G of description for a module). |
lib/IR/Core.cpp | ||
---|---|---|
161–162 | A string should know its length already, so taking the pointer and then computing strlen is wasteful. It is also not needed to strdup. It is common practice in the C API to return string the caller don't have ownership of. If caller has ownership of something, then a LLVMDisposeXXX method is provided. In this case, I don't think this is necessary. auto &Str = unwrap(M)->getModuleIdentifier() *Length = Str.length(); return Str.c_str(); Also, just take a size_t for length so yu don't need to assert. I see no reason why someone would have such a large identifier that it matters, but, on the other hand, I see no reason to prevent it. |
tools/llvm-c-test/echo.cpp | ||
---|---|---|
880 | What happens if you read the module identifier from src and copy it to dst ? That would avoid having to hardcode a module name as it is done now. |
tools/llvm-c-test/echo.cpp | ||
---|---|---|
880 | How do you mean? |
lib/IR/Core.cpp | ||
---|---|---|
161–162 | As said, just use size_t and get rid of the assert. | |
tools/llvm-c-test/echo.cpp | ||
880 | This test take a module as input, read it, and write a copy in another module. That allow to test read and write operations. Reading the identifier from the Src module writing it in the Dst module seems like the way to do that. |
lib/IR/Core.cpp | ||
---|---|---|
167 | Actually, can you call StringRef constructor here? I'm pretty sure I've never seen brace-initializer style anywhere else in LLVM. |
lib/IR/Core.cpp | ||
---|---|---|
167 | Yeah, I can. I will change it when I can. |
Please add a length parameter for both functions. Not all languages keep their string zero terminated and keep track of the length. For C StringRef will call strlen so the cost is the same.