aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Analysis/FormatString.cpp
AgeCommit message (Collapse)AuthorFilesLines
2018-11-02Reapply Logging: make os_log buffer size an integer constant expression.Tim Northover1-955/+0
The size of an os_log buffer is known at any stage of compilation, so making it a constant expression means that the common idiom of declaring a buffer for it won't result in a VLA. That allows the compiler to skip saving and restoring the stack pointer around such buffers. This also moves the OSLog and other FormatString helpers from libclangAnalysis to libclangAST to avoid a circular dependency. llvm-svn: 345971
2018-11-01Fix clang -Wimplicit-fallthrough warnings across llvm, NFCReid Kleckner1-1/+1
This patch should not introduce any behavior changes. It consists of mostly one of two changes: 1. Replacing fall through comments with the LLVM_FALLTHROUGH macro 2. Inserting 'break' before falling through into a case block consisting of only 'break'. We were already using this warning with GCC, but its warning behaves slightly differently. In this patch, the following differences are relevant: 1. GCC recognizes comments that say "fall through" as annotations, clang doesn't 2. GCC doesn't warn on "case N: foo(); default: break;", clang does 3. GCC doesn't warn when the case contains a switch, but falls through the outer case. I will enable the warning separately in a follow-up patch so that it can be cleanly reverted if necessary. Reviewers: alexfh, rsmith, lattner, rtrieu, EricWF, bollu Differential Revision: https://reviews.llvm.org/D53950 llvm-svn: 345882
2018-10-30NFC: Remove the ObjC1/ObjC2 distinction from clang (and related projects)Erik Pilkington1-1/+1
We haven't supported compiling ObjC1 for a long time (and never will again), so there isn't any reason to keep these separate. This patch replaces LangOpts::ObjC1 and LangOpts::ObjC2 with LangOpts::ObjC. Differential revision: https://reviews.llvm.org/D53547 llvm-svn: 345637
2018-09-19Sema: handle `wint_t` more carefully for printf checkingSaleem Abdulrasool1-4/+6
In the case that `win_t` is an `unsigned short` (e.g. on Windows), we would previously incorrectly diagnose the conversion because we would immediately promote the argument type from `wint_t` (aka `unsigned short`) to `int` before checking if the type matched. This should repair the Windows hosted bots. llvm-svn: 342565
2018-07-30Remove trailing spaceFangrui Song1-5/+5
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338291
2016-10-24Add support for __builtin_os_log_format[_buffer_size]Mehdi Amini1-0/+3
This reverts commit r285007 and reapply r284990, with a fix for the opencl test that I broke. Original commit message follows: These new builtins support a mechanism for logging OS events, using a printf-like format string to specify the layout of data in a buffer. The _buffer_size version of the builtin can be used to determine the size of the buffer to allocate to hold the data, and then __builtin_os_log_format can write data into that buffer. This implements format checking to report mismatches between the format string and the data arguments. Most of this code was written by Chris Willmore. Differential Revision: https://reviews.llvm.org/D25888 llvm-svn: 285019
2016-10-24Revert "Add support for __builtin_os_log_format[_buffer_size]"Mehdi Amini1-3/+0
This reverts commit r284990, two opencl test are broken llvm-svn: 285007
2016-10-24Add support for __builtin_os_log_format[_buffer_size]Mehdi Amini1-0/+3
These new builtins support a mechanism for logging OS events, using a printf-like format string to specify the layout of data in a buffer. The _buffer_size version of the builtin can be used to determine the size of the buffer to allocate to hold the data, and then __builtin_os_log_format can write data into that buffer. This implements format checking to report mismatches between the format string and the data arguments. Most of this code was written by Chris Willmore. Differential Revision: https://reviews.llvm.org/D25888 llvm-svn: 284990
2016-09-30Move UTF functions into namespace llvm.Justin Lebar1-3/+4
Summary: This lets people link against LLVM and their own version of the UTF library. I determined this only affects llvm, clang, lld, and lldb by running $ git grep -wl 'UTF[0-9]\+\|\bConvertUTF\bisLegalUTF\|getNumBytesFor' | cut -f 1 -d '/' | sort | uniq clang lld lldb llvm Tested with ninja lldb ninja check-clang check-llvm check-lld (ninja check-lldb doesn't complete for me with or without this patch.) Reviewers: rnk Subscribers: klimek, beanz, mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D24996 llvm-svn: 282822
2016-08-20[Sema] Don't crash on scanf on forward-declared enums.Benjamin Kramer1-3/+14
This is valid in GNU C, which allows pointers to incomplete enums. GCC just pretends that the underlying type is 'int' in those cases, follow that behavior. llvm-svn: 279374
2016-04-26Check 'r' and 'y specifiers of freebsd_kernel_printf format strings on PS4Sunil Srivastava1-2/+2
This is an addendum to r229921. llvm-svn: 267625
2016-03-29[Sema] Handle UTF-8 invalid format string specifiersBruno Cardoso Lopes1-0/+23
Improve invalid format string specifier handling by printing out invalid specifiers characters with \x, \u and \U. Previously clang would print gargabe whenever the character is unprintable. Example, before: NSLog(@"%\u25B9"); => warning: invalid conversion specifier ' [-Wformat-invalid-specifier] after: NSLog(@"%\u25B9"); => warning: invalid conversion specifier '\u25b9' [-Wformat-invalid-specifier] Differential Revision: http://reviews.llvm.org/D18296 rdar://problem/24672159 llvm-svn: 264752
2016-02-18Remove use of builtin comma operator.Richard Trieu1-4/+12
Cleanup for upcoming Clang warning -Wcomma. No functionality change intended. llvm-svn: 261271
2015-10-20Roll-back r250822.Angel Garcia Gomez1-1/+1
Summary: It breaks the build for the ASTMatchers Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D13893 llvm-svn: 250827
2015-10-20Apply modernize-use-default to clang.Angel Garcia Gomez1-1/+1
Summary: Replace empty bodies of default constructors and destructors with '= default'. Reviewers: bkramer, klimek Subscribers: klimek, alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13890 llvm-svn: 250822
2015-05-18Wrap to 80 columns. No behavior change.Nico Weber1-1/+2
llvm-svn: 237549
2015-03-04Add a format warning for "%p" with non-void* argsSeth Cantrell1-37/+45
GCC -pedantic produces a format warning when the "%p" specifier is used with arguments that are not void*. It's useful for portability to be able to catch such warnings with clang as well. The warning is off by default in both gcc and with this patch. This patch enables it either when extensions are disabled with -pedantic, or with the specific flag -Wformat-pedantic. The C99 and C11 specs do appear to require arguments corresponding to 'p' specifiers to be void*: "If any argument is not the correct type for the corresponding conversion specification, the behavior is undefined." [7.19.6.1 p9], and of the 'p' format specifier "The argument shall be a pointer to void." [7.19.6.1 p8] Both printf and scanf format checking are covered. llvm-svn: 231211
2015-02-19Add support for analyzing FreeBSD kernel printf extensions.Dimitry Andric1-0/+16
This adds a new __freebsd_kprintf__ format string type, which enables checking when used in __attribute__((format(...))) attributes. It can check the FreeBSD kernel specific %b, %D, %r and %y specifiers, using existing diagnostic messages. Also adds test cases for all these specifiers. Differential Revision: http://reviews.llvm.org/D7154 llvm-svn: 229921
2014-09-07MS format strings: parse the 'Z' printf conversion specifier (PR20808)Hans Wennborg1-1/+8
llvm-svn: 217326
2014-09-04MS format strings: allow the 'h' length modifier with C, C, s and S (PR20808)Hans Wennborg1-1/+13
llvm-svn: 217196
2014-09-04MS format strings: support the 'w' length modifier (PR20808)Hans Wennborg1-0/+15
llvm-svn: 217195
2014-08-29Add a comment, no functional change.Nico Weber1-1/+1
llvm-svn: 216777
2014-05-20[C++11] Use 'nullptr'. Analysis edition.Craig Topper1-3/+3
llvm-svn: 209191
2013-08-21Analysis: Add support for MS specific printf format specifiersDavid Majnemer1-1/+45
Summary: Adds support for %I, %I32 and %I64. Reviewers: hans, jordan_rose, rnk, majnemer Reviewed By: majnemer CC: cfe-commits, cdavis5x Differential Revision: http://llvm-reviews.chandlerc.com/D1456 llvm-svn: 188937
2013-05-10Add support for __wchar_t in -fms-extensions mode.Hans Wennborg1-2/+2
MSVC provides __wchar_t. This is the same as the built-in wchar_t type from C++, but it is also available with -fno-wchar and in C. The commit changes ASTContext to have two different types for this: - WCharTy is the built-in type used for wchar_t in C++ and __wchar_t. - WideCharTy is the type of a wide character literal. In C++ this is the same as WCharTy, and in C it is an integer type compatible with the type in <stddef.h>. This fixes PR15815. llvm-svn: 181587
2013-02-21Use None rather than Optional<T>() where possible.David Blaikie1-2/+2
llvm-svn: 175705
2013-02-20Include llvm::Optional in clang/Basic/LLVM.hDavid Blaikie1-5/+4
Post-commit CR feedback from Jordan Rose regarding r175594. llvm-svn: 175679
2013-01-02s/CPlusPlus0x/CPlusPlus11/gRichard Smith1-1/+1
llvm-svn: 171367
2012-09-13Format strings: offer a fixit for Darwin's %D/%U/%O to ISO %d/%u/%o.Jordan Rose1-0/+23
<rdar://problem/12061922> llvm-svn: 163772
2012-09-13Format strings: %D, %U, and %O are valid on Darwin (same as %d, %u, %o).Jordan Rose1-0/+12
These will warn under -Wformat-non-iso, and will still be rejected outright on other platforms. <rdar://problem/12061922> llvm-svn: 163771
2012-09-08Format strings: suggest %lld instead of %qd and %Ld with -Wformat-non-iso.Jordan Rose1-11/+3
As a corollary to the previous commit, even when an extension is available, we can still offer a fixit to the standard modifier. llvm-svn: 163453
2012-09-08Format strings: %Ld isn't available on Darwin or Windows.Jordan Rose1-3/+27
This seems to be a GNU libc extension; we offer a fixit to %lld on these platforms. <rdar://problem/11518237> llvm-svn: 163452
2012-08-07Remove ScanfArgType and bake that logic into ArgType.Hans Wennborg1-18/+48
This is useful for example for %n in printf, which expects a pointer to int with the same logic for checking as %d would have in scanf. llvm-svn: 161407
2012-08-07Rename analyze_format_string::ArgTypeResult to ArgTypeHans Wennborg1-10/+10
Also remove redundant constructors and unused member functions. llvm-svn: 161403
2012-07-31-Wformat: better handling of qualifiers on pointer argumentsHans Wennborg1-0/+7
Warn about using pointers to const-qualified types as arguments to scanf. Ignore the volatile qualifier when checking if types match. llvm-svn: 161052
2012-07-27Make -Wformat walk the typedef chain when looking for size_t, etc.Hans Wennborg1-0/+34
Clang's -Wformat fix-its currently suggest using "%zu" for values of type size_t (in C99 or C++11 mode). However, for a type such as std::vector<T>::size_type, it does not notice that type is actually typedeffed to size_t, and instead suggests a format for the underlying type, such as "%lu" or "%u". This commit makes the format string fix mechanism walk the typedef chain so that it notices if the type is size_t, even if that isn't "at the top". llvm-svn: 160886
2012-06-04Teach printf/scanf about enums with fixed underlying types.Jordan Rose1-0/+6
llvm-svn: 157961
2012-05-08Make -Wformat accept printf("%hhx", c); with -funsigned-charHans Wennborg1-2/+1
For "%hhx", printf expects an unsigned char. This makes Clang accept a 'char' argument for that also when using -funsigned-char. This fixes PR12761. llvm-svn: 156388
2012-05-04Fix handling of wint_t - we can't assume wint_t is purely an integer ↵James Molloy1-10/+10
promotion of wchar_t - they may differ in signedness. Teach ASTContext about WIntType, and have it taken from TargetInfo like WCharType. Should fix test/Sema/format-strings.c for ARM, with the exception of one subtest which will fail if wint_t and wchar_t are the same size and wint_t is signed, wchar_t is unsigned. There'll be a followup commit to fix that. Reviewed by Chandler and Hans at http://llvm.org/reviews/r/8 llvm-svn: 156165
2012-03-15Support '%p' format specifier with block pointers.Ted Kremenek1-1/+1
llvm-svn: 152839
2012-03-09-Wformat-non-iso: warn about positional arguments (pr12017)Hans Wennborg1-0/+3
This renames the -Wformat-non-standard flag to -Wformat-non-iso, rewords the current warnings a bit (pointing out that a format string is not supported by ISO C rather than being "non standard"), and adds a warning about positional arguments. llvm-svn: 152403
2012-02-22Warn about non-standard format strings (pr12017)Hans Wennborg1-0/+71
This adds the -Wformat-non-standard flag (off by default, enabled by -pedantic), which warns about non-standard things in format strings (such as the 'q' length modifier, the 'S' conversion specifier, etc.) llvm-svn: 151154
2012-02-16Format string analysis: give 'q' its own enumerator.Hans Wennborg1-3/+6
This is in preparation for being able to warn about 'q' and other non-standard format string features. It also allows us to print its name correctly. llvm-svn: 150697
2012-02-06Tweak format string checking to work with %@ and ObjC toll-free bridging. ↵Ted Kremenek1-3/+17
<rdar://problem/10814120> llvm-svn: 149907
2012-01-31Format string warnings: don't a.k.a. wchar_t with wchar_t.Hans Wennborg1-1/+1
This fixes the case where Clang would output: error: format specifies type 'wchar_t *' (aka 'wchar_t *') ArgTypeResult::getRepresentativeTypeName needs to take into account that wchar_t can be a built-in type (as opposed to in C, where it is a typedef). llvm-svn: 149387
2012-01-25Fix NSLog format string checking for %@.Ted Kremenek1-1/+2
llvm-svn: 148885
2012-01-24Teach scanf/printf checking about '%Ld' and friends (a GNU extension). ↵Ted Kremenek1-0/+8
Fixes PR 9466. llvm-svn: 148859
2012-01-20The 'l' length modifier makes sense with the scanlist conversion specifier.Ted Kremenek1-0/+1
llvm-svn: 148586
2012-01-20More dead code removal (using -Wunreachable-code)David Blaikie1-7/+3
llvm-svn: 148577
2012-01-12scanf: parse the 'm' length modifier, and check that the right argumentsHans Wennborg1-0/+21
are used with that and the 'a' length modifier. llvm-svn: 148029