================
@@ -0,0 +1,64 @@
+// Verify that -mloadtime-comment-vars= diagnoses named C variables it cannot
+// preserve. The diagnostics are produced by Sema and fire even with
+// -fsyntax-only.
+//
+// Covered cases:
+//   - volatile-qualified pointer (char *volatile)
+//   - pointer-to-volatile character (volatile char *)
+//   - volatile character array (volatile char[])
+//   - thread-local variable (__thread, not static storage duration)
+//   - pointer not initialized directly with a string literal
+//   - name-matched variables of an unsupported type (int, unsigned char)
+//   - valid const char array — no diagnostic
+//   - a preserved variable counts as used: no -Wunused-const-variable for it,
+//     while an unlisted static const variable still warns
+//
+// The NONAIX scenario invokes cc1 directly for a non-AIX target: the option
+// is rejected with an error.
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix -Wunused-const-variable \
+// RUN:   
-mloadtime-comment-vars=vol_ptr,vol_char,vol_arr,tls_ptr,ind_ptr,const_arr,lfn,kept,notchar,ustr
 \
----------------
tonykuttai wrote:

```
❯ cat t.c
void h(void) {
  static char lfn[] = "@(#) lfn";
  (void)lfn;
}

❯ clang -cc1 -triple powerpc64-ibm-aix -ast-dump t.c                            
         
.....
`-FunctionDecl 0x79d719f000 <t.c:1:1, line:4:1> line:1:6 h 'void (void)' 
external-linkage
  `-CompoundStmt 0x79d719f2a8 <col:14, line:4:1> FPEvalMethod=1
    |-DeclStmt 0x79d719f220 <line:2:3, col:33>
    | `-VarDecl 0x79d719f160 <col:3, col:23> col:15 used lfn 'char[9]' static 
cinit
    |   `-StringLiteral 0x79d719f200 <col:23> 'char[9]' "@(#) lfn"
    `-CStyleCastExpr 0x79d719f280 <line:3:3, col:9> 'void' <ToVoid>
      `-ImplicitCastExpr 0x79d719f268 <col:9> 'char *' <ArrayToPointerDecay> 
part_of_explicit_cast
        `-DeclRefExpr 0x79d719f238 <col:9> 'char[9]' lvalue Var 0x79d719f160 
'lfn' 'char[9]'
```

Sema matches the `ASTNameGenerator` returned named, so `lfn` matches. But it 
uses `h.lfn` in Clang codegen though.

```
❯ clang -cc1 -triple powerpc64-ibm-aix -emit-llvm -o - t.c 
-mloadtime-comment-vars=lfn 
t.c:2:15: warning: 'lfn' named in '-mloadtime-comment-vars=' is a 
function-local variable and will not be preserved [-Wloadtime-comment-var]
    2 |   static char lfn[] = "@(#) lfn";
      |               ^
; ModuleID = 't.c'
source_filename = "t.c"
target datalayout = 
"E-m:a-Fi64-i64:64-i128:128-n32:64-f64:32:64-S128-v256:256:256-v512:512:512"
target triple = "powerpc64-ibm-aix"

@h.lfn = internal global [9 x i8] c"@(#) lfn\00", align 1

; Function Attrs: noinline nounwind optnone
define void @h() #0 {
entry:
  ret void
}

attributes #0 = { noinline nounwind optnone "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" }

!llvm.ident = !{!0}

!0 = !{!"clang version 24.0.0git"}
1 warning generated.
```

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

Reply via email to