================
@@ -0,0 +1,54 @@
+! Tests that -finit-local= emits a controlled diagnostic rather than crashing
+! or silently misbehaving when a kind mapping produces a sub-byte or
+! non-byte-multiple width for LOGICAL or CHARACTER types.
+!
+! LOGICAL reproducer: --kind-mapping=l4:1 maps LOGICAL(4) to 1 bit.  Before
+! this fix, APInt::getSplat(1, APInt(8, 0xAA)) asserted because the destination
+! width (1) is less than the source width (8).
+!
+! CHARACTER reproducer: --kind-mapping=a1:1 maps CHARACTER(1) to 1 bit.
+! getCharacterBitsize / 8 truncates to zero, silently skipping initialization.
+! --kind-mapping=a1:12 produces a 12-bit width; integer division gives
+! kindBytes=1, so only half the bytes would be covered.
+! Both cases now emit a controlled TODO diagnostic.
+!
+! RUN: %not_todo_cmd bbc -emit-hlfir --kind-mapping=l4:1 -finit-local=0xAA %s 
-o - 2>&1 | \
+! RUN:     FileCheck %s
+
+! CHECK: not yet implemented: -finit-local= with a sub-byte LOGICAL kind 
mapping
+
+subroutine test_logical4_subbyte(res)
+  logical(kind=4) :: l
+  integer :: res
+  if (l) res = 1
+end subroutine
+
+! CHARACTER kind-mapping sub-byte case: --kind-mapping=a1:1 maps CHARACTER(1)
+! to 1 bit.  getCharacterBitsize(1) / 8 would truncate to zero, silently
+! producing no initialization.  The guard emits a controlled diagnostic 
instead.
+!
+! RUN: %not_todo_cmd bbc -emit-hlfir --kind-mapping=a1:1 -finit-local=0xAA %s 
-o - 2>&1 | \
+! RUN:     FileCheck --check-prefix=CHAR-SUBBYTE %s
+
+! CHAR-SUBBYTE: not yet implemented: -finit-local= with a sub-byte or 
non-byte-multiple CHARACTER kind mapping
+
+subroutine test_char1_subbyte(res)
+  character(kind=1, len=2) :: c
+  integer :: res
+  res = ichar(c(1:1))
+end subroutine
+
+! CHARACTER kind-mapping non-byte-multiple case: --kind-mapping=a1:12 maps
+! CHARACTER(1) to 12 bits.  getCharacterBitsize(1) / 8 = 1, so the loop
+! would run nUnits times with a 1-byte stride, covering only half the storage.
+!
+! RUN: %not_todo_cmd bbc -emit-hlfir --kind-mapping=a1:12 -finit-local=0xAA %s 
-o - 2>&1 | \
+! RUN:     FileCheck --check-prefix=CHAR-NONBYTE %s
+
+! CHAR-NONBYTE: not yet implemented: -finit-local= with a sub-byte or 
non-byte-multiple CHARACTER kind mapping
+
+subroutine test_char1_nonbyte(res)
----------------
MattPD wrote:

The first `TODO` reached aborts lowering, so only the first subroutine that 
trips a guard is ever lowered. This subroutine has the same declarations as 
`test_char1_subbyte`, so both CHARACTER runs stop in `test_char1_subbyte`.

Running each RUN line's command on this file reports:

```
--kind-mapping=l4:1    loc(...:20:1)   ConvertVariable.cpp:1450
--kind-mapping=a1:1    loc(...:35:1)   ConvertVariable.cpp:1496
--kind-mapping=a1:12   loc(...:35:1)   ConvertVariable.cpp:1496
```

This subroutine is never lowered, and removing it would not change either 
CHARACTER result. The `% 8` branch is still covered, because 
`test_char1_subbyte` takes it under `a1:12`.

The runtime-length guard on line 1756 has no coverage. Both new declarations 
are `character(kind=1, len=2)`. Across the suite, only this file and 
`finit-local-kind-mapping.f90` pass `--kind-mapping`. Neither declares a 
runtime-length CHARACTER.

Both guards emit the same text, so `FileCheck` cannot distinguish them. Only 
the `ConvertVariable.cpp:NNNN` line in the diagnostic identifies which one 
fired. Could you add a runtime-length case in its own compilation? One 
compilation cannot reach both guards, because the first `TODO` ends the run.

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

Reply via email to