Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

RFC: [llvm] specialize cl::opt_storage for std::string#149172

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
andrurogerz wants to merge1 commit intollvm:main
base:main
Choose a base branch
Loading
fromandrurogerz:clopt-string

Conversation

andrurogerz
Copy link
Contributor

Purpose

Specializellvm::cl::opt_storage for data typestd::string so that it no longer inherits fromstd::string. With this patch in place, explicitly instantiatedcl::opt<std::string> can be safely exported from an LLVM Windows DLL.

Overview

  • Add fully-specified implementation ofcl::opt_storage for data typestd::string. It does NOT inherit fromstd::string as it did previously when data typestd::string matched the partially specified templatecl::opt_storage<DataType, false, true>
  • Implement implicit conversions tostd::string,llvm::StringRef, andllvm::Twine so that instances can be used in many places wherestd::string is used.
  • Implement a number ofstd::string methods so that instances of the class are mostly interoperable withstd::string.
  • Add a new explicit constructor toTriple so it properly constructs fromcl::opt_storage<std::string>. This change avoids having to modify clients that constructTriples fromcl::opt<std::string> instances.

Background

This patch is in support of annotating LLVM's public symbols for Windows DLL export., tracked in#109483. Additional context is provided inthis discourse.

This change is needed because, without it, we cannot exportopt<std::string> from an LLVM Windows DLL. This is because MSVC exports all ancestor classes when exporting an instantiated template class. Since one ofopt's ancestor classes is its type argument (viaopt_storage), it is an ancestor ofstd::string. Therefore, if we exportopt<std::string> from the LLVM DLL, MSVC forcesstd::basic_string to also be exported. This leads to duplicate symbol errors and generally seems like a bad idea. Compiling withclang-cl does not exhibit this behavior.

Validation

  • Built llvm-project on Windows with MSVCcl andclang-cl.
  • Built llvm-project on Fedora withclang andgcc.

@github-actionsGitHub Actions
Copy link

github-actionsbot commentedJul 16, 2025
edited
Loading

⚠️ C/C++ code formatter, clang-format found issues in your code.⚠️

You can test this locally with the following command:
git-clang-format --diff HEAD~1 HEAD --extensions h -- llvm/include/llvm/Support/CommandLine.h llvm/include/llvm/TargetParser/Triple.h
View the diff from clang-format here.
diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.hindex 823e31a80..7c041fbff 100644--- a/llvm/include/llvm/Support/CommandLine.h+++ b/llvm/include/llvm/Support/CommandLine.h@@ -1417,23 +1417,23 @@ public:   const OptionValue<std::string> &getDefault() const { return Default; }    // Support implicit conversions to std::string and LLVM string-like types.-  //operator std::string() const { return Value; }-  operator std::string&() { return Value; }-  operator const std::string&() const { return Value; }+  // operator std::string() const { return Value; }+  operator std::string &() { return Value; }+  operator const std::string &() const { return Value; }   operator llvm::StringRef() const { return llvm::StringRef(Value); }   operator llvm::Twine() const { return llvm::Twine(llvm::StringRef(Value)); }    // If the datatype is a pointer, support -> on it.   std::string operator->() const { return Value; }-  Self& operator=(const Self& rhs) = default;+  Self &operator=(const Self &rhs) = default;-  Self& operator=(const std::string& rhs) {+  Self &operator=(const std::string &rhs) {     Value = rhs;     return *this;   }-  Self& operator=(const char* rhs) {+  Self &operator=(const char *rhs) {     Value = rhs;     return *this;   }@@ -1491,43 +1491,39 @@ public:    char operator[](size_t pos) const { return Value.at(pos); }-  Self& assign(const std::string& rhs) {+  Self &assign(const std::string &rhs) {     Value.assign(rhs);     return *this;   }-  Self& assign(const char* rhs) {+  Self &assign(const char *rhs) {     Value.assign(rhs);     return *this;   }-  Self& operator+=(const std::string& rhs) {+  Self &operator+=(const std::string &rhs) {     Value += rhs;     return *this;   }-  Self& operator+=(const char* rhs) {+  Self &operator+=(const char *rhs) {     Value += rhs;     return *this;   }-  friend std::string-  operator+(Self const& lhs, std::string const& rhs) {+  friend std::string operator+(Self const &lhs, std::string const &rhs) {     return lhs.Value + rhs;   }-  friend std::string-  operator+(std::string const& lhs, Self const& rhs) {+  friend std::string operator+(std::string const &lhs, Self const &rhs) {     return lhs + rhs.Value;   }-  friend std::string-  operator+(Self const& lhs, char const* rhs) {+  friend std::string operator+(Self const &lhs, char const *rhs) {     return lhs.Value + rhs;   }-  friend std::string-  operator+(char const* lhs, Self const& rhs) {+  friend std::string operator+(char const *lhs, Self const &rhs) {     return lhs + rhs.Value;   }

@andrurogerzandrurogerz changed the title[llvm] specialize cl::opt_storage for std::stringRFC: [llvm] specialize cl::opt_storage for std::stringJul 16, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant
@andrurogerz

[8]ページ先頭

©2009-2025 Movatter.jp