From 1fdb98c08954ef430f28d390b9925b6c819c2a27 Mon Sep 17 00:00:00 2001 From: zhangruifeng111 <14605462+zhang-ruifeng-1111@user.noreply.gitee.com> Date: Sat, 19 Jul 2025 10:47:22 +0800 Subject: [PATCH 1/2] feat: add ollama --- migration-agent/.gitignore | 2 +- migration-agent/setup_compiler_driver.sh | 22 +- migration-agent/src/global_config.py | 23 +- migration-agent/src/inference.py | 10 +- migration-agent/src/utilities/llms.py | 282 +++++++++++++++++- .../assembly_errors/test1/compiler_options | 1 + .../assembly_errors/test1/makefile | 25 ++ .../test1/path to the source file | 1 + .../assembly_errors/test1/reasoning | 1 + .../assembly_errors/test1/test.cpp | 22 ++ .../assembly_errors/test2/makefile | 25 ++ .../assembly_errors/test2/test.cpp | 8 + .../compiler_options/test1/makefile | 37 +++ .../compiler_options/test1/test.cpp | 8 + .../test_examples/link_errors/test1/makefile | 25 ++ .../test_examples/link_errors/test1/reasoning | 1 + .../test_examples/link_errors/test1/test.c | 6 + .../llvm_related_errors/test1/makefile | 25 ++ .../llvm_related_errors/test1/test.cpp | 12 + .../llvm_related_errors/test2/makefile | 25 ++ .../llvm_related_errors/test2/test.cpp | 18 ++ .../llvm_related_errors/test3/makefile | 25 ++ .../llvm_related_errors/test3/test.cpp | 7 + .../llvm_related_errors/test4/makefile | 25 ++ .../llvm_related_errors/test4/test.cpp | 13 + .../llvm_related_errors/test5/makefile | 25 ++ .../llvm_related_errors/test5/test.cpp | 29 ++ .../llvm_related_errors/test6/makefile | 25 ++ .../llvm_related_errors/test6/test.cpp | 20 ++ .../llvm_related_errors/test7/makefile | 25 ++ .../llvm_related_errors/test7/test.cpp | 6 + .../llvm_related_errors/test8/makefile | 24 ++ .../llvm_related_errors/test8/test.cpp | 14 + .../llvm_related_errors/test9/makefile | 25 ++ .../llvm_related_errors/test9/test.cpp | 4 + .../source_code_errors/test1/makefile | 25 ++ .../source_code_errors/test1/test.cpp | 23 ++ .../source_code_errors/test1/test.h | 8 + .../source_code_errors/test10/makefile | 35 +++ .../source_code_errors/test10/test.cpp | 3 + .../source_code_errors/test11/makefile | 37 +++ .../source_code_errors/test11/test.cpp | 18 ++ .../source_code_errors/test12/makefile | 35 +++ .../source_code_errors/test12/test.cpp | 11 + .../source_code_errors/test13/makefile | 35 +++ .../source_code_errors/test13/test.cpp | 3 + .../source_code_errors/test14/main.cpp | 6 + .../source_code_errors/test14/makefile | 25 ++ .../source_code_errors/test14/wrapper.cpp | 5 + .../source_code_errors/test14/wrapper.h | 12 + .../source_code_errors/test15/makefile | 25 ++ .../source_code_errors/test15/test.cpp | 15 + .../source_code_errors/test16/func.cpp | 6 + .../source_code_errors/test16/main.cpp | 10 + .../source_code_errors/test16/makefile | 25 ++ .../source_code_errors/test16/pi.cpp | 5 + .../source_code_errors/test16/pi.h | 8 + .../source_code_errors/test17/makefile | 25 ++ .../source_code_errors/test17/test.c | 5 + .../source_code_errors/test18/makefile | 25 ++ .../source_code_errors/test18/test.cpp | 19 ++ .../source_code_errors/test19/makefile | 25 ++ .../source_code_errors/test19/test.cpp | 17 ++ .../source_code_errors/test2/makefile | 35 +++ .../source_code_errors/test2/test.cpp | 12 + .../source_code_errors/test20/makefile | 25 ++ .../source_code_errors/test20/test.cpp | 3 + .../source_code_errors/test21/makefile | 25 ++ .../source_code_errors/test21/test.cpp | 4 + .../source_code_errors/test23/makefile | 25 ++ .../source_code_errors/test23/test.cpp | 2 + .../source_code_errors/test24/makefile | 25 ++ .../source_code_errors/test24/test.cpp | 11 + .../source_code_errors/test3/makefile | 35 +++ .../source_code_errors/test3/test.cpp | 12 + .../source_code_errors/test4/makefile | 25 ++ .../source_code_errors/test4/test.cpp | 32 ++ .../source_code_errors/test5/makefile | 37 +++ .../source_code_errors/test5/test.c | 1 + .../source_code_errors/test6/makefile | 35 +++ .../source_code_errors/test6/test.cpp | 18 ++ .../source_code_errors/test7/makefile | 37 +++ .../source_code_errors/test7/test.cpp | 6 + .../source_code_errors/test8/makefile | 37 +++ .../source_code_errors/test8/test.cpp | 18 ++ .../source_code_errors/test9/makefile | 37 +++ .../source_code_errors/test9/test.cpp | 4 + .../test_examples/type_errors/test1/makefile | 25 ++ .../test_examples/type_errors/test1/test.c | 7 + .../test_examples/type_errors/test2/makefile | 25 ++ .../test_examples/type_errors/test2/test.cpp | 18 ++ .../test_examples/type_errors/test3/makefile | 25 ++ .../test_examples/type_errors/test3/test.cpp | 4 + 93 files changed, 1916 insertions(+), 26 deletions(-) create mode 100644 migration-agent/test_examples/assembly_errors/test1/compiler_options create mode 100644 migration-agent/test_examples/assembly_errors/test1/makefile create mode 100644 migration-agent/test_examples/assembly_errors/test1/path to the source file create mode 100644 migration-agent/test_examples/assembly_errors/test1/reasoning create mode 100644 migration-agent/test_examples/assembly_errors/test1/test.cpp create mode 100644 migration-agent/test_examples/assembly_errors/test2/makefile create mode 100644 migration-agent/test_examples/assembly_errors/test2/test.cpp create mode 100644 migration-agent/test_examples/compiler_options/test1/makefile create mode 100644 migration-agent/test_examples/compiler_options/test1/test.cpp create mode 100644 migration-agent/test_examples/link_errors/test1/makefile create mode 100644 migration-agent/test_examples/link_errors/test1/reasoning create mode 100644 migration-agent/test_examples/link_errors/test1/test.c create mode 100644 migration-agent/test_examples/llvm_related_errors/test1/makefile create mode 100644 migration-agent/test_examples/llvm_related_errors/test1/test.cpp create mode 100644 migration-agent/test_examples/llvm_related_errors/test2/makefile create mode 100644 migration-agent/test_examples/llvm_related_errors/test2/test.cpp create mode 100644 migration-agent/test_examples/llvm_related_errors/test3/makefile create mode 100644 migration-agent/test_examples/llvm_related_errors/test3/test.cpp create mode 100644 migration-agent/test_examples/llvm_related_errors/test4/makefile create mode 100644 migration-agent/test_examples/llvm_related_errors/test4/test.cpp create mode 100644 migration-agent/test_examples/llvm_related_errors/test5/makefile create mode 100644 migration-agent/test_examples/llvm_related_errors/test5/test.cpp create mode 100644 migration-agent/test_examples/llvm_related_errors/test6/makefile create mode 100644 migration-agent/test_examples/llvm_related_errors/test6/test.cpp create mode 100644 migration-agent/test_examples/llvm_related_errors/test7/makefile create mode 100644 migration-agent/test_examples/llvm_related_errors/test7/test.cpp create mode 100644 migration-agent/test_examples/llvm_related_errors/test8/makefile create mode 100644 migration-agent/test_examples/llvm_related_errors/test8/test.cpp create mode 100644 migration-agent/test_examples/llvm_related_errors/test9/makefile create mode 100644 migration-agent/test_examples/llvm_related_errors/test9/test.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test1/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test1/test.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test1/test.h create mode 100644 migration-agent/test_examples/source_code_errors/test10/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test10/test.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test11/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test11/test.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test12/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test12/test.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test13/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test13/test.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test14/main.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test14/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test14/wrapper.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test14/wrapper.h create mode 100644 migration-agent/test_examples/source_code_errors/test15/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test15/test.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test16/func.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test16/main.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test16/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test16/pi.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test16/pi.h create mode 100644 migration-agent/test_examples/source_code_errors/test17/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test17/test.c create mode 100644 migration-agent/test_examples/source_code_errors/test18/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test18/test.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test19/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test19/test.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test2/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test2/test.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test20/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test20/test.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test21/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test21/test.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test23/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test23/test.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test24/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test24/test.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test3/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test3/test.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test4/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test4/test.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test5/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test5/test.c create mode 100644 migration-agent/test_examples/source_code_errors/test6/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test6/test.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test7/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test7/test.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test8/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test8/test.cpp create mode 100644 migration-agent/test_examples/source_code_errors/test9/makefile create mode 100644 migration-agent/test_examples/source_code_errors/test9/test.cpp create mode 100644 migration-agent/test_examples/type_errors/test1/makefile create mode 100644 migration-agent/test_examples/type_errors/test1/test.c create mode 100644 migration-agent/test_examples/type_errors/test2/makefile create mode 100644 migration-agent/test_examples/type_errors/test2/test.cpp create mode 100644 migration-agent/test_examples/type_errors/test3/makefile create mode 100644 migration-agent/test_examples/type_errors/test3/test.cpp diff --git a/migration-agent/.gitignore b/migration-agent/.gitignore index 10b8bdb4e545..2754094b74bd 100644 --- a/migration-agent/.gitignore +++ b/migration-agent/.gitignore @@ -12,6 +12,6 @@ tmp*/ build/ dist/ bishengai.spec - +migration-agent/test_examples/ diff --git a/migration-agent/setup_compiler_driver.sh b/migration-agent/setup_compiler_driver.sh index 07c9469ee343..a4f3fea06217 100644 --- a/migration-agent/setup_compiler_driver.sh +++ b/migration-agent/setup_compiler_driver.sh @@ -2,7 +2,7 @@ pip install pyinstaller rm -rf build/ rm -rf dist/ -rm bishengai.spec +rm -f bishengai.spec TARGET="bishengai" SOURCE="src/compiler_driver.py" pyinstaller --onefile $SOURCE --name $TARGET @@ -12,10 +12,18 @@ export LLM_DEVELOPMENT=1 # export COMPILER_CHOICE="clang++" # "clang" for c; "clang++"" for c++ export LLM_DEBUG=1 export AUTO_ACCEPT=1 # not export-interactive window; export-automatically change -export LLM_API_TOKEN= # add your api token here -~ -~ -~ -~ -~ + +# 1:流式 0:非流式 +export ENABLE_STREAM=0 + +# openai +# export LLM_MODEL_TYPE=openai +# export LLM_API_TOKEN=sk-pdpqvfeudracdnsglcycewfqdusergvbbzclcznphpjqdmxs +# export LLM_MODEL=deepseek-ai/DeepSeek-R1-Distill-Qwen-32B +# export LLM_URL=https://api.siliconflow.cn/v1/chat/completions + +# 本地ollama +export LLM_MODEL_TYPE=local_ollama +export LLM_URL=http://localhost:11434/api/generate +export LLM_MODEL=deepseek-r1:1.5b diff --git a/migration-agent/src/global_config.py b/migration-agent/src/global_config.py index 53e029b5f274..98bf05e5cbca 100644 --- a/migration-agent/src/global_config.py +++ b/migration-agent/src/global_config.py @@ -3,12 +3,17 @@ This defines the global configurations for the compiler driver """ import logging +from enum import Enum import os from termcolor import colored # Global Constants LOG_FILE = "llm4compiler.log" -llm_url = "https://api.siliconflow.cn/v1/chat/completions" + +class ModelType(str, Enum): + LOCAL_OLLAMA = "local_ollama" # 本地Ollama部署 + OPENAI = "openai" # OpenAI API + LLAMA_CPP_CPU = "llama_cpp_cpu" # llama.cpp CPU部署 # Function to get the api token for siliconflow @@ -17,6 +22,22 @@ def get_llm_api_token() -> str: return os.getenv("LLM_API_TOKEN", "") llm_api_token = get_llm_api_token() +def get_model_type() -> ModelType: + """Return the LLM model type""" + return ModelType(os.getenv("LLM_MODEL_TYPE", ModelType.OPENAI)) + +def get_enable_stream() -> bool: + value = os.getenv("ENABLE_STREAM", "0") + mapping = { + "1": True, + "0": False + } + return mapping.get(value, False) + +def get_llm_url() -> str: + """Return the LLM url""" + return os.getenv("LLM_URL", "") + # Function to check if automatic acceptance of LLM code changes is enabled def is_auto_accept_code_change() -> bool: diff --git a/migration-agent/src/inference.py b/migration-agent/src/inference.py index 5ddef41c8f1e..19f5ff89649f 100644 --- a/migration-agent/src/inference.py +++ b/migration-agent/src/inference.py @@ -179,12 +179,12 @@ class LLMRepair: # logging.debug(f"prompt={prompt}") response = self.llm.inference(prompt) + logging.debug(f"response={response}") + if response: - data = json.loads(response.text) - message_content = data.get("choices")[0].get("message").get("content") - reasoning_content = ( - data.get("choices")[0].get("message").get("reasoning_content") - ) + # 直接从 response 字典中获取 content 和 reasoning_content + message_content = response.get("content", "") + reasoning_content = response.get("reasoning_content", "") self.llm.set_model_id(prev_model) return self.process_response(message_content, reasoning_content) diff --git a/migration-agent/src/utilities/llms.py b/migration-agent/src/utilities/llms.py index 0f512e26e448..82faf6935a32 100644 --- a/migration-agent/src/utilities/llms.py +++ b/migration-agent/src/utilities/llms.py @@ -1,5 +1,6 @@ """ This defines LLM related utility functions """ +import json import requests import logging from global_config import * @@ -32,6 +33,16 @@ class LLM: self.model_id = model_id def inference(self, prompt): + model_type = get_model_type() + if model_type == ModelType.OPENAI: + return self.openapi_inference(prompt) + elif model_type == ModelType.LOCAL_OLLAMA: + return self.local_ollama_inference(prompt) + else: + logging.error(f"Unsupported model type: {model_type}") + return {"content": "", "reasoning_content": ""} + + def openapi_inference(self, prompt): payload = { "model": self.model_id, "messages": [ @@ -41,17 +52,264 @@ class LLM: } ], "temperature": 0.3, + "stream": get_enable_stream(), } - response = requests.request( - "POST", - llm_url, - json=payload, - headers=self.headers, - verify=False, - ) - # Successfully getting the inference response - if response.status_code == 200: - return response - else: - return None + try: + response = requests.post( + get_llm_url(), + json=payload, + headers=self.headers, + verify=False, + stream=get_enable_stream() + ) + response.raise_for_status() + + if get_enable_stream(): + content, reasoning_content = self._process_openai_stream(response) + else: + content, reasoning_content = self._process_openai_non_stream(response) + return {"content": content, "reasoning_content": reasoning_content} + except requests.exceptions.RequestException as e: + logging.error(f"OpenAI request failed: {e}") + return {"content": "", "reasoning_content": ""} + + def _process_openai_stream(self, response): + full_content = "" + reasoning_content = "" + + for line in response.iter_lines(): + if not line: + continue + + # 解码并清理响应行,移除 'data: ' 前缀 + decoded_line = line.decode('utf-8').replace("data: ", "") + + # 判断是否为流式响应的结束标记 + if decoded_line == "[DONE]": + break + + try: + data = json.loads(decoded_line) + content_part = "" + reasoning_part = "" + # 从 JSON 数据中提取 content 和 reasoning_content + if 'choices' in data and data['choices']: + delta = data['choices'][0].get('delta', {}) + content_part = delta.get('content', '') + if content_part is None: + content_part = "" + reasoning_part = delta.get('reasoning_content') + if reasoning_part is None: + reasoning_part = "" + full_content += content_part + reasoning_content += reasoning_part + except json.JSONDecodeError: + logging.debug("Failed to decode JSON line in stream response") + continue + + return full_content, reasoning_content + + def _process_openai_non_stream(self, response): + content = "" + reasoning_content = "" + try: + data = response.json() + if 'choices' in data and data['choices']: + content = data['choices'][0]['message']['content'] + reasoning_content = data['choices'][0]['message'].get('reasoning_content', '') + except (KeyError, IndexError, ValueError): + logging.error("Failed to parse OpenAI response JSON") + return content, reasoning_content + + def local_ollama_inference(self, prompt): + payload = { + "model": self.model_id, + "prompt": prompt, + "options": { + "temperature": 0.3 + }, + "stream": get_enable_stream() + } + + try: + response = requests.post( + get_llm_url(), + json=payload, + headers=self.headers, + verify=False, + stream=get_enable_stream(), + timeout=30 + ) + response.raise_for_status() + + if get_enable_stream(): + content, reasoning_content = self._process_ollama_stream(response) + else: + content, reasoning_content = self._process_ollama_non_stream(response) + return {"content": content, "reasoning_content": reasoning_content} + except requests.exceptions.RequestException as e: + logging.error(f"Ollama request failed: {e}") + return {"content": "", "reasoning_content": ""} + + def _process_ollama_stream(self, response): + full_content = "" + reasoning_content = "" + for line in response.iter_lines(): + if line: + try: + line_decoded = line.decode('utf-8') + data = json.loads(line_decoded) + response_text = data.get('response', '') + if response_text is None: + response_text = "" + full_content += response_text + reasoning_delta = data.get('reasoning_content', '') + if reasoning_delta is None: + reasoning_delta = "" + reasoning_content += reasoning_delta + + if data.get('done'): + break + except json.JSONDecodeError as e: + logging.debug(f"Failed to decode JSON: {e}") + continue + + # 处理完整内容,移除 ... 部分 + import re + think_pattern = re.compile(r'.*?', re.DOTALL) + full_content = think_pattern.sub('', full_content).strip() + + # 记录清理后的内容供调试 + logging.debug(f"Processed content: {full_content[:200]}...") + + return full_content, reasoning_content + + def _process_ollama_non_stream(self, response): + content = "" + reasoning_content = "" + try: + # 检查 response 是否已经是字典 + if isinstance(response, dict): + data = response + else: + data = response.json() + + # 获取响应内容 + content = data.get('response', '') or data.get('content', '') + + # 移除 ... 部分 + import re + think_pattern = re.compile(r'.*?', re.DOTALL) + content = think_pattern.sub('', content).strip() + + # 获取推理内容 + reasoning_content = data.get('reasoning_content', '') + except Exception as e: + logging.error(f"Failed to parse Ollama response JSON: {str(e)}") + return content, reasoning_content + + +# """ This defines LLM related utility functions """ + +# import requests +# import logging +# from global_config import * + +# # Suppress all warnings for cleaner output +# import warnings + +# warnings.filterwarnings("ignore") + + +# class LLM: +# def __init__(self, local_mode=False, ollama_url="http://localhost:11434"): +# """Initialize LLM instance with the model ID and API headers.""" +# self.local_mode = local_mode +# self.ollama_url = ollama_url +# if not local_mode: +# self.headers = { +# "Authorization": self.get_api_token(), +# "Content-Type": "application/json", +# } +# else: +# self.headers = { +# "Content-Type": "application/json", +# } +# self.model_id = get_model_id() + +# def get_api_token(self) -> str: +# """Return the API token required for authorization.""" +# return f"Bearer {llm_api_token}" + +# def get_model_id(self): +# """Return the current LLM model ID.""" +# return self.model_id + +# def set_model_id(self, model_id: str): +# """Set the model ID for the LLM.""" +# self.model_id = model_id + +# def inference(self, prompt): +# if self.local_mode: +# return self._ollama_inference(prompt) +# else: +# return self._cloud_inference(prompt) + +# def _cloud_inference(self, prompt): +# payload = { +# "model": self.model_id, +# "messages": [ +# { +# "role": "user", +# "content": prompt, +# } +# ], +# "temperature": 0.3, +# } + +# response = requests.request( +# "POST", +# llm_url, +# json=payload, +# headers=self.headers, +# verify=False, +# ) +# # Successfully getting the inference response +# if response.status_code == 200: +# return response +# else: +# return None + +# def _ollama_inference(self, prompt): +# """Use Ollama local service for inference""" +# payload = { +# "model": self.model_id, +# "prompt": prompt, +# "options": { +# "temperature": 0.3 +# } +# } + +# try: +# # 添加调试日志 +# logging.debug(f"Sending request to Ollama at {self.ollama_url}") +# logging.debug(f"Payload: {payload}") + +# response = requests.post( +# f"{self.ollama_url}/api/generate", +# json=payload, +# headers=self.headers, +# verify=False, +# timeout=30 # 添加超时 +# ) + +# # 添加响应日志 +# logging.debug(f"Ollama response status: {response.status_code}") +# if response.status_code == 200: +# logging.debug(f"Response content: {response.text[:200]}...") # 截取部分内容 +# return response.json() +# return None +# except requests.exceptions.RequestException as e: +# logging.error(f"Ollama request failed: {e}") +# return None diff --git a/migration-agent/test_examples/assembly_errors/test1/compiler_options b/migration-agent/test_examples/assembly_errors/test1/compiler_options new file mode 100644 index 000000000000..3af2ac082212 --- /dev/null +++ b/migration-agent/test_examples/assembly_errors/test1/compiler_options @@ -0,0 +1 @@ +-V \ No newline at end of file diff --git a/migration-agent/test_examples/assembly_errors/test1/makefile b/migration-agent/test_examples/assembly_errors/test1/makefile new file mode 100644 index 000000000000..72ba0795f1a8 --- /dev/null +++ b/migration-agent/test_examples/assembly_errors/test1/makefile @@ -0,0 +1,25 @@ +# Compiler + +ifndef CXX + CXX = clang++ +endif + + +# Compiler flags +CXXFLAGS = -Wall -std=c++11 + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: + $(CXX) $(CXXFLAGS) -c $(SRC) -o $(OBJ) + +# Clean up object and executable files +clean: + rm -f $(OBJ) *.log + +.PHONY: all clean diff --git a/migration-agent/test_examples/assembly_errors/test1/path to the source file b/migration-agent/test_examples/assembly_errors/test1/path to the source file new file mode 100644 index 000000000000..64554df78823 --- /dev/null +++ b/migration-agent/test_examples/assembly_errors/test1/path to the source file @@ -0,0 +1 @@ +test.cpp \ No newline at end of file diff --git a/migration-agent/test_examples/assembly_errors/test1/reasoning b/migration-agent/test_examples/assembly_errors/test1/reasoning new file mode 100644 index 000000000000..4fce30572ac5 --- /dev/null +++ b/migration-agent/test_examples/assembly_errors/test1/reasoning @@ -0,0 +1 @@ +The vector load instruction uses an invalid source operand 'Utv'. Replacing it with 'ldr d0, %1' fixes the error. \ No newline at end of file diff --git a/migration-agent/test_examples/assembly_errors/test1/test.cpp b/migration-agent/test_examples/assembly_errors/test1/test.cpp new file mode 100644 index 000000000000..21eb8d2b5574 --- /dev/null +++ b/migration-agent/test_examples/assembly_errors/test1/test.cpp @@ -0,0 +1,22 @@ +typedef unsigned long long __attribute__((aligned((8)))) u64a; +typedef signed char __int8_t; +typedef __int8_t int8_t; +typedef __attribute__((neon_vector_type(16))) int8_t int8x16_t; + +typedef union { + int8x16_t vect_s8; + +} __m128i; + +typedef __m128i m128; + + +static inline __attribute__ ((always_inline, unused)) m128 load_m128_from_u64a(const u64a *p) { + m128 result; + __asm__ __volatile__("ldr %d0, %1 \n\t" + : "=w"(result) + : "Utv"(*p) + : + ); + return result; +} diff --git a/migration-agent/test_examples/assembly_errors/test2/makefile b/migration-agent/test_examples/assembly_errors/test2/makefile new file mode 100644 index 000000000000..72ba0795f1a8 --- /dev/null +++ b/migration-agent/test_examples/assembly_errors/test2/makefile @@ -0,0 +1,25 @@ +# Compiler + +ifndef CXX + CXX = clang++ +endif + + +# Compiler flags +CXXFLAGS = -Wall -std=c++11 + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: + $(CXX) $(CXXFLAGS) -c $(SRC) -o $(OBJ) + +# Clean up object and executable files +clean: + rm -f $(OBJ) *.log + +.PHONY: all clean diff --git a/migration-agent/test_examples/assembly_errors/test2/test.cpp b/migration-agent/test_examples/assembly_errors/test2/test.cpp new file mode 100644 index 000000000000..36e686dea27f --- /dev/null +++ b/migration-agent/test_examples/assembly_errors/test2/test.cpp @@ -0,0 +1,8 @@ +void f(int x) +{ + __asm__ ( "123456" : : "r" (x)); +} +void g (void) +{ + __asm__ ("simple asm not discarded 123456"); +} \ No newline at end of file diff --git a/migration-agent/test_examples/compiler_options/test1/makefile b/migration-agent/test_examples/compiler_options/test1/makefile new file mode 100644 index 000000000000..27edfc2c0a51 --- /dev/null +++ b/migration-agent/test_examples/compiler_options/test1/makefile @@ -0,0 +1,37 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags +CXXFLAGS = -Wall -fanalyzer -std=c++11 + +# Output executable name +TARGET = test + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: $(TARGET) +# all: +# $(CXX) $(CXXFLAGS) -c $(SRC) -o $(OBJ) + +# Rule to create the executable +$(TARGET): $(OBJ) + $(CXX) $(OBJ) -o $(TARGET) + +# Rule to compile .cpp files into .o files +%.o: %.cpp + $(CXX) $(CXXFLAGS) -c $< -o $@ + +# Clean up object and executable files +clean: + rm -f $(OBJ) $(TARGET) + +.PHONY: all clean diff --git a/migration-agent/test_examples/compiler_options/test1/test.cpp b/migration-agent/test_examples/compiler_options/test1/test.cpp new file mode 100644 index 000000000000..e575ad17d78d --- /dev/null +++ b/migration-agent/test_examples/compiler_options/test1/test.cpp @@ -0,0 +1,8 @@ +#include + +using namespace std; + +int main() { + cout << "Hello World\n" << endl; + return 0; +} diff --git a/migration-agent/test_examples/link_errors/test1/makefile b/migration-agent/test_examples/link_errors/test1/makefile new file mode 100644 index 000000000000..83eea5e3b94e --- /dev/null +++ b/migration-agent/test_examples/link_errors/test1/makefile @@ -0,0 +1,25 @@ +# Compiler + +ifeq ($(CC),) + CC = clang +endif + + +# Compiler flags, -nostdinc -iwithprefix include差异 +CFLAGS = -nostdinc -iwithprefix include -Wall + +# Source files +SRC = test.c + +# Object files +OBJ = $(SRC:.c=.o) + +# Default rule +all: + $(CC) $(CFLAGS) -c $(SRC) -o $(OBJ) + +# Clean up object and executable files +clean: + rm -f $(OBJ) *.log + +.PHONY: all clean diff --git a/migration-agent/test_examples/link_errors/test1/reasoning b/migration-agent/test_examples/link_errors/test1/reasoning new file mode 100644 index 000000000000..4dcda2c50bac --- /dev/null +++ b/migration-agent/test_examples/link_errors/test1/reasoning @@ -0,0 +1 @@ +The source file test.c needs to include both and for the compiler to find the required headers. \ No newline at end of file diff --git a/migration-agent/test_examples/link_errors/test1/test.c b/migration-agent/test_examples/link_errors/test1/test.c new file mode 100644 index 000000000000..5e16703d2fa1 --- /dev/null +++ b/migration-agent/test_examples/link_errors/test1/test.c @@ -0,0 +1,6 @@ +#include + +int main() +{ + return 0; +} \ No newline at end of file diff --git a/migration-agent/test_examples/llvm_related_errors/test1/makefile b/migration-agent/test_examples/llvm_related_errors/test1/makefile new file mode 100644 index 000000000000..dce36e93d859 --- /dev/null +++ b/migration-agent/test_examples/llvm_related_errors/test1/makefile @@ -0,0 +1,25 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags, Wnonnull告警差异 +CXXFLAGS = -Wall -std=c++11 + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: + $(CXX) $(CXXFLAGS) -c $(SRC) -o $(OBJ) + +# Clean up object and executable files +clean: + rm -f $(OBJ) *.log + +.PHONY: all clean diff --git a/migration-agent/test_examples/llvm_related_errors/test1/test.cpp b/migration-agent/test_examples/llvm_related_errors/test1/test.cpp new file mode 100644 index 000000000000..7b2eae410f4f --- /dev/null +++ b/migration-agent/test_examples/llvm_related_errors/test1/test.cpp @@ -0,0 +1,12 @@ +template +class C +{ +public: + void mf1() const {} + void mf2() const {} + +private: + T t; +}; +template void C::mf1() const; +template class C; \ No newline at end of file diff --git a/migration-agent/test_examples/llvm_related_errors/test2/makefile b/migration-agent/test_examples/llvm_related_errors/test2/makefile new file mode 100644 index 000000000000..4b09ca26eb43 --- /dev/null +++ b/migration-agent/test_examples/llvm_related_errors/test2/makefile @@ -0,0 +1,25 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags +CXXFLAGS = -Wall -std=c++11 + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: + $(CXX) $(CXXFLAGS) -c $(SRC) -o $(OBJ) + +# Clean up object and executable files +clean: + rm -f $(OBJ) *.log + +.PHONY: all clean diff --git a/migration-agent/test_examples/llvm_related_errors/test2/test.cpp b/migration-agent/test_examples/llvm_related_errors/test2/test.cpp new file mode 100644 index 000000000000..47f7d7c7bc46 --- /dev/null +++ b/migration-agent/test_examples/llvm_related_errors/test2/test.cpp @@ -0,0 +1,18 @@ +#include + +class A { +public: + virtual ~A() {std::cout << "executed ~A()\n";} +}; + +class B : public A { +public: + virtual ~B() {std::cout << "executed ~B()\n";} +}; + +int main() { + std::cout << "starting\n"; + B b; + b.~A(); //子类直接调用父类析构函数 + std::cout << "done\n"; +} diff --git a/migration-agent/test_examples/llvm_related_errors/test3/makefile b/migration-agent/test_examples/llvm_related_errors/test3/makefile new file mode 100644 index 000000000000..4b09ca26eb43 --- /dev/null +++ b/migration-agent/test_examples/llvm_related_errors/test3/makefile @@ -0,0 +1,25 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags +CXXFLAGS = -Wall -std=c++11 + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: + $(CXX) $(CXXFLAGS) -c $(SRC) -o $(OBJ) + +# Clean up object and executable files +clean: + rm -f $(OBJ) *.log + +.PHONY: all clean diff --git a/migration-agent/test_examples/llvm_related_errors/test3/test.cpp b/migration-agent/test_examples/llvm_related_errors/test3/test.cpp new file mode 100644 index 000000000000..25a0bd71951d --- /dev/null +++ b/migration-agent/test_examples/llvm_related_errors/test3/test.cpp @@ -0,0 +1,7 @@ +struct A +{ + template A(T) = delete; +}; +template<> A::A(int) {} // error +//template<> A::A(int) {} // no error +//A a(0); diff --git a/migration-agent/test_examples/llvm_related_errors/test4/makefile b/migration-agent/test_examples/llvm_related_errors/test4/makefile new file mode 100644 index 000000000000..dce36e93d859 --- /dev/null +++ b/migration-agent/test_examples/llvm_related_errors/test4/makefile @@ -0,0 +1,25 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags, Wnonnull告警差异 +CXXFLAGS = -Wall -std=c++11 + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: + $(CXX) $(CXXFLAGS) -c $(SRC) -o $(OBJ) + +# Clean up object and executable files +clean: + rm -f $(OBJ) *.log + +.PHONY: all clean diff --git a/migration-agent/test_examples/llvm_related_errors/test4/test.cpp b/migration-agent/test_examples/llvm_related_errors/test4/test.cpp new file mode 100644 index 000000000000..6499b195ae46 --- /dev/null +++ b/migration-agent/test_examples/llvm_related_errors/test4/test.cpp @@ -0,0 +1,13 @@ +#ifndef __PRAGMA_REDEFINE_EXTNAME +#error +#endif +namespace somewhere { + extern "C" int whiz(void); + int whiz(int); +} +#pragma redefine_extname whiz bang +int (*s)() = somewhere::whiz; +namespace elsewhere { + extern "C" int whiz(void); +} +int (*t)() = elsewhere::whiz; diff --git a/migration-agent/test_examples/llvm_related_errors/test5/makefile b/migration-agent/test_examples/llvm_related_errors/test5/makefile new file mode 100644 index 000000000000..dce36e93d859 --- /dev/null +++ b/migration-agent/test_examples/llvm_related_errors/test5/makefile @@ -0,0 +1,25 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags, Wnonnull告警差异 +CXXFLAGS = -Wall -std=c++11 + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: + $(CXX) $(CXXFLAGS) -c $(SRC) -o $(OBJ) + +# Clean up object and executable files +clean: + rm -f $(OBJ) *.log + +.PHONY: all clean diff --git a/migration-agent/test_examples/llvm_related_errors/test5/test.cpp b/migration-agent/test_examples/llvm_related_errors/test5/test.cpp new file mode 100644 index 000000000000..807072ed30fb --- /dev/null +++ b/migration-agent/test_examples/llvm_related_errors/test5/test.cpp @@ -0,0 +1,29 @@ +#include +#include +int test, failed; +int main (void); +void +eh1 (void *p, int x) +{ + printf("eh1\n"); + void *q = __builtin_alloca (x); + __builtin_eh_return (0, p); +} +void fail (void) +{ + printf ("failed\n"); + abort (); +} +void continuation (void) +{ + printf ("continuation\n"); + test++; + main(); +} +int main (void) +{ + printf("main\n"); + if(test==0) eh1 (continuation, 100); + printf("exit\n"); + exit (0); +} diff --git a/migration-agent/test_examples/llvm_related_errors/test6/makefile b/migration-agent/test_examples/llvm_related_errors/test6/makefile new file mode 100644 index 000000000000..dce36e93d859 --- /dev/null +++ b/migration-agent/test_examples/llvm_related_errors/test6/makefile @@ -0,0 +1,25 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags, Wnonnull告警差异 +CXXFLAGS = -Wall -std=c++11 + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: + $(CXX) $(CXXFLAGS) -c $(SRC) -o $(OBJ) + +# Clean up object and executable files +clean: + rm -f $(OBJ) *.log + +.PHONY: all clean diff --git a/migration-agent/test_examples/llvm_related_errors/test6/test.cpp b/migration-agent/test_examples/llvm_related_errors/test6/test.cpp new file mode 100644 index 000000000000..8c41d6f5cebd --- /dev/null +++ b/migration-agent/test_examples/llvm_related_errors/test6/test.cpp @@ -0,0 +1,20 @@ +#include +#include + +struct NonPod { + NonPod() {} + ~NonPod() {} +}; + +void sum(int count, ...) { + va_list args; + va_start(args, count); + for (int i = 0; i < count; ++i) { + NonPod obj = va_arg(args, NonPod); + } + va_end(args); +} + +int main() { + sum(2, 1, 2); +} diff --git a/migration-agent/test_examples/llvm_related_errors/test7/makefile b/migration-agent/test_examples/llvm_related_errors/test7/makefile new file mode 100644 index 000000000000..dce36e93d859 --- /dev/null +++ b/migration-agent/test_examples/llvm_related_errors/test7/makefile @@ -0,0 +1,25 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags, Wnonnull告警差异 +CXXFLAGS = -Wall -std=c++11 + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: + $(CXX) $(CXXFLAGS) -c $(SRC) -o $(OBJ) + +# Clean up object and executable files +clean: + rm -f $(OBJ) *.log + +.PHONY: all clean diff --git a/migration-agent/test_examples/llvm_related_errors/test7/test.cpp b/migration-agent/test_examples/llvm_related_errors/test7/test.cpp new file mode 100644 index 000000000000..67e4d7ab73dc --- /dev/null +++ b/migration-agent/test_examples/llvm_related_errors/test7/test.cpp @@ -0,0 +1,6 @@ +int test(const char* a) { + if (a > 0) { + return 0; + } + return 1; +} diff --git a/migration-agent/test_examples/llvm_related_errors/test8/makefile b/migration-agent/test_examples/llvm_related_errors/test8/makefile new file mode 100644 index 000000000000..224c7edcc5ac --- /dev/null +++ b/migration-agent/test_examples/llvm_related_errors/test8/makefile @@ -0,0 +1,24 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +CXXFLAGS = -Wall -std=c++11 + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: + $(CXX) $(CXXFLAGS) -c $(SRC) -o $(OBJ) + +# Clean up object and executable files +clean: + rm -f $(OBJ) *.log + +.PHONY: all clean diff --git a/migration-agent/test_examples/llvm_related_errors/test8/test.cpp b/migration-agent/test_examples/llvm_related_errors/test8/test.cpp new file mode 100644 index 000000000000..71309dacc35f --- /dev/null +++ b/migration-agent/test_examples/llvm_related_errors/test8/test.cpp @@ -0,0 +1,14 @@ +class A { +public: + template void As(); + static A *FromWebContents(); + A *FromWebContents2(); +}; +template class B : A { + void FromWebContents() { + auto guest = A::FromWebContents(); + guest ? guest->As() : nullptr; + auto guest2 = A::FromWebContents2(); + guest2 ? guest2->As() : nullptr; + } +} diff --git a/migration-agent/test_examples/llvm_related_errors/test9/makefile b/migration-agent/test_examples/llvm_related_errors/test9/makefile new file mode 100644 index 000000000000..dce36e93d859 --- /dev/null +++ b/migration-agent/test_examples/llvm_related_errors/test9/makefile @@ -0,0 +1,25 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags, Wnonnull告警差异 +CXXFLAGS = -Wall -std=c++11 + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: + $(CXX) $(CXXFLAGS) -c $(SRC) -o $(OBJ) + +# Clean up object and executable files +clean: + rm -f $(OBJ) *.log + +.PHONY: all clean diff --git a/migration-agent/test_examples/llvm_related_errors/test9/test.cpp b/migration-agent/test_examples/llvm_related_errors/test9/test.cpp new file mode 100644 index 000000000000..65a7dfd6085f --- /dev/null +++ b/migration-agent/test_examples/llvm_related_errors/test9/test.cpp @@ -0,0 +1,4 @@ +void test(char *MemoryOrderIn, int strlen1) { + char *MemoryOrder; + memcpy(MemoryOrder,MemoryOrderIn,strlen1); +} diff --git a/migration-agent/test_examples/source_code_errors/test1/makefile b/migration-agent/test_examples/source_code_errors/test1/makefile new file mode 100644 index 000000000000..4b09ca26eb43 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test1/makefile @@ -0,0 +1,25 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags +CXXFLAGS = -Wall -std=c++11 + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: + $(CXX) $(CXXFLAGS) -c $(SRC) -o $(OBJ) + +# Clean up object and executable files +clean: + rm -f $(OBJ) *.log + +.PHONY: all clean diff --git a/migration-agent/test_examples/source_code_errors/test1/test.cpp b/migration-agent/test_examples/source_code_errors/test1/test.cpp new file mode 100644 index 000000000000..ff4fa32abf27 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test1/test.cpp @@ -0,0 +1,23 @@ +#include +#include +#include "test.h" + +opc_status SyncDBOpc::GetRightStatus(std::string str_status) +{ + opc_status status; + switch (stoi(str_status)) + { + case 0: + status = OPC_STATUS_OK; + break; + case 1: + status = OPC_STATUS_WARNING; + break; + case 2: + status = OPC_STATUS_ERROR; + break; + default: + status = OPC_STATUS_UNKNOWN; + break; + } +} diff --git a/migration-agent/test_examples/source_code_errors/test1/test.h b/migration-agent/test_examples/source_code_errors/test1/test.h new file mode 100644 index 000000000000..fe29f78a6c74 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test1/test.h @@ -0,0 +1,8 @@ +#ifndef TEST_H +#define TEST_H + +class SyncDBOpc{ +public: +opc_status SyncDBOpc::GetRightStatus(std::string str_status); +} +#endif diff --git a/migration-agent/test_examples/source_code_errors/test10/makefile b/migration-agent/test_examples/source_code_errors/test10/makefile new file mode 100644 index 000000000000..ecbaffc455a9 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test10/makefile @@ -0,0 +1,35 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags +CXXFLAGS = -Wall -std=c++11 + +# Output executable name +TARGET = test + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: $(TARGET) + +# Rule to create the executable +$(TARGET): $(OBJ) + $(CXX) $(OBJ) -o $(TARGET) + +# Rule to compile .cpp files into .o files +%.o: %.cpp + $(CXX) $(CXXFLAGS) -c $< -o $@ + +# Clean up object and executable files +clean: + rm -f $(OBJ) $(TARGET) + +.PHONY: all clean diff --git a/migration-agent/test_examples/source_code_errors/test10/test.cpp b/migration-agent/test_examples/source_code_errors/test10/test.cpp new file mode 100644 index 000000000000..93fca75802d1 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test10/test.cpp @@ -0,0 +1,3 @@ +void test() { + return 1; +} diff --git a/migration-agent/test_examples/source_code_errors/test11/makefile b/migration-agent/test_examples/source_code_errors/test11/makefile new file mode 100644 index 000000000000..b31d4dd0f3e9 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test11/makefile @@ -0,0 +1,37 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags +CXXFLAGS = -Wall -std=c++11 + +# Output executable name +TARGET = test + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +# all: $(TARGET) +all: + $(CC) $(CFLAGS) -c $(SRC) -o $(OBJ) + +# # Rule to create the executable +# $(TARGET): $(OBJ) +# $(CXX) $(OBJ) -o $(TARGET) + +# # Rule to compile .cpp files into .o files +# %.o: %.cpp +# $(CXX) $(CXXFLAGS) -c $< -o $@ + +# Clean up object and executable files +clean: + rm -f $(OBJ) $(TARGET) + +.PHONY: all clean diff --git a/migration-agent/test_examples/source_code_errors/test11/test.cpp b/migration-agent/test_examples/source_code_errors/test11/test.cpp new file mode 100644 index 000000000000..2fa2430125b6 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test11/test.cpp @@ -0,0 +1,18 @@ +#include +#include +template +class Base { +public: + void foo() { + std::cout << "Base::foo()\n"; + } +}; + +template +class Derived : public Base { + +public: + void bar() { + foo(); + } +}; diff --git a/migration-agent/test_examples/source_code_errors/test12/makefile b/migration-agent/test_examples/source_code_errors/test12/makefile new file mode 100644 index 000000000000..ecbaffc455a9 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test12/makefile @@ -0,0 +1,35 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags +CXXFLAGS = -Wall -std=c++11 + +# Output executable name +TARGET = test + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: $(TARGET) + +# Rule to create the executable +$(TARGET): $(OBJ) + $(CXX) $(OBJ) -o $(TARGET) + +# Rule to compile .cpp files into .o files +%.o: %.cpp + $(CXX) $(CXXFLAGS) -c $< -o $@ + +# Clean up object and executable files +clean: + rm -f $(OBJ) $(TARGET) + +.PHONY: all clean diff --git a/migration-agent/test_examples/source_code_errors/test12/test.cpp b/migration-agent/test_examples/source_code_errors/test12/test.cpp new file mode 100644 index 000000000000..edae46c6a818 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test12/test.cpp @@ -0,0 +1,11 @@ +// Order of invocation is undefined in this context according to the C++ standard. +// It's possible to leak a Foo or a Bar depending on the order of evaluation if one +// of the new statements throws an exception before their auto_ptrs can "own" it +accept_two_ptrs(std::auto_ptr(new Foo), std::auto_ptr(new Bar)); + +void MyClass::InvokeCallback(CallbackType cb) +{ + Foo* resource = new Foo; + cb(resource); // If cb throws an exception, resource leaks + delete resource; +} diff --git a/migration-agent/test_examples/source_code_errors/test13/makefile b/migration-agent/test_examples/source_code_errors/test13/makefile new file mode 100644 index 000000000000..ecbaffc455a9 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test13/makefile @@ -0,0 +1,35 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags +CXXFLAGS = -Wall -std=c++11 + +# Output executable name +TARGET = test + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: $(TARGET) + +# Rule to create the executable +$(TARGET): $(OBJ) + $(CXX) $(OBJ) -o $(TARGET) + +# Rule to compile .cpp files into .o files +%.o: %.cpp + $(CXX) $(CXXFLAGS) -c $< -o $@ + +# Clean up object and executable files +clean: + rm -f $(OBJ) $(TARGET) + +.PHONY: all clean diff --git a/migration-agent/test_examples/source_code_errors/test13/test.cpp b/migration-agent/test_examples/source_code_errors/test13/test.cpp new file mode 100644 index 000000000000..e9d3bfdfe631 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test13/test.cpp @@ -0,0 +1,3 @@ +while( !cin.eof() ) { + getline(cin, input); +} diff --git a/migration-agent/test_examples/source_code_errors/test14/main.cpp b/migration-agent/test_examples/source_code_errors/test14/main.cpp new file mode 100644 index 000000000000..3d662f1267fd --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test14/main.cpp @@ -0,0 +1,6 @@ +#include "wrapper.h" +int main() { + Wrapper x(10); + x.print(); + return 0; +} diff --git a/migration-agent/test_examples/source_code_errors/test14/makefile b/migration-agent/test_examples/source_code_errors/test14/makefile new file mode 100644 index 000000000000..ad75933271d9 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test14/makefile @@ -0,0 +1,25 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags +CXXFLAGS = -Wall -std=c++11 + +# Source files +SRC = wrapper.cpp main.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: + $(CXX) $(CXXFLAGS) $(SRC) + +# Clean up object and executable files +clean: + rm -f $(OBJ) a.out *.log + +.PHONY: all clean diff --git a/migration-agent/test_examples/source_code_errors/test14/wrapper.cpp b/migration-agent/test_examples/source_code_errors/test14/wrapper.cpp new file mode 100644 index 000000000000..cb6418c53b05 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test14/wrapper.cpp @@ -0,0 +1,5 @@ +#include "wrapper.h" +#include +template void Wrapper::print() { + std::cout << x << std::endl; +} diff --git a/migration-agent/test_examples/source_code_errors/test14/wrapper.h b/migration-agent/test_examples/source_code_errors/test14/wrapper.h new file mode 100644 index 000000000000..a239e59d3c82 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test14/wrapper.h @@ -0,0 +1,12 @@ +#ifndef WRAPPER_H +#define WRAPPER_H +template class Wrapper { + public: + Wrapper() = default; + Wrapper(const T &t) : x(t) {} + void print(); + private: + T x; +}; +template class Wrapper; +#endif diff --git a/migration-agent/test_examples/source_code_errors/test15/makefile b/migration-agent/test_examples/source_code_errors/test15/makefile new file mode 100644 index 000000000000..4b09ca26eb43 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test15/makefile @@ -0,0 +1,25 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags +CXXFLAGS = -Wall -std=c++11 + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: + $(CXX) $(CXXFLAGS) -c $(SRC) -o $(OBJ) + +# Clean up object and executable files +clean: + rm -f $(OBJ) *.log + +.PHONY: all clean diff --git a/migration-agent/test_examples/source_code_errors/test15/test.cpp b/migration-agent/test_examples/source_code_errors/test15/test.cpp new file mode 100644 index 000000000000..2623c358f5af --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test15/test.cpp @@ -0,0 +1,15 @@ +#include +#include +struct S { + static constexpr int Dim = 3; +}; +void func(const S &s) { + std::array a; + std::cout << s.Dim << std::endl; + std::cout << a.size() << std::endl; +} +int main() { + S s; + func(s); + return 0; +} diff --git a/migration-agent/test_examples/source_code_errors/test16/func.cpp b/migration-agent/test_examples/source_code_errors/test16/func.cpp new file mode 100644 index 000000000000..678fd29b443d --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test16/func.cpp @@ -0,0 +1,6 @@ +#include "pi.h" +#include +void func() { + double d = pi::value; + std::cout << "func: " << d << std::endl; +} diff --git a/migration-agent/test_examples/source_code_errors/test16/main.cpp b/migration-agent/test_examples/source_code_errors/test16/main.cpp new file mode 100644 index 000000000000..25adb482e6b5 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test16/main.cpp @@ -0,0 +1,10 @@ +#include +#include "pi.h" +void func(); +int main() { + double d = pi::value; + std::cout << "main: " << d << std::endl; + func(); + return 0; +} + diff --git a/migration-agent/test_examples/source_code_errors/test16/makefile b/migration-agent/test_examples/source_code_errors/test16/makefile new file mode 100644 index 000000000000..1000d8691070 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test16/makefile @@ -0,0 +1,25 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags +CXXFLAGS = -Wall -std=c++14 + +# Source files +SRC = func.cpp main.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: + $(CXX) $(CXXFLAGS) $(SRC) + +# Clean up object and executable files +clean: + rm -f $(OBJ) a.out *.log + +.PHONY: all clean diff --git a/migration-agent/test_examples/source_code_errors/test16/pi.cpp b/migration-agent/test_examples/source_code_errors/test16/pi.cpp new file mode 100644 index 000000000000..eb687d5995ce --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test16/pi.cpp @@ -0,0 +1,5 @@ +#include "pi.h" +template +T pi::value = 3.14159265358979323846264338327950288419716939937510; +template +T pi::value; \ No newline at end of file diff --git a/migration-agent/test_examples/source_code_errors/test16/pi.h b/migration-agent/test_examples/source_code_errors/test16/pi.h new file mode 100644 index 000000000000..b076027beb40 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test16/pi.h @@ -0,0 +1,8 @@ +#ifndef PI_H +#define PI_H +namespace pi { +template +constexpr T value() { return T(3.14159265358979323846264338327950288419716939937510); +} +} +#endif \ No newline at end of file diff --git a/migration-agent/test_examples/source_code_errors/test17/makefile b/migration-agent/test_examples/source_code_errors/test17/makefile new file mode 100644 index 000000000000..054e9650af44 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test17/makefile @@ -0,0 +1,25 @@ +# Compiler + +ifeq ($(CC),) + CC = clang +endif + + +# Compiler flags +CCFLAGS = -Wall + +# Source files +SRC = test.c + +# Object files +OBJ = $(SRC:.c=.o) + +# Default rule +all: + $(CC) $(CCFLAGS) -c $(SRC) -o $(OBJ) + +# Clean up object and executable files +clean: + rm -f $(OBJ) + +.PHONY: all clean diff --git a/migration-agent/test_examples/source_code_errors/test17/test.c b/migration-agent/test_examples/source_code_errors/test17/test.c new file mode 100644 index 000000000000..67ca0e04e668 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test17/test.c @@ -0,0 +1,5 @@ +int foo (double a, double b) +{ + double square (double z){ return z * z; } + return square (a) + square (b); +} diff --git a/migration-agent/test_examples/source_code_errors/test18/makefile b/migration-agent/test_examples/source_code_errors/test18/makefile new file mode 100644 index 000000000000..4b09ca26eb43 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test18/makefile @@ -0,0 +1,25 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags +CXXFLAGS = -Wall -std=c++11 + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: + $(CXX) $(CXXFLAGS) -c $(SRC) -o $(OBJ) + +# Clean up object and executable files +clean: + rm -f $(OBJ) *.log + +.PHONY: all clean diff --git a/migration-agent/test_examples/source_code_errors/test18/test.cpp b/migration-agent/test_examples/source_code_errors/test18/test.cpp new file mode 100644 index 000000000000..6e2db58c3142 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test18/test.cpp @@ -0,0 +1,19 @@ +#include + class CommonName { + int x; +}; + namespace ns::CommonName { +class C { +public: + void print() { + std::cout << "Hello, world" << std::endl; + } +}; +} // namespace ns::CommonName + using namespace ns; + int main() { + // ns::CommonName::C c; + CommonName::C c; + c.print(); + return 0; +} diff --git a/migration-agent/test_examples/source_code_errors/test19/makefile b/migration-agent/test_examples/source_code_errors/test19/makefile new file mode 100644 index 000000000000..4b09ca26eb43 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test19/makefile @@ -0,0 +1,25 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags +CXXFLAGS = -Wall -std=c++11 + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: + $(CXX) $(CXXFLAGS) -c $(SRC) -o $(OBJ) + +# Clean up object and executable files +clean: + rm -f $(OBJ) *.log + +.PHONY: all clean diff --git a/migration-agent/test_examples/source_code_errors/test19/test.cpp b/migration-agent/test_examples/source_code_errors/test19/test.cpp new file mode 100644 index 000000000000..1704b331122d --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test19/test.cpp @@ -0,0 +1,17 @@ +template +void f (T* p) +{ + p->~auto(); +} + +int d; +struct A { ~A() { ++d; } }; + +int main() +{ + f(new int(42)); + f(new A); + if (d != 1) + throw; + return 0; +} diff --git a/migration-agent/test_examples/source_code_errors/test2/makefile b/migration-agent/test_examples/source_code_errors/test2/makefile new file mode 100644 index 000000000000..ecbaffc455a9 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test2/makefile @@ -0,0 +1,35 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags +CXXFLAGS = -Wall -std=c++11 + +# Output executable name +TARGET = test + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: $(TARGET) + +# Rule to create the executable +$(TARGET): $(OBJ) + $(CXX) $(OBJ) -o $(TARGET) + +# Rule to compile .cpp files into .o files +%.o: %.cpp + $(CXX) $(CXXFLAGS) -c $< -o $@ + +# Clean up object and executable files +clean: + rm -f $(OBJ) $(TARGET) + +.PHONY: all clean diff --git a/migration-agent/test_examples/source_code_errors/test2/test.cpp b/migration-agent/test_examples/source_code_errors/test2/test.cpp new file mode 100644 index 000000000000..9a46798cba32 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test2/test.cpp @@ -0,0 +1,12 @@ +#include + +struct E __final {}; + +void foo(){ + printf("Hello world\n"); +} + +int main() +{ + return 0; +} diff --git a/migration-agent/test_examples/source_code_errors/test20/makefile b/migration-agent/test_examples/source_code_errors/test20/makefile new file mode 100644 index 000000000000..4b09ca26eb43 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test20/makefile @@ -0,0 +1,25 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags +CXXFLAGS = -Wall -std=c++11 + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: + $(CXX) $(CXXFLAGS) -c $(SRC) -o $(OBJ) + +# Clean up object and executable files +clean: + rm -f $(OBJ) *.log + +.PHONY: all clean diff --git a/migration-agent/test_examples/source_code_errors/test20/test.cpp b/migration-agent/test_examples/source_code_errors/test20/test.cpp new file mode 100644 index 000000000000..ca3e2e58e011 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test20/test.cpp @@ -0,0 +1,3 @@ +void test(int n){ + char num[n]={0}; +} diff --git a/migration-agent/test_examples/source_code_errors/test21/makefile b/migration-agent/test_examples/source_code_errors/test21/makefile new file mode 100644 index 000000000000..4b09ca26eb43 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test21/makefile @@ -0,0 +1,25 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags +CXXFLAGS = -Wall -std=c++11 + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: + $(CXX) $(CXXFLAGS) -c $(SRC) -o $(OBJ) + +# Clean up object and executable files +clean: + rm -f $(OBJ) *.log + +.PHONY: all clean diff --git a/migration-agent/test_examples/source_code_errors/test21/test.cpp b/migration-agent/test_examples/source_code_errors/test21/test.cpp new file mode 100644 index 000000000000..a8bd5ae7d65d --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test21/test.cpp @@ -0,0 +1,4 @@ +void func() { +  double y = 2.0; +  int z {y}; +} diff --git a/migration-agent/test_examples/source_code_errors/test23/makefile b/migration-agent/test_examples/source_code_errors/test23/makefile new file mode 100644 index 000000000000..4b09ca26eb43 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test23/makefile @@ -0,0 +1,25 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags +CXXFLAGS = -Wall -std=c++11 + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: + $(CXX) $(CXXFLAGS) -c $(SRC) -o $(OBJ) + +# Clean up object and executable files +clean: + rm -f $(OBJ) *.log + +.PHONY: all clean diff --git a/migration-agent/test_examples/source_code_errors/test23/test.cpp b/migration-agent/test_examples/source_code_errors/test23/test.cpp new file mode 100644 index 000000000000..080d324aed62 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test23/test.cpp @@ -0,0 +1,2 @@ +template static void func() {} +template static void func(); diff --git a/migration-agent/test_examples/source_code_errors/test24/makefile b/migration-agent/test_examples/source_code_errors/test24/makefile new file mode 100644 index 000000000000..4b09ca26eb43 --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test24/makefile @@ -0,0 +1,25 @@ +# Compiler + +ifeq ($(CXX),) + CXX = clang++ +endif + + +# Compiler flags +CXXFLAGS = -Wall -std=c++11 + +# Source files +SRC = test.cpp + +# Object files +OBJ = $(SRC:.cpp=.o) + +# Default rule +all: + $(CXX) $(CXXFLAGS) -c $(SRC) -o $(OBJ) + +# Clean up object and executable files +clean: + rm -f $(OBJ) *.log + +.PHONY: all clean diff --git a/migration-agent/test_examples/source_code_errors/test24/test.cpp b/migration-agent/test_examples/source_code_errors/test24/test.cpp new file mode 100644 index 000000000000..a7883167e28d --- /dev/null +++ b/migration-agent/test_examples/source_code_errors/test24/test.cpp @@ -0,0 +1,11 @@ +#include +#include +template