1 // RUN: %clang_analyze_cc1 -triple=x86_64-unknown-unknown \
2 // RUN: -analyzer-checker debug.ExprInspection,core -Wno-error=invalid-gnu-asm-cast -w %s -verify
4 int clang_analyzer_eval(int);
5 void clang_analyzer_dump(int);
6 void clang_analyzer_dump_ptr(void *);
9 void testRValueOutput() {
11 __asm__("" : "=r"(((int)(global
)))); // don't crash on rvalue output operand
12 int newVal
= global
; // Value "after" the invalidation.
13 clang_analyzer_eval(origVal
== newVal
); // expected-warning{{TRUE}} expected-warning{{FALSE}}
16 void *MyMemcpy(void *d
, const void *s
, const int n
) {
19 :: "S" (s
), "D" (d
), "c" (n
) : "memory"
24 void testInlineAsmMemcpy(void)
27 MyMemcpy(&a
, &b
, sizeof(b
));
31 void testInlineAsmMemcpyArray(void)
33 int a
[10], b
[10] = {}, c
;
34 MyMemcpy(&a
, &b
, sizeof(b
));
35 c
= a
[8]; // no-warning
38 void testInlineAsmMemcpyUninit(void)
40 int a
[10], b
[10] = {}, c
;
41 MyMemcpy(&a
[1], &b
[1], sizeof(b
) - sizeof(b
[1]));
42 c
= a
[0]; // FIXME: should be warning about uninitialized value, but invalidateRegions() also
43 // invalidates super region.
46 void testInlineAsmMemcpyUninitLoop(const void *src
, unsigned long len
)
49 unsigned long toCopy
= sizeof(a
) < len
? sizeof(a
) : len
;
51 MyMemcpy(a
, src
, toCopy
);
53 // Use index 1, since before use of invalidateRegions in VisitGCCAsmStmt, engine bound unknown SVal only to
55 c
= a
[1]; // no-warning
58 void testAsmWithVoidPtrArgument()
60 extern void *globalVoidPtr
;
61 clang_analyzer_dump(*(int *)globalVoidPtr
); // expected-warning-re {{reg_${{[0-9]+}}<int Element{SymRegion{reg_${{[0-9]+}}<void * globalVoidPtr>},0 S64b,int}>}}
62 clang_analyzer_dump_ptr(globalVoidPtr
); // expected-warning-re {{&SymRegion{reg_${{[0-9]+}}<void * globalVoidPtr>}}}
63 asm ("" : : "a"(globalVoidPtr
)); // no crash
64 clang_analyzer_dump(*(int *)globalVoidPtr
); // expected-warning {{derived_}}
65 clang_analyzer_dump_ptr(globalVoidPtr
); // expected-warning-re {{&SymRegion{reg_${{[0-9]+}}<void * globalVoidPtr>}}}