-
Notifications
You must be signed in to change notification settings - Fork 15.1k
use Twine instead of char* for function args #165569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-clang @llvm/pr-subscribers-llvm-support Author: Sean Perry (perry-ca) ChangesChanged the function arguments to take Full diff: https://github.com/llvm/llvm-project/pull/165569.diff 4 Files Affected:
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index d8ec837f0f7b9..938c6485125ee 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -608,8 +608,7 @@ FileID SourceManager::createFileIDImpl(ContentCache &File, StringRef Filename,
return FileID::get(LoadedID);
}
unsigned FileSize = File.getSize();
- llvm::ErrorOr<bool> NeedConversion =
- llvm::needConversion(Filename.str().c_str());
+ llvm::ErrorOr<bool> NeedConversion = llvm::needConversion(Filename);
if (NeedConversion && *NeedConversion) {
// Buffer size may increase due to potential z/OS EBCDIC to UTF-8
// conversion.
diff --git a/llvm/include/llvm/Support/AutoConvert.h b/llvm/include/llvm/Support/AutoConvert.h
index 1e6792636e169..15f1ec8af6c57 100644
--- a/llvm/include/llvm/Support/AutoConvert.h
+++ b/llvm/include/llvm/Support/AutoConvert.h
@@ -18,6 +18,7 @@
#include <_Ccsid.h>
#endif
#ifdef __cplusplus
+#include "llvm/ADT/Twine.h"
#include "llvm/Support/Error.h"
#include <system_error>
#endif /* __cplusplus */
@@ -47,12 +48,12 @@ namespace llvm {
std::error_code setzOSFileTag(int FD, int CCSID, bool Text);
/** \brief Get the the tag ccsid for a file name or a file descriptor. */
-ErrorOr<__ccsid_t> getzOSFileTag(const char *FileName, const int FD = -1);
+ErrorOr<__ccsid_t> getzOSFileTag(const Twine &FileName, const int FD = -1);
/** \brief Query the file tag to determine if it needs conversion to UTF-8
* codepage.
*/
-ErrorOr<bool> needzOSConversion(const char *FileName, const int FD = -1);
+ErrorOr<bool> needzOSConversion(const Twine &FileName, const int FD = -1);
#endif /* __MVS__*/
@@ -87,7 +88,7 @@ inline std::error_code setFileTag(int FD, int CCSID, bool Text) {
return std::error_code();
}
-inline ErrorOr<bool> needConversion(const char *FileName, const int FD = -1) {
+inline ErrorOr<bool> needConversion(const Twine &FileName, const int FD = -1) {
#ifdef __MVS__
return needzOSConversion(FileName, FD);
#endif
diff --git a/llvm/lib/Support/AutoConvert.cpp b/llvm/lib/Support/AutoConvert.cpp
index 0b6928e10ef5a..741bb7bd2c5b0 100644
--- a/llvm/lib/Support/AutoConvert.cpp
+++ b/llvm/lib/Support/AutoConvert.cpp
@@ -96,7 +96,7 @@ std::error_code llvm::setzOSFileTag(int FD, int CCSID, bool Text) {
return std::error_code();
}
-ErrorOr<__ccsid_t> llvm::getzOSFileTag(const char *FileName, const int FD) {
+ErrorOr<__ccsid_t> llvm::getzOSFileTag(const Twine &FileName, const int FD) {
// If we have a file descriptor, use it to find out file tagging. Otherwise we
// need to use stat() with the file path.
if (FD != -1) {
@@ -110,12 +110,12 @@ ErrorOr<__ccsid_t> llvm::getzOSFileTag(const char *FileName, const int FD) {
return Query.fccsid;
}
struct stat Attr;
- if (stat(FileName, &Attr) == -1)
+ if (stat(FileName.str().c_str(), &Attr) == -1)
return std::error_code(errno, std::generic_category());
return Attr.st_tag.ft_ccsid;
}
-ErrorOr<bool> llvm::needzOSConversion(const char *FileName, const int FD) {
+ErrorOr<bool> llvm::needzOSConversion(const Twine &FileName, const int FD) {
ErrorOr<__ccsid_t> Ccsid = getzOSFileTag(FileName, FD);
if (std::error_code EC = Ccsid.getError())
return EC;
diff --git a/llvm/lib/Support/MemoryBuffer.cpp b/llvm/lib/Support/MemoryBuffer.cpp
index 1c4645ad83641..23b9f8c5790d2 100644
--- a/llvm/lib/Support/MemoryBuffer.cpp
+++ b/llvm/lib/Support/MemoryBuffer.cpp
@@ -512,7 +512,7 @@ getOpenFileImpl(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize,
}
#ifdef __MVS__
- ErrorOr<bool> NeedsConversion = needConversion(Filename.str().c_str(), FD);
+ ErrorOr<bool> NeedsConversion = needConversion(Filename, FD);
if (std::error_code EC = NeedsConversion.getError())
return EC;
// File size may increase due to EBCDIC -> UTF-8 conversion, therefore we
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/88/builds/17631 Here is the relevant piece of the build log for the reference |
Changed the function arguments to take `const Twine&` instead of `const char*`. This will avoid converting StringRef's to C strings too soon (or ever).
Changed the function arguments to take `const Twine&` instead of `const char*`. This will avoid converting StringRef's to C strings too soon (or ever).
Changed the function arguments to take
const Twine&instead ofconst char*. This will avoid converting StringRef's to C strings too soon (or ever).