-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Add clang::lifetimebound annotation to StringRef constructors. #113878
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-llvm-adt Author: Haojian Wu (hokein) ChangesAdding the lifetimebound annotation to the ArrayRef's array constructor can enable us to detect the following use-after-free issues:
See #113533 Full diff: https://github.com/llvm/llvm-project/pull/113878.diff 1 Files Affected:
diff --git a/llvm/include/llvm/ADT/StringRef.h b/llvm/include/llvm/ADT/StringRef.h
index f879bbf7164fd6..0dcd4d90086eff 100644
--- a/llvm/include/llvm/ADT/StringRef.h
+++ b/llvm/include/llvm/ADT/StringRef.h
@@ -81,7 +81,7 @@ namespace llvm {
StringRef(std::nullptr_t) = delete;
/// Construct a string ref from a cstring.
- /*implicit*/ constexpr StringRef(const char *Str)
+ /*implicit*/ constexpr StringRef(const char *Str LLVM_LIFETIME_BOUND)
: View(Str, Str ?
// GCC 7 doesn't have constexpr char_traits. Fall back to __builtin_strlen.
#if defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 8
@@ -93,7 +93,8 @@ namespace llvm {
}
/// Construct a string ref from a pointer and length.
- /*implicit*/ constexpr StringRef(const char *data, size_t length)
+ /*implicit*/ constexpr StringRef(const char *data LLVM_LIFETIME_BOUND,
+ size_t length)
: View(data, length) {}
/// Construct a string ref from an std::string.
|
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! Thanks!
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/27/builds/1111 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/139/builds/5492 Here is the relevant piece of the build log for the reference
|
…113878) Adding the lifetimebound annotation to the ArrayRef's array constructor can enable us to detect the following use-after-free issues: ``` llvm::StringRef TestZoneName() { char test[] = "foo"; // oops, missing static return test; // use-after-free. } ``` See llvm#113533
Adding the lifetimebound annotation to the ArrayRef's array constructor can enable us to detect the following use-after-free issues:
See #113533