apache / doris

Apache Doris is an easy-to-use, high performance and unified analytics database.
https://doris.apache.org
Apache License 2.0
12.77k stars 3.28k forks source link

[Enhancement] Add static check for implicit numric casts and fix potential precision loss under dir doris/be/src/olap #44400

Open TangSiyang2001 opened 15 hours ago

TangSiyang2001 commented 15 hours ago

Search before asking

Description

* For .h files Wrap the .h with "common/compile_check_begin.h" and "common/compile_check_end.h".

* For .cpp files Including "common/compile_check_begin.h" allows for internal compilation checks within the current cpp file. Note that it should be placed under a namespace to avoid formatting checks on other included .h files as well.

** Our goals Avoid some precision lost and cast them if sure to be safe.

** How to find problems

#!/bin/bash

# 指定要遍历的文件目录
DIR=$1

# 遍历 .h 和 .cpp 文件
find "$DIR" -type f \( -name "*.h" -o -name "*.cpp" \) | while read -r file; do
    # 检查是否已经包含 compile_check_begin.h
    if grep -q '#include "common/compile_check_begin.h"' "$file"; then
        echo "Skipping $file: already contains compile_check_begin.h."
        continue
    fi

    # 检查是否已经包含 compile_check_end.h
    if grep -q '#include "common/compile_check_end.h"' "$file"; then
        echo "Skipping $file: already contains compile_check_end.h."
        continue
    fi

    # 查找第一个 namespace 的行号
    namespace_line=$(grep -n '^namespace' "$file" | head -n 1 | cut -d: -f1)

    if [ -z "$namespace_line" ]; then
        echo "Skipping $file: no namespace found."
        continue
    fi

    # 在第一个 namespace 下插入 compile_check_begin.h
    sed -i "${namespace_line}a #include \"common/compile_check_begin.h\"" "$file"

    # 在文件最后一个 } 的上一行插入 compile_check_end.h
    last_brace_line=$(grep -n '^[[:space:]]*}' "$file" | tail -n 1 | cut -d: -f1)
    if [ -n "$last_brace_line" ]; then
        sed -i "${last_brace_line}i #include \"common/compile_check_end.h\"" "$file"
    else
        echo "Skipping $file: no closing brace found."
    fi

    echo "Processed $file."
done

Run the bash script above, then compile be, then problems wiill be printed out.

** Reference https://github.com/apache/doris/pull/44398 Everyone is free to pick several files and make contribution.

Solution

No response

Are you willing to submit PR?

Code of Conduct