================
@@ -0,0 +1,31 @@
+// DEFINE: %{analyze} = %clang_analyze_cc1 \
+// DEFINE:   -analyzer-checker=core,unix.StdCLibraryFunctions \
+// DEFINE:   -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=true
+
+// RUN: %{analyze} -triple arm64-apple-darwin -verify=darwin %s
+// RUN: %{analyze} -triple x86_64-unknown-linux-gnu -verify=linux %s
+
+typedef unsigned long size_t;
+typedef long off_t;
+void *mmap(void *, size_t, int, int, int, off_t);
+
+#define MAP_PRIVATE 0x0002
+#define MAP_ANON    0x1000
+
+// VM_MAKE_TAG on Darwin encodes a Mach VM memory tag in the top 8 bits.
+// For tags >= 128 the result is a large negative signed integer.
+#define VM_MAKE_TAG(tag) ((int)((unsigned)(tag) << 24))
+#define VM_MEMORY_APPLICATION_SPECIFIC_1 240
+
+void test_mmap_vm_make_tag(void) {
+  void *p = mmap(0, 4096, 0, MAP_ANON | MAP_PRIVATE,
+                 VM_MAKE_TAG(VM_MEMORY_APPLICATION_SPECIFIC_1), 0);
+  // darwin-no-warning: no bound restriction on fd parameter on Darwin
+  // linux-warning@-3 {{The 5th argument to 'mmap' is -268435456 but should be 
>= -1}}
+}
+
+void test_mmap_size_constraint(void) {
+  void *p = mmap(0, 0, 0, MAP_ANON | MAP_PRIVATE, -1, 0);
+  // darwin-warning@-1 {{The 2nd argument to 'mmap' is 0 but should be > 0}}
+  // linux-warning@-2 {{The 2nd argument to 'mmap' is 0 but should be > 0}}
----------------
steakhal wrote:

Let's align these two.
```suggestion
  // linux-warning@-2  {{The 2nd argument to 'mmap' is 0 but should be > 0}}
```

FYI I don't think its worth it but you could pass multiple verify prefixes: 
`-verify=common,darwin` which would mean that both `common` and `darwin` lines 
would be matched, etc. That way you can naturally express the warning subset 
relations. It's a total overkill for this single instance but wanted to point 
this out for the future. 

https://github.com/llvm/llvm-project/pull/219568
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to