Skip to content
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

[Support] Give llvm_strlcpy restrict semantics #78168

Closed
wants to merge 1 commit into from

Conversation

AtariDreams
Copy link
Contributor

strlcpy has restrict semantics, so llvm_strlcpy should have them too.

Source: https://man.freebsd.org/cgi/man.cgi?strlcpy

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 15, 2024

@llvm/pr-subscribers-llvm-support

Author: AtariDreams (AtariDreams)

Changes

strlcpy has restrict semantics, so llvm_strlcpy should have them too.

Source: https://man.freebsd.org/cgi/man.cgi?strlcpy


Full diff: https://github.com/llvm/llvm-project/pull/78168.diff

2 Files Affected:

  • (modified) llvm/lib/Support/regex_impl.h (+1-1)
  • (modified) llvm/lib/Support/regstrlcpy.c (+1-1)
diff --git a/llvm/lib/Support/regex_impl.h b/llvm/lib/Support/regex_impl.h
index 8f0c532205edc3..6b780da10e35fe 100644
--- a/llvm/lib/Support/regex_impl.h
+++ b/llvm/lib/Support/regex_impl.h
@@ -99,7 +99,7 @@ size_t	llvm_regerror(int, const llvm_regex_t *, char *, size_t);
 int	llvm_regexec(const llvm_regex_t *, const char *, size_t,
                      llvm_regmatch_t [], int);
 void	llvm_regfree(llvm_regex_t *);
-size_t  llvm_strlcpy(char *dst, const char *src, size_t siz);
+size_t  llvm_strlcpy(char *__restrict dst, const char * __restrict src, size_t siz);
 
 #ifdef __cplusplus
 }
diff --git a/llvm/lib/Support/regstrlcpy.c b/llvm/lib/Support/regstrlcpy.c
index 8b68afdf75f16a..1e55c4f36af7b9 100644
--- a/llvm/lib/Support/regstrlcpy.c
+++ b/llvm/lib/Support/regstrlcpy.c
@@ -26,7 +26,7 @@
  * Returns strlen(src); if retval >= siz, truncation occurred.
  */
 size_t
-llvm_strlcpy(char *dst, const char *src, size_t siz)
+llvm_strlcpy(char *__restrict dst, const char *__restrict src, size_t siz)
 {
 	char *d = dst;
 	const char *s = src;

Copy link

github-actions bot commented Jan 15, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like an unnecessary change for the sake of change.

@AtariDreams
Copy link
Contributor Author

This looks like an unnecessary change for the sake of change.

It is just for consistency.

strlcpy has restrict semantics, so llvm_strlcpy should have them too.

Source: https://man.freebsd.org/cgi/man.cgi?strlcpy
@nikic
Copy link
Contributor

nikic commented Jan 19, 2024

This looks like an unnecessary change for the sake of change.

It is just for consistency.

Consistency with what? This is an utterly unimportant helper used only by the regex implementation, which is imported from a 3rd party to boot. The code is not performance critical, so why would we care to sprinkle about dangerous optimization attributes in its implementation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants