r217461 - Teach the analyzer that __builtin_assume_aligned returns its first argument.
Jordan Rose
jordan_rose at apple.com
Tue Sep 9 14:42:16 PDT 2014
Author: jrose
Date: Tue Sep 9 16:42:16 2014
New Revision: 217461
URL: http://llvm.org/viewvc/llvm-project?rev=217461&view=rev
Log:
Teach the analyzer that __builtin_assume_aligned returns its first argument.
Patch by Daniel Fahlgren!
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
cfe/trunk/test/Analysis/builtin-functions.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp?rev=217461&r1=217460&r2=217461&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp Tue Sep 9 16:42:16 2014
@@ -42,8 +42,10 @@ bool BuiltinFunctionChecker::evalCall(co
return false;
case Builtin::BI__builtin_expect:
+ case Builtin::BI__builtin_assume_aligned:
case Builtin::BI__builtin_addressof: {
- // For __builtin_expect, just return the value of the subexpression.
+ // For __builtin_expect and __builtin_assume_aligned, just return the value
+ // of the subexpression.
// __builtin_addressof is going from a reference to a pointer, but those
// are represented the same way in the analyzer.
assert (CE->arg_begin() != CE->arg_end());
Modified: cfe/trunk/test/Analysis/builtin-functions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/builtin-functions.cpp?rev=217461&r1=217460&r2=217461&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/builtin-functions.cpp (original)
+++ cfe/trunk/test/Analysis/builtin-functions.cpp Tue Sep 9 16:42:16 2014
@@ -22,3 +22,31 @@ void testSize() {
clang_analyzer_eval(i == 0); // expected-warning{{TRUE}}
}
+
+void test_assume_aligned_1(char *p) {
+ char *q;
+
+ q = (char*) __builtin_assume_aligned(p, 16);
+ clang_analyzer_eval(p == q); // expected-warning{{TRUE}}
+}
+
+void test_assume_aligned_2(char *p) {
+ char *q;
+
+ q = (char*) __builtin_assume_aligned(p, 16, 8);
+ clang_analyzer_eval(p == q); // expected-warning{{TRUE}}
+}
+
+void test_assume_aligned_3(char *p) {
+ void *q;
+
+ q = __builtin_assume_aligned(p, 16, 8);
+ clang_analyzer_eval(p == q); // expected-warning{{TRUE}}
+}
+
+void test_assume_aligned_4(char *p) {
+ char *q;
+
+ q = (char*) __builtin_assume_aligned(p + 1, 16);
+ clang_analyzer_eval(p == q); // expected-warning{{FALSE}}
+}
More information about the cfe-commits
mailing list