From a14051740779e03d6bfcfacf4ca208ca44637138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Saffran?= Date: Fri, 5 Dec 2025 14:18:47 -0800 Subject: [PATCH 1/9] adding fix for codeql issues --- .../lib/DxbcConverter/DxbcConverter.cpp | 4 +-- .../dxilconv/lib/DxbcConverter/DxbcUtil.cpp | 3 +- .../unittests/HLSLExec/ExecutionTest.cpp | 2 +- utils/DSAclean.py | 32 ------------------- 4 files changed, 5 insertions(+), 36 deletions(-) delete mode 100644 utils/DSAclean.py diff --git a/projects/dxilconv/lib/DxbcConverter/DxbcConverter.cpp b/projects/dxilconv/lib/DxbcConverter/DxbcConverter.cpp index d0f00f7c73..0f586991f6 100644 --- a/projects/dxilconv/lib/DxbcConverter/DxbcConverter.cpp +++ b/projects/dxilconv/lib/DxbcConverter/DxbcConverter.cpp @@ -6393,8 +6393,8 @@ void DxbcConverter::EmitGSOutputRegisterStore(unsigned StreamId) { CompType DxbcValueType = SE.GetCompType(); Type *pDxbcValueType = DxbcValueType.GetLLVMType(m_Ctx); - for (BYTE c = 0; c < SE.GetCols(); c++) { - BYTE Comp = SE.GetStartCol() + c; + for (unsigned int c = 0; c < SE.GetCols(); c++) { + unsigned int Comp = SE.GetStartCol() + c; Value *pValue; // 1. Load value from the corresponding temp reg. diff --git a/projects/dxilconv/lib/DxbcConverter/DxbcUtil.cpp b/projects/dxilconv/lib/DxbcConverter/DxbcUtil.cpp index 2bcefd89b9..280a74522c 100644 --- a/projects/dxilconv/lib/DxbcConverter/DxbcUtil.cpp +++ b/projects/dxilconv/lib/DxbcConverter/DxbcUtil.cpp @@ -46,7 +46,8 @@ CMask::CMask(BYTE StartComp, BYTE NumComp) { (StartComp + NumComp - 1) < DXBC::kAllCompMask, "otherwise the caller did not check"); m_Mask = 0; - for (BYTE c = StartComp; c < StartComp + NumComp; c++) { + BYTE EndComp = StartComp + NumComp; + for (BYTE c = StartComp; c < EndComp; c++) { m_Mask |= (1 << c); } } diff --git a/tools/clang/unittests/HLSLExec/ExecutionTest.cpp b/tools/clang/unittests/HLSLExec/ExecutionTest.cpp index cb08b5edab..ec4f79244f 100644 --- a/tools/clang/unittests/HLSLExec/ExecutionTest.cpp +++ b/tools/clang/unittests/HLSLExec/ExecutionTest.cpp @@ -2480,7 +2480,7 @@ TEST_F(ExecutionTest, WaveIntrinsicsTest) { } // Waves should cover 4 threads or more. - LogCommentFmt(L"Found %u distinct lane ids: %u", firstLaneIds.size()); + LogCommentFmt(L"Found %u distinct lane ids", firstLaneIds.size()); if (!dxbc) { VERIFY_IS_GREATER_THAN_OR_EQUAL(values.size() / 4, firstLaneIds.size()); } diff --git a/utils/DSAclean.py b/utils/DSAclean.py deleted file mode 100644 index 6c43357019..0000000000 --- a/utils/DSAclean.py +++ /dev/null @@ -1,32 +0,0 @@ -#! /usr/bin/python - -#changelog: -#10/13/2005b: replaced the # in tmp(.#*)* with alphanumeric and _, this will then remove -#nodes such as %tmp.1.i and %tmp._i.3 -#10/13/2005: exntended to remove variables of the form %tmp(.#)* rather than just -#%tmp.#, i.e. it now will remove %tmp.12.3.15 etc, additionally fixed a spelling error in -#the comments -#10/12/2005: now it only removes nodes and edges for which the label is %tmp.# rather -#than removing all lines for which the lable CONTAINS %tmp.# -import re -import sys -if( len(sys.argv) < 3 ): - print 'usage is: ./DSAclean ' - sys.exit(1) -#get a file object -input = open(sys.argv[1], 'r') -output = open(sys.argv[2], 'w') -#we'll get this one line at a time...while we could just put the whole thing in a string -#it would kill old computers -buffer = input.readline() -while buffer != '': - if re.compile("label(\s*)=(\s*)\"\s%tmp(.\w*)*(\s*)\"").search(buffer): - #skip next line, write neither this line nor the next - buffer = input.readline() - else: - #this isn't a tmp Node, we can write it - output.write(buffer) - #prepare for the next iteration - buffer = input.readline() -input.close() -output.close() From 5a9b8bd9eee5f4d74d2b81063b1017838dd44163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Saffran?= Date: Fri, 5 Dec 2025 14:21:47 -0800 Subject: [PATCH 2/9] remove capture cmd --- tools/clang/utils/CaptureCmd | 73 ------------------------------------ 1 file changed, 73 deletions(-) delete mode 100644 tools/clang/utils/CaptureCmd diff --git a/tools/clang/utils/CaptureCmd b/tools/clang/utils/CaptureCmd deleted file mode 100644 index 705585c3bb..0000000000 --- a/tools/clang/utils/CaptureCmd +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env python - -"""CaptureCmd - A generic tool for capturing information about the -invocations of another program. - -Usage --- -1. Move the original tool to a safe known location. - -2. Link CaptureCmd to the original tool's location. - -3. Define CAPTURE_CMD_PROGRAM to the known location of the original -tool; this must be an absolute path. - -4. Define CAPTURE_CMD_DIR to a directory to write invocation -information to. -""" - -import hashlib -import os -import sys -import time - -def saveCaptureData(prefix, dir, object): - string = repr(object) + '\n' - key = hashlib.sha1(string).hexdigest() - path = os.path.join(dir, - prefix + key) - if not os.path.exists(path): - f = open(path, 'wb') - f.write(string) - f.close() - return prefix + key - -def main(): - program = os.getenv('CAPTURE_CMD_PROGRAM') - dir = os.getenv('CAPTURE_CMD_DIR') - fallback = os.getenv('CAPTURE_CMD_FALLBACK') - if not program: - raise ValueError('CAPTURE_CMD_PROGRAM is not defined!') - if not dir: - raise ValueError('CAPTURE_CMD_DIR is not defined!') - - # Make the output directory if it doesn't already exist. - if not os.path.exists(dir): - os.mkdir(dir, 0700) - - # Get keys for various data. - env = os.environ.items() - env.sort() - envKey = saveCaptureData('env-', dir, env) - cwdKey = saveCaptureData('cwd-', dir, os.getcwd()) - argvKey = saveCaptureData('argv-', dir, sys.argv) - entry = (time.time(), envKey, cwdKey, argvKey) - saveCaptureData('cmd-', dir, entry) - - if fallback: - pid = os.fork() - if not pid: - os.execv(program, sys.argv) - os._exit(1) - else: - res = os.waitpid(pid, 0) - if not res: - os.execv(fallback, sys.argv) - os._exit(1) - os._exit(res) - else: - os.execv(program, sys.argv) - os._exit(1) - -if __name__ == '__main__': - main() From e97c64b0902102c4f503f602b27fdb435e8d35e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Saffran?= Date: Fri, 5 Dec 2025 14:25:22 -0800 Subject: [PATCH 3/9] improving code formating --- projects/dxilconv/lib/DxbcConverter/DxbcUtil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/dxilconv/lib/DxbcConverter/DxbcUtil.cpp b/projects/dxilconv/lib/DxbcConverter/DxbcUtil.cpp index 280a74522c..8ab2f9118b 100644 --- a/projects/dxilconv/lib/DxbcConverter/DxbcUtil.cpp +++ b/projects/dxilconv/lib/DxbcConverter/DxbcUtil.cpp @@ -47,7 +47,7 @@ CMask::CMask(BYTE StartComp, BYTE NumComp) { "otherwise the caller did not check"); m_Mask = 0; BYTE EndComp = StartComp + NumComp; - for (BYTE c = StartComp; c < EndComp; c++) { + for (BYTE c = StartComp; c < EndComp; c++) { m_Mask |= (1 << c); } } From e5ab16c2298cee88df993d37e76c1e37b86002ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Saffran?= Date: Mon, 8 Dec 2025 14:53:28 -0800 Subject: [PATCH 4/9] add codeql comment to disable scanner --- include/dxc/Support/dxcapi.use.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index 6c4eb3f215..16e1ad5225 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -69,7 +69,7 @@ class SpecificDllLoader : public DllLoader { return S_OK; #ifdef _WIN32 - m_dll = LoadLibraryA(dllName); + m_dll = LoadLibraryA(dllName); // CodeQL [SM01925] This is by design, intended to be used to test multiple validators versions. if (m_dll == nullptr) return HRESULT_FROM_WIN32(GetLastError()); m_createFn = (DxcCreateInstanceProc)GetProcAddress(m_dll, fnName); From 10136e6e8f148aa00d93402c5216a80a4302e173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Saffran?= Date: Mon, 8 Dec 2025 14:56:03 -0800 Subject: [PATCH 5/9] add codeql comment to disable analysis --- unittests/Support/ProgramTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittests/Support/ProgramTest.cpp b/unittests/Support/ProgramTest.cpp index 84979d6288..2f34808275 100644 --- a/unittests/Support/ProgramTest.cpp +++ b/unittests/Support/ProgramTest.cpp @@ -313,7 +313,7 @@ TEST(ProgramTest, TestWriteWithSystemEncoding) { #else char buf[10]; ASSERT_EQ(::read(fd, buf, 10), 10); - ASSERT_EQ(strncmp(buf, utf8_text, 10), 0); + ASSERT_EQ(strncmp(buf, utf8_text, 10), 0); // CodeQL [SM01932] the file content is controlled by the test. #endif ::close(fd); ASSERT_NO_ERROR(fs::remove(file_pathname.str())); From be1a5ab5357bdc215c2159e4a744e85edfe709f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Saffran?= Date: Mon, 8 Dec 2025 15:03:08 -0800 Subject: [PATCH 6/9] add codeql comment to disable scanner --- include/dxc/Support/dxcapi.use.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index 16e1ad5225..77cb3f041a 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -81,7 +81,7 @@ class SpecificDllLoader : public DllLoader { return hr; } #else - m_dll = ::dlopen(dllName, RTLD_LAZY); + m_dll = ::dlopen(dllName, RTLD_LAZY); // CodeQL [SM01925] This is by design, intended to be used to test multiple validators versions. if (m_dll == nullptr) return E_FAIL; m_createFn = (DxcCreateInstanceProc)::dlsym(m_dll, fnName); From ebf740d7250cb2f8cd64a0459b672bb064dc2d0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Saffran?= Date: Mon, 8 Dec 2025 15:15:04 -0800 Subject: [PATCH 7/9] address comments from damyan --- projects/dxilconv/lib/DxbcConverter/DxbcConverter.cpp | 4 ++-- projects/dxilconv/lib/DxbcConverter/DxbcUtil.cpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/projects/dxilconv/lib/DxbcConverter/DxbcConverter.cpp b/projects/dxilconv/lib/DxbcConverter/DxbcConverter.cpp index 0f586991f6..b668feb4d9 100644 --- a/projects/dxilconv/lib/DxbcConverter/DxbcConverter.cpp +++ b/projects/dxilconv/lib/DxbcConverter/DxbcConverter.cpp @@ -6393,8 +6393,8 @@ void DxbcConverter::EmitGSOutputRegisterStore(unsigned StreamId) { CompType DxbcValueType = SE.GetCompType(); Type *pDxbcValueType = DxbcValueType.GetLLVMType(m_Ctx); - for (unsigned int c = 0; c < SE.GetCols(); c++) { - unsigned int Comp = SE.GetStartCol() + c; + for (unsigned c = 0; c < SE.GetCols(); c++) { + unsigned Comp = SE.GetStartCol() + c; Value *pValue; // 1. Load value from the corresponding temp reg. diff --git a/projects/dxilconv/lib/DxbcConverter/DxbcUtil.cpp b/projects/dxilconv/lib/DxbcConverter/DxbcUtil.cpp index 8ab2f9118b..98172bcd05 100644 --- a/projects/dxilconv/lib/DxbcConverter/DxbcUtil.cpp +++ b/projects/dxilconv/lib/DxbcConverter/DxbcUtil.cpp @@ -17,6 +17,7 @@ #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Type.h" #include "llvm/Support/Casting.h" +#include #include "DxbcUtil.h" #include "Support/DXIncludes.h" @@ -46,6 +47,7 @@ CMask::CMask(BYTE StartComp, BYTE NumComp) { (StartComp + NumComp - 1) < DXBC::kAllCompMask, "otherwise the caller did not check"); m_Mask = 0; + DXASSERT((StartComp + NumComp) < 256, "sum should fit in a BYTE"); BYTE EndComp = StartComp + NumComp; for (BYTE c = StartComp; c < EndComp; c++) { m_Mask |= (1 << c); From 56722bac443c4afad007d07ae62785efed4f0278 Mon Sep 17 00:00:00 2001 From: Joao Saffran Date: Tue, 9 Dec 2025 13:14:56 -0800 Subject: [PATCH 8/9] apply clang format --- include/dxc/Support/dxcapi.use.h | 8 ++++++-- unittests/Support/ProgramTest.cpp | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index 77cb3f041a..e1aa7aff86 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -69,7 +69,9 @@ class SpecificDllLoader : public DllLoader { return S_OK; #ifdef _WIN32 - m_dll = LoadLibraryA(dllName); // CodeQL [SM01925] This is by design, intended to be used to test multiple validators versions. + m_dll = LoadLibraryA( + dllName); // CodeQL [SM01925] This is by design, intended to be used to + // test multiple validators versions. if (m_dll == nullptr) return HRESULT_FROM_WIN32(GetLastError()); m_createFn = (DxcCreateInstanceProc)GetProcAddress(m_dll, fnName); @@ -81,7 +83,9 @@ class SpecificDllLoader : public DllLoader { return hr; } #else - m_dll = ::dlopen(dllName, RTLD_LAZY); // CodeQL [SM01925] This is by design, intended to be used to test multiple validators versions. + m_dll = ::dlopen( + dllName, RTLD_LAZY); // CodeQL [SM01925] This is by design, intended to + // be used to test multiple validators versions. if (m_dll == nullptr) return E_FAIL; m_createFn = (DxcCreateInstanceProc)::dlsym(m_dll, fnName); diff --git a/unittests/Support/ProgramTest.cpp b/unittests/Support/ProgramTest.cpp index 2f34808275..f7dcce8a4a 100644 --- a/unittests/Support/ProgramTest.cpp +++ b/unittests/Support/ProgramTest.cpp @@ -313,7 +313,8 @@ TEST(ProgramTest, TestWriteWithSystemEncoding) { #else char buf[10]; ASSERT_EQ(::read(fd, buf, 10), 10); - ASSERT_EQ(strncmp(buf, utf8_text, 10), 0); // CodeQL [SM01932] the file content is controlled by the test. + ASSERT_EQ(strncmp(buf, utf8_text, 10), + 0); // CodeQL [SM01932] the file content is controlled by the test. #endif ::close(fd); ASSERT_NO_ERROR(fs::remove(file_pathname.str())); From 7d4247eb39d3cac5df2b0335d2fe8b4f38716b34 Mon Sep 17 00:00:00 2001 From: Joao Saffran Date: Tue, 9 Dec 2025 13:27:57 -0800 Subject: [PATCH 9/9] remove redundant assert --- projects/dxilconv/lib/DxbcConverter/DxbcUtil.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/projects/dxilconv/lib/DxbcConverter/DxbcUtil.cpp b/projects/dxilconv/lib/DxbcConverter/DxbcUtil.cpp index 98172bcd05..92020ae991 100644 --- a/projects/dxilconv/lib/DxbcConverter/DxbcUtil.cpp +++ b/projects/dxilconv/lib/DxbcConverter/DxbcUtil.cpp @@ -47,7 +47,6 @@ CMask::CMask(BYTE StartComp, BYTE NumComp) { (StartComp + NumComp - 1) < DXBC::kAllCompMask, "otherwise the caller did not check"); m_Mask = 0; - DXASSERT((StartComp + NumComp) < 256, "sum should fit in a BYTE"); BYTE EndComp = StartComp + NumComp; for (BYTE c = StartComp; c < EndComp; c++) { m_Mask |= (1 << c);