Hi,
On tis, 2014-09-09 at 12:30 +0200, Daniel Fahlgren wrote:
> This patch teaches the analyzer how the __builtin_assume_aligned()
> function works. All it does is to return the first argument it gets.
I must have been half asleep when I wrote that code, sorry. Attached is
an updated patch that avoids code duplication.
Cheers,
Daniel Fahlgren
Index: lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp (revision 217451)
+++ lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp (working copy)
@@ -42,8 +42,10 @@
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());
Index: test/Analysis/builtin-functions.cpp
===================================================================
--- test/Analysis/builtin-functions.cpp (revision 217451)
+++ test/Analysis/builtin-functions.cpp (working copy)
@@ -22,3 +22,31 @@
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}}
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits