Skip to content

Commit e80f7ff

Browse files
EthanLuisMcDonoughjdenny-ornl
authored andcommitted
Prepend target prefix to basename
This fix is cherry-picked from c6b34ad from PR#93365.
1 parent e690e2a commit e80f7ff

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

compiler-rt/lib/profile/InstrProfilingFile.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,10 +1356,21 @@ int __llvm_write_custom_profile(const char *Target,
13561356
TargetFilename =
13571357
(char *)COMPILER_RT_ALLOCA(FilenameLength + TargetLength + 2);
13581358

1359+
/* Find file basename and path sizes */
1360+
int32_t DirEnd = FilenameLength - 1;
1361+
while (DirEnd >= 0 && !IS_DIR_SEPARATOR(Filename[DirEnd])) {
1362+
DirEnd--;
1363+
}
1364+
uint32_t DirSize = DirEnd + 1, BaseSize = FilenameLength - DirSize;
1365+
13591366
/* Prepend "TARGET." to current filename */
1360-
memcpy(TargetFilename, Target, TargetLength);
1361-
TargetFilename[TargetLength] = '.';
1362-
memcpy(TargetFilename + 1 + TargetLength, Filename, FilenameLength);
1367+
if (DirSize > 0) {
1368+
memcpy(TargetFilename, Filename, DirSize);
1369+
}
1370+
memcpy(TargetFilename + DirSize, Target, TargetLength);
1371+
TargetFilename[TargetLength + DirSize] = '.';
1372+
memcpy(TargetFilename + DirSize + 1 + TargetLength, Filename + DirSize,
1373+
BaseSize);
13631374
TargetFilename[FilenameLength + 1 + TargetLength] = 0;
13641375

13651376
/* Check if there is llvm/runtime version mismatch. */

0 commit comments

Comments
 (0)