-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[clang-tidy] Generates invalid code - adds invalid escapes to string literals #9683
Comments
What clang-tidy check is being run exactly? Are you able to provide an isolated repro sample code? Does the bug require formatting or not? From the thread on LLVM, it sounds like it's a clang-tidy bug? Our extension invokes clang-tidy and processes the fix yaml -- so either we're getting invalid fixes from clang-tidy or there's a bug in processing of those fixes. |
---
AnalyzeTemporaryDtors: false
FormatStyle: none
HeaderFilterRegex: 'agent/[^/]*\.(hpp|cpp|hxx|cxx)$|library/[^/]*\.(hpp|cpp|hxx|cxx)$|initial-validate/[^/]*\.(hpp|cpp|hxx|cxx)$|modules/[^/]*\.(hpp|cpp|hxx|cxx)$'
User: user
WarningsAsErrors: false
# Checks order:
# 1. Disable all default checks `-*`
# 2. Enable all desired checks `-<check_name_group>-*`
# 3. Disable specific checks with `-<check_name>`
Checks: >
-*,
boost-*,
bugprone-*,
cert-*,
clang-analyzer-*,
clang-diagnostic-*,
concurrency-*,
cppcoreguidelines-*,
google-*,
hicpp-*,
misc-*,
modernize-*,
performance-*,
portability-*,
readability-*,
-modernize-use-trailing-return-type,
-readability-redundant-access-specifiers,
CheckOptions:
- key: cert-dcl16-c.NewSuffixes
value: 'L;LL;LU;LLU'
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
value: 'false'
- key: cert-str34-c.DiagnoseSignedUnsignedCharComparisons
value: 'false'
- key: google-readability-namespace-comments.ShortNamespaceLines
value: '10'
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
value: 'true'
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
value: 'true'
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: 'true'
- key: google-readability-braces-around-statements.ShortStatementLines
value: '1'
- key: google-readability-function-size.StatementThreshold
value: '800'
- key: google-readability-namespace-comments.SpacesBeforeComments
value: '2'
- key: llvm-else-after-return.WarnOnConditionVariables
value: 'false'
- key: llvm-else-after-return.WarnOnUnfixable
value: 'false'
- key: llvm-qualified-auto.AddConstToQualified
value: 'false'
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: 'true'
- key: modernize-loop-convert.MaxCopySize
value: '16'
- key: modernize-loop-convert.MinConfidence
value: reasonable
- key: modernize-loop-convert.NamingStyle
value: CamelCase
- key: modernize-pass-by-value.IncludeStyle
value: llvm
- key: modernize-replace-auto-ptr.IncludeStyle
value: llvm
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
...
Applying the above on: #define MAX_FILENAME 2
char* szConfigName;
void ResetState() {}
void LoadConfig(char** buf) {(void) buf; }
void CheckModified() {
struct stat fileinfo;
time_t mytime;
char Buf[MAX_FILENAME];
if (stat(szConfigName, &fileinfo) == -1) {
fprintf(stderr, "CheckModified() Error: Cannot stat [%s]!\n", szConfigName);
return;
} else {
mytime = fileinfo.st_mtime;
if (mytime > 1) {
snprintf(Buf, MAX_FILENAME, "%s", szConfigName);
// BugID 7073: Suppressing output to stderr, it seems to be bothering dave.
// fprintf(stderr, "CheckModified() Reloading Configuration [%s]\n", Buf);
ResetState();
LoadConfig(Buf);
}
}
} produces: #define MAX_FILENAME 2
char* szConfigName;
void ResetState() {}
void LoadConfig(char** buf) {(void) buf; }
void CheckModified() {
struct stat fileinfo;
time_t mytime = 0;
char Buf[MAX_FILENAME];
if (stat(szConfigName, &fileinfo) == -1) {
fprintf(stderr, "CheckModified() Error: Cannot stat [%s]!\n", szConfigName);
return;
} mytime = fileinfo.st_mtime;
if (mytime > 1) {
snprintf(Buf, MAX_FILENAME, \"%s\", szConfigName);
// BugID 7073: Suppressing output to stderr, it seems to be bothering dave.
// fprintf(stderr, \"CheckModified() Reloading Configuration [%s]\
\", Buf);
ResetState();
LoadConfig(Buf);
}
} |
A minimal project: |
@sean-mcmanus I looks like a VSCode issue to me. I run this: #include <cstdio>
#include <sys/stat.h>
#define MAX_FILENAME 2
char* szConfigName;
void ResetState() {}
void LoadConfig(const char* buf) {(void) buf; }
void CheckModified(int i) {
struct stat fileinfo{};
time_t mytime = 0;
char Buf[MAX_FILENAME];
if (stat(szConfigName, &fileinfo) == -1) {
fprintf(stderr, "CheckModified() Error: Cannot stat [%s]!\n", szConfigName);
return;
} mytime = fileinfo.st_mtime;
if (mytime > i) {
snprintf(Buf, MAX_FILENAME, "%s", szConfigName);
// BugID 7073: Suppressing output to stderr, it seems to be bothering dave.
// fprintf(stderr, "CheckModified() Reloading Configuration [%s]\n", Buf);
ResetState();
LoadConfig(Buf);
}
}
int main() {
int iiiiii = 0;
CheckModified(iiiiii);
} This is an updated version: |
@sean-mcmanus I applied all fixes but applying the fix |
@H-G-Hristov Thanks, I got the repro. |
The fix should be in our next insiders release (next week). |
Environment
I filed this bug agains Clang-Tidy here
llvm/llvm-project#56669
As @sean-mcmanus suggested that it maybe a VScode extension bug I'm filing it again. #9322 (comment)
Bug Summary and Steps to Reproduce
Bug Summary:
https://user-images.githubusercontent.com/47526411/180406454-7ad4fedd-813a-447b-bcb6-e8f95834c04e.png
The following was automatically fixed by Clang-Tidy and reformatted with clang-format:
Invalid output:
Steps to reproduce:
Other Extensions
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: