diff options
author | partouf <partouf@gmail.com> | 2024-03-02 01:07:37 +0100 |
---|---|---|
committer | partouf <partouf@gmail.com> | 2024-03-02 01:07:37 +0100 |
commit | 9579c5aa9fa2b7407c502492140c6c5d38bb186b (patch) | |
tree | d2faa683ae8b0f115e560339b20436d342d4dfc4 | |
parent | 5ebd04f90ef0ab94ed9d14dc6662d5550a6f6b41 (diff) | |
download | compiler-explorer-gh-10822.tar.gz compiler-explorer-gh-10822.zip |
fix llvm-covgh-10822
-rw-r--r-- | etc/config/c++.amazon.properties | 6 | ||||
-rw-r--r-- | lib/base-compiler.ts | 36 | ||||
-rw-r--r-- | lib/tooling/llvm-cov-tool.ts | 33 | ||||
-rw-r--r-- | types/compilation/compilation.interfaces.ts | 39 |
4 files changed, 93 insertions, 21 deletions
diff --git a/etc/config/c++.amazon.properties b/etc/config/c++.amazon.properties index 02d498551..998431a85 100644 --- a/etc/config/c++.amazon.properties +++ b/etc/config/c++.amazon.properties @@ -228,6 +228,7 @@ group.clang.compilerType=clang group.clang.unwiseOptions=-march=native group.clang.supportsPVS-Studio=true group.clang.supportsSonar=true +group.clang.supportsLlvmCov=true group.clang.licenseName=LLVM Apache 2 group.clang.licenseLink=https://github.com/llvm/llvm-project/blob/main/LICENSE.TXT group.clang.licensePreamble=The LLVM Project is under the Apache License v2.0 with LLVM Exceptions @@ -395,6 +396,7 @@ group.clangx86trunk.compilerType=clang group.clangx86trunk.unwiseOptions=-march=native group.clangx86trunk.supportsPVS-Studio=true group.clangx86trunk.supportsSonar=true +group.clangx86trunk.supportsLlvmCov=true group.clangx86trunk.ldPath=${exePath}/../lib|${exePath}/../lib/x86_64-unknown-linux-gnu group.clangx86trunk.compilerCategories=clang @@ -575,6 +577,7 @@ group.clang-rocm.compilerType=clang group.clang-rocm.unwiseOptions=-march=native group.clang-rocm.supportsPVS-Studio=true group.clang-rocm.supportsSonar=true +group.clang-rocm.supportsLlvmCov=true group.clang-rocm.licenseName=LLVM Apache 2 and NCSA group.clang-rocm.licenseLink=https://github.com/RadeonOpenCompute/llvm-project/blob/amd-stg-open/LICENSE.TXT # and https://github.com/RadeonOpenCompute/ROCm-Device-Libs/blob/amd-stg-open/LICENSE.TXT @@ -4739,10 +4742,11 @@ tools.ldd.class=readelf-tool tools.ldd.exclude=djggp tools.ldd.stdinHint=disabled -tools.llvm-covtrunk.name=llvm-cov (trunk) +tools.llvm-covtrunk.name=llvm-cov (clang-only) tools.llvm-covtrunk.exe=/opt/compiler-explorer/clang-trunk/bin/llvm-cov tools.llvm-covtrunk.type=postcompilation tools.llvm-covtrunk.class=llvm-cov-tool +tools.llvm-covtrunk.includeKey=supportsLlvmCov tools.llvm-mcatrunk.name=llvm-mca (trunk) tools.llvm-mcatrunk.exe=/opt/compiler-explorer/clang-trunk/bin/llvm-mca diff --git a/lib/base-compiler.ts b/lib/base-compiler.ts index 70ec59b49..f41bae8c0 100644 --- a/lib/base-compiler.ts +++ b/lib/base-compiler.ts @@ -34,8 +34,11 @@ import { BuildResult, BuildStep, BypassCache, + CacheKey, + CmakeCacheKey, CompilationCacheKey, CompilationInfo, + CompilationInfo2, CompilationResult, CompileChildLibraries, CustomInputForTool, @@ -1723,7 +1726,11 @@ export class BaseCompiler implements ICompiler { return await this.postProcess(asmResult, outputFilename, filters); } - runToolsOfType(tools, type: ToolTypeKey, compilationInfo): Promise<ToolResult>[] { + runToolsOfType( + tools, + type: ToolTypeKey, + compilationInfo: CompilationInfo | CompilationInfo2, + ): Promise<ToolResult>[] { const tooling: Promise<ToolResult>[] = []; if (tools) { for (const tool of tools) { @@ -2149,11 +2156,11 @@ export class BaseCompiler implements ICompiler { return result; } - getCacheKey(source, options, backendOptions, filters, tools, libraries, files) { + getCacheKey(source, options, backendOptions, filters, tools, libraries, files): CacheKey { return {compiler: this.compiler, source, options, backendOptions, filters, tools, libraries, files}; } - getCmakeCacheKey(key, files) { + getCmakeCacheKey(key, files): CmakeCacheKey { const cacheKey = Object.assign({}, key); cacheKey.compiler = this.compiler; cacheKey.files = files; @@ -2166,13 +2173,26 @@ export class BaseCompiler implements ICompiler { return cacheKey; } - getCompilationInfo( + getCompilationInfo(key: CompilationCacheKey, result: CompilationResult, customBuildPath?: string): CompilationInfo { + return { + outputFilename: this.getOutputFilename(customBuildPath || result.dirPath || '', this.outputFilebase, key), + executableFilename: this.getExecutableFilename( + customBuildPath || result.dirPath || '', + this.outputFilebase, + key, + ), + asmParser: this.asm, + ...key, + ...result, + }; + } + + getCompilationInfo2( key: CompilationCacheKey, - result: CompilationResult | CustomInputForTool, + result: CustomInputForTool, customBuildPath?: string, - ): CompilationInfo { + ): CompilationInfo2 { return { - outputFilename: this.getOutputFilename(customBuildPath || result.dirPath || '', this.outputFilebase, key), executableFilename: this.getExecutableFilename( customBuildPath || result.dirPath || '', this.outputFilebase, @@ -2316,7 +2336,7 @@ export class BaseCompiler implements ICompiler { this.runToolsOfType( tools, 'independent', - this.getCompilationInfo(key, { + this.getCompilationInfo2(key, { inputFilename, dirPath, outputFilename, diff --git a/lib/tooling/llvm-cov-tool.ts b/lib/tooling/llvm-cov-tool.ts index 3c2a09d2b..0b21f428b 100644 --- a/lib/tooling/llvm-cov-tool.ts +++ b/lib/tooling/llvm-cov-tool.ts @@ -24,7 +24,7 @@ import path from 'path'; -import {ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import {CompilationInfo, ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; import {BaseTool} from './base-tool.js'; @@ -33,14 +33,32 @@ export class LLVMCovTool extends BaseTool { return 'llvm-cov-tool'; } - override async runTool(compilationInfo, inputFilepath, args: string[], stdin) { + override async runTool(compilationInfo: CompilationInfo, inputFilepath, args: string[], stdin) { const compilationExecOptions = this.getDefaultExecOptions(); compilationExecOptions.customCwd = path.dirname(inputFilepath); compilationExecOptions.input = stdin; try { const generatedExecutableName = this.getUniqueFilePrefix() + '-coverage.a'; - // Remove inputs - const options = compilationInfo.compilationOptions.slice().splice(0, 4); + + let skipNext = false; + const options: string[] = []; + const withoutInputFile = (compilationInfo.compilationOptions || []).filter( + v => !v.includes(inputFilepath) && v !== '-S' && !v.startsWith('-O'), + ); + for (const v of withoutInputFile) { + if (v === '-o') { + skipNext = true; + continue; + } + + if (skipNext) { + skipNext = false; + continue; + } + + options.push(v); + } + const compilationArgs = [ ...options, '-fprofile-instr-generate', @@ -52,6 +70,8 @@ export class LLVMCovTool extends BaseTool { generatedExecutableName, ]; + const compilerPath = path.dirname(compilationInfo.compiler.exe); + const compilationResult = await this.exec( compilationInfo.compiler.exe, compilationArgs, @@ -72,8 +92,7 @@ export class LLVMCovTool extends BaseTool { input: stdin, }); - const folder = path.dirname(this.tool.exe); - const profdataPath = path.join(folder, 'llvm-profdata'); + const profdataPath = path.join(compilerPath, 'llvm-profdata'); const generatedProfdataName = this.getUniqueFilePrefix() + '.profdata'; const profdataResult = await this.exec( @@ -88,7 +107,7 @@ export class LLVMCovTool extends BaseTool { } const covResult = await this.exec( - this.tool.exe, + path.join(compilerPath, 'llvm-cov'), [ 'show', './' + generatedExecutableName, diff --git a/types/compilation/compilation.interfaces.ts b/types/compilation/compilation.interfaces.ts index 1526a76e3..ec4f45530 100644 --- a/types/compilation/compilation.interfaces.ts +++ b/types/compilation/compilation.interfaces.ts @@ -257,7 +257,25 @@ export type BuildStep = BasicExecutionResult & { step: string; }; -export type CompilationInfo = { +export type CompilationInfo = CompilationResult & { + mtime: Date | null; + compiler: CompilerInfo & Record<string, unknown>; + args: string[]; + options: ExecutionOptions; + outputFilename: string; + executableFilename: string; + asmParser: IAsmParser; + inputFilename?: string; + dirPath?: string; +}; + +export type CustomInputForTool = { + inputFilename: string; + dirPath: string; + outputFilename: string; +}; + +export type CompilationInfo2 = CustomInputForTool & { mtime: Date | null; compiler: CompilerInfo & Record<string, unknown>; args: string[]; @@ -276,10 +294,21 @@ export type CompilationCacheKey = { options: ExecutionOptions; }; -export type CustomInputForTool = { - inputFilename: string; - dirPath: string; - outputFilename: string; +export type CacheKey = { + compiler: any; + source: string; + options: string[]; + backendOptions: any; + filters?: any; + tools: any[]; + libraries: any[]; + files: any[]; +}; + +export type CmakeCacheKey = CacheKey & { + compiler: CompilerInfo; + files: []; + api: string; }; export type FiledataPair = { |