]> granicus.if.org Git - clang/commitdiff
Teach the analyzer that __builtin_assume_aligned returns its first argument.
authorJordan Rose <jordan_rose@apple.com>
Tue, 9 Sep 2014 21:42:16 +0000 (21:42 +0000)
committerJordan Rose <jordan_rose@apple.com>
Tue, 9 Sep 2014 21:42:16 +0000 (21:42 +0000)
Patch by Daniel Fahlgren!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@217461 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
test/Analysis/builtin-functions.cpp

index a871049848835915cafc549f055adce99d44ce1b..104a81eac4c74af8878b5a8682140ab1a4991798 100644 (file)
@@ -42,8 +42,10 @@ bool BuiltinFunctionChecker::evalCall(const CallExpr *CE,
     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 72d5ad23b16e82bc430939eb73454068db3c4900..d3afab5bd6150d28d54ae4e4915f760a7b8725a1 100644 (file)
@@ -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}}
+}