Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 of 3 tasks
TangSiyang2001 opened this issue Nov 21, 2024 · 0 comments

Comments

@TangSiyang2001
Copy link
Collaborator

TangSiyang2001 commented Nov 21, 2024

Search before asking

  • I had searched in the issues and found no similar issues.

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
#44398
Everyone is free to pick several files and make contribution.

Solution

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

@TangSiyang2001 TangSiyang2001 changed the title [Enhancement] Add static check for implicit numric casts and fix potential precision loss [Enhancement] Add static check for implicit numric casts and fix potential precision loss under dir /be/src/olap Nov 21, 2024
@TangSiyang2001 TangSiyang2001 changed the title [Enhancement] Add static check for implicit numric casts and fix potential precision loss under dir /be/src/olap [Enhancement] Add static check for implicit numric casts and fix potential precision loss under dir doris/be/src/olap Nov 21, 2024
dataroaring pushed a commit that referenced this issue Nov 23, 2024
…/olap/ (#44398)

### What problem does this PR solve?

Issue Number: related #44400
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant