[Lldb-commits] [PATCH] D27780: Make OptionDefinition structure store a StringRef

Zachary Turner via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Dec 14 16:42:24 PST 2016

zturner added a comment.

In response to all the questions about "Will a StringRef constructor be called on XXX", the answer is usually yes, but the constructor will be inlined and invoke `__builtin_strlen` (which is constexpr on GCC and Clang) when used on a string literal.  In other words, there is zero overhead.

So the code generated for `S.startswith("--")` will end up just being `(2 >= S.Length) && (::memcmp(S.Data, "--", 2) == 0)`.

The only time we have to worry about constexprness and make sure we use `StringLiteral` is with static variables (global or local).  With static variables, the compiler has to decide between static link-time initialization or runtime initialization, and only if you declare the variable as `constexpr` will it choose link-time initialization.  So the generated code for these two might look something like this:

  // No generated code, S is initialized at link-time.
  constexpr StringLiteral S("foo");   
  // mov <addr-of-T.Data>, <addr-of-global-string>
  // mov <addr-of-T.Length>, 3
  StringLiteral T("foo");


More information about the lldb-commits mailing list