[PATCH] D124453: const char* for LLVMTargetMachineEmitToFile's argument

Andrei Damian via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 26 07:04:07 PDT 2022


Tachyon created this revision.
Tachyon added a reviewer: baldrick.
Tachyon added a project: LLVM.
Herald added a reviewer: deadalnix.
Herald added a subscriber: hiraditya.
Herald added a project: All.
Tachyon requested review of this revision.
Herald added a subscriber: llvm-commits.

The `LLVMTargetMachineEmitToFile` takes a `char* Filename` right now, but it doesn't modify it.
This is annoying to use in the case where you want to pass a const string, because you either have to remove the const, or copy it somewhere else and pass that. Either way, it's not very nice.

I added a const and clang formatted it. This shouldn't break any ABI in my opinion.
I'm sorry but I didn't know whom to put as reviewer for this, so I chose someone with a lot of commits from the .cpp file.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124453

Files:
  llvm/include/llvm-c/TargetMachine.h
  llvm/lib/Target/TargetMachineC.cpp


Index: llvm/lib/Target/TargetMachineC.cpp
===================================================================
--- llvm/lib/Target/TargetMachineC.cpp
+++ llvm/lib/Target/TargetMachineC.cpp
@@ -213,7 +213,9 @@
 }
 
 LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
-  char* Filename, LLVMCodeGenFileType codegen, char** ErrorMessage) {
+                                     const char *Filename,
+                                     LLVMCodeGenFileType codegen,
+                                     char **ErrorMessage) {
   std::error_code EC;
   raw_fd_ostream dest(Filename, EC, sys::fs::OF_None);
   if (EC) {
Index: llvm/include/llvm-c/TargetMachine.h
===================================================================
--- llvm/include/llvm-c/TargetMachine.h
+++ llvm/include/llvm-c/TargetMachine.h
@@ -136,7 +136,9 @@
   wraps several c++ only classes (among them a file stream). Returns any
   error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */
 LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
-  char *Filename, LLVMCodeGenFileType codegen, char **ErrorMessage);
+                                     const char *Filename,
+                                     LLVMCodeGenFileType codegen,
+                                     char **ErrorMessage);
 
 /** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */
 LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleRef M,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124453.425200.patch
Type: text/x-patch
Size: 1510 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220426/6b92bbae/attachment.bin>


More information about the llvm-commits mailing list