[clang] [clang-format] Add null-terminated path option (#123921) (PR #123926)
@@ -869,5 +876,12 @@ def convert_string(bytes_input): return str(bytes_input) +def print_filename(filename, null=False): +if null: +print(filename + "\0", end="") +else: +print("%s" % filename) owenca wrote: ```suggestion def print_filenames(filenames, print0=False): for filename in filenames: if print0: print(filename, end="\0") else: print(" " * 4 + filename) ``` https://github.com/llvm/llvm-project/pull/123926 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add null-terminated path option (#123921) (PR #123926)
@@ -261,14 +267,14 @@ def main(): "ignored by clang-format):" ) for filename in ignored_files: -print("%s" % filename) +print_filename(filename, opts.null) owenca wrote: ```suggestion print_filenames(ignored_files, opts.print0) ``` and delete line 269 above. https://github.com/llvm/llvm-project/pull/123926 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add null-terminated path option (#123921) (PR #123926)
@@ -869,5 +875,12 @@ def convert_string(bytes_input): return str(bytes_input) +def print_filename(filename, null=False): +if null: +print(filename + "\0", end="") owenca wrote: > Shouldn't you copy the the indentation of the printed files? It prints the filename, not the file. https://github.com/llvm/llvm-project/pull/123926 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add null-terminated path option (#123921) (PR #123926)
@@ -205,6 +205,12 @@ def main(): "commits" ), ) +p.add_argument( +"-0", +"--null", owenca wrote: Please move it (and `--diff_from_common_commit` above) up to keep the options sorted. I would use `--print0` (without `-0`) instead, just like in `find -print0` that can be piped to `xargs -0`. https://github.com/llvm/llvm-project/pull/123926 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add null-terminated path option (#123921) (PR #123926)
@@ -205,6 +205,12 @@ def main(): "commits" ), ) +p.add_argument( +"-0", +"--null", +action="store_true", +help="print the affected paths with null-terminated characters", owenca wrote: ```suggestion help="end each printed filename with a null character", ``` https://github.com/llvm/llvm-project/pull/123926 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Sema] Migrate away from PointerUnion::dyn_cast (NFC) (PR #124447)
https://github.com/nikic approved this pull request. https://github.com/llvm/llvm-project/pull/124447 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AST] Migrate away from PointerUnion::dyn_cast (NFC) (PR #124446)
https://github.com/nikic approved this pull request. https://github.com/llvm/llvm-project/pull/124446 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
@@ -0,0 +1,626 @@ +#!/usr/bin/env python3 + +""" generate_unsupported_in_drivermode.py + +usage: python generate_unsupported_in_drivermode.py /Options.td [/llvm-tblgen] + +This script generates a Lit regression test file that validates that options +are only exposed to intended driver modes. + +The options and driver modes are parsed from Options.td, whose path should be +provided on the command line. See clang/include/clang/Driver/Options.td + +The path to the TableGen executable can optionally be provided. Otherwise, the +script will search for it. + +The primary maintenance task for this script would be updating the expected return message for a driver mode if +there are changes over time. See the instantiations of DriverController, specifically the check_string. + +Logic: +1) For each option, (records of class "Option"), and for each driver, (records of class "OptionVisibility") +a. if the option's "Visibility" field includes the driver flavour, skip processing this option for this driver +b. if the option is part of an option group, (the record has the "Group" property), + and the group's "Visibility" field includes the driver flavour, skip processing this option for this driver +c. otherwise this option is not supported by this driver flavour, and this pairing is saved for testing +2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to parse for expected output. Ex: "error: unknown argument" +""" + +import sys +import shutil +import os +import json +import subprocess +import math +from pathlib import Path + +LLVM_TABLEGEN = "llvm-tblgen" +LIT_TEST_PATH = "../test/Driver/unsupported_in_drivermode.c" +LIT_TEST_PATH_FLANG = "../test/Driver/flang/unsupported_in_flang.f90" +INCLUDE_PATH = "../../llvm/include" + +# Strings defined in Options.td for the various driver flavours. See "OptionVisibility" +VISIBILITY_CC1AS = "CC1AsOption" +VISIBILITY_CC1 = "CC1Option" +VISIBILITY_CL = "CLOption" +VISIBILITY_DXC = "DXCOption" +VISIBILITY_DEFAULT = "DefaultVis" +VISIBILITY_FC1 = "FC1Option" +VISIBILITY_FLANG = "FlangOption" + +# Strings used in the commands to be tested +CLANG = "clang" +CLANG_CL = f"{CLANG} --driver-mode=cl" +CLANG_DXC = f"{CLANG} --driver-mode=dxc" +FLANG = f"{CLANG} --driver-mode=flang" +CLANG_LIT = "%clang" +CLANG_CL_LIT = "%clang_cl" +CLANG_DXC_LIT = "%clang_dxc" +FLANG_LIT = f"%{FLANG}" +OPTION_HASH = "-###" +OPTION_X = "-x" +OPTION_WX = "/WX" +OPTION_CPP = "c++" +OPTION_C = "-c" +OPTION_CC1 = "-cc1" +OPTION_CC1AS = "-cc1as" +OPTION_FC1 = "-fc1" +OPTION_SLASH_C = "/c" +OPTION_T = "/T lib_6_7" +SLASH_SLASH = "// " +EXCLAMATION = "! " Maetveis wrote: I don't think giving these names like this is particularly helpful, it just requires me to jump back and forth when reading the strings below to see what the variables will resolve to. https://github.com/llvm/llvm-project/pull/120900 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
https://github.com/Maetveis edited https://github.com/llvm/llvm-project/pull/120900 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
@@ -0,0 +1,626 @@ +#!/usr/bin/env python3 + +""" generate_unsupported_in_drivermode.py + +usage: python generate_unsupported_in_drivermode.py /Options.td [/llvm-tblgen] + +This script generates a Lit regression test file that validates that options +are only exposed to intended driver modes. + +The options and driver modes are parsed from Options.td, whose path should be +provided on the command line. See clang/include/clang/Driver/Options.td + +The path to the TableGen executable can optionally be provided. Otherwise, the +script will search for it. + +The primary maintenance task for this script would be updating the expected return message for a driver mode if +there are changes over time. See the instantiations of DriverController, specifically the check_string. + +Logic: +1) For each option, (records of class "Option"), and for each driver, (records of class "OptionVisibility") +a. if the option's "Visibility" field includes the driver flavour, skip processing this option for this driver +b. if the option is part of an option group, (the record has the "Group" property), + and the group's "Visibility" field includes the driver flavour, skip processing this option for this driver +c. otherwise this option is not supported by this driver flavour, and this pairing is saved for testing +2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to parse for expected output. Ex: "error: unknown argument" +""" + +import sys +import shutil +import os +import json +import subprocess +import math +from pathlib import Path + +LLVM_TABLEGEN = "llvm-tblgen" +LIT_TEST_PATH = "../test/Driver/unsupported_in_drivermode.c" +LIT_TEST_PATH_FLANG = "../test/Driver/flang/unsupported_in_flang.f90" +INCLUDE_PATH = "../../llvm/include" + +# Strings defined in Options.td for the various driver flavours. See "OptionVisibility" +VISIBILITY_CC1AS = "CC1AsOption" +VISIBILITY_CC1 = "CC1Option" +VISIBILITY_CL = "CLOption" +VISIBILITY_DXC = "DXCOption" +VISIBILITY_DEFAULT = "DefaultVis" +VISIBILITY_FC1 = "FC1Option" +VISIBILITY_FLANG = "FlangOption" + +# Strings used in the commands to be tested +CLANG = "clang" +CLANG_CL = f"{CLANG} --driver-mode=cl" +CLANG_DXC = f"{CLANG} --driver-mode=dxc" +FLANG = f"{CLANG} --driver-mode=flang" +CLANG_LIT = "%clang" +CLANG_CL_LIT = "%clang_cl" +CLANG_DXC_LIT = "%clang_dxc" +FLANG_LIT = f"%{FLANG}" +OPTION_HASH = "-###" +OPTION_X = "-x" +OPTION_WX = "/WX" +OPTION_CPP = "c++" +OPTION_C = "-c" +OPTION_CC1 = "-cc1" +OPTION_CC1AS = "-cc1as" +OPTION_FC1 = "-fc1" +OPTION_SLASH_C = "/c" +OPTION_T = "/T lib_6_7" +SLASH_SLASH = "// " +EXCLAMATION = "! " + +# Invalid usage of the driver options below causes unique output, so skip testing +exceptions_sequence = [ +"cc1", +"cc1as", +] + + +class DriverController: +"""Controller for data specific to each driver +shell_cmd_prefix: The beginning string of the command to be tested +lit_cmd_prefix: The beginning string of the Lit command +visibility_str: The corresponding visibility string from OptionVisibility in Options.td +shell_cmd_suffix: Strings near the end of the command to be tested +check_string: The string or regex to be sent to FileCheck +lit_cmd_end: String at the end of the Lit command + +supported_sequence: List of UnsupportedDriverOption objects for supported options +that are Kind KIND_JOINED*, as defined in Options.td +""" + +def __init__( +self, +shell_cmd_prefix="", +lit_cmd_prefix="", +visibility_str="", +shell_cmd_suffix="", +check_string="{{(unknown argument|n?N?o such file or directory)}}", +lit_cmd_end=" - < /dev/null 2>&1 | FileCheck -check-prefix=", +): +self.shell_cmd_prefix = shell_cmd_prefix +self.lit_cmd_prefix = lit_cmd_prefix +self.visibility_str = visibility_str +self.shell_cmd_suffix = shell_cmd_suffix +self.supported_sequence = [] +self.check_string = check_string +self.lit_cmd_end = lit_cmd_end + + +class UnsupportedDriverOption: +"""Defines an unsupported driver-option combination +driver: The driver string as defined by OptionVisibility in Options.td +option: The option object from Options.td +option_name: Corresponding string for an option. See "Name" for a given option in Options.td +prefix: String that precedes the option. Ex. "-" +is_error: Boolean indicating whether the corresponding command generates an error +""" + +def __init__(self, driver, option, option_name, prefix): +self.driver = driver +self.option = option +self.option_name = option_name +self.prefix = prefix +self.is_error = True + +# For sorting +def __len__(self): +return len(self.option_name) + + +def print_usage(): +"""Print valid usage of this script""" +sys.exit("usage: python " + sys.argv[0] + " /Options.td
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
@@ -0,0 +1,626 @@ +#!/usr/bin/env python3 + +""" generate_unsupported_in_drivermode.py + +usage: python generate_unsupported_in_drivermode.py /Options.td [/llvm-tblgen] + +This script generates a Lit regression test file that validates that options +are only exposed to intended driver modes. + +The options and driver modes are parsed from Options.td, whose path should be +provided on the command line. See clang/include/clang/Driver/Options.td + +The path to the TableGen executable can optionally be provided. Otherwise, the +script will search for it. + +The primary maintenance task for this script would be updating the expected return message for a driver mode if +there are changes over time. See the instantiations of DriverController, specifically the check_string. + +Logic: +1) For each option, (records of class "Option"), and for each driver, (records of class "OptionVisibility") +a. if the option's "Visibility" field includes the driver flavour, skip processing this option for this driver +b. if the option is part of an option group, (the record has the "Group" property), + and the group's "Visibility" field includes the driver flavour, skip processing this option for this driver +c. otherwise this option is not supported by this driver flavour, and this pairing is saved for testing +2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to parse for expected output. Ex: "error: unknown argument" +""" + +import sys +import shutil +import os +import json +import subprocess +import math +from pathlib import Path + +LLVM_TABLEGEN = "llvm-tblgen" +LIT_TEST_PATH = "../test/Driver/unsupported_in_drivermode.c" +LIT_TEST_PATH_FLANG = "../test/Driver/flang/unsupported_in_flang.f90" +INCLUDE_PATH = "../../llvm/include" + +# Strings defined in Options.td for the various driver flavours. See "OptionVisibility" +VISIBILITY_CC1AS = "CC1AsOption" +VISIBILITY_CC1 = "CC1Option" +VISIBILITY_CL = "CLOption" +VISIBILITY_DXC = "DXCOption" +VISIBILITY_DEFAULT = "DefaultVis" +VISIBILITY_FC1 = "FC1Option" +VISIBILITY_FLANG = "FlangOption" + +# Strings used in the commands to be tested +CLANG = "clang" +CLANG_CL = f"{CLANG} --driver-mode=cl" +CLANG_DXC = f"{CLANG} --driver-mode=dxc" +FLANG = f"{CLANG} --driver-mode=flang" +CLANG_LIT = "%clang" +CLANG_CL_LIT = "%clang_cl" +CLANG_DXC_LIT = "%clang_dxc" +FLANG_LIT = f"%{FLANG}" +OPTION_HASH = "-###" +OPTION_X = "-x" +OPTION_WX = "/WX" +OPTION_CPP = "c++" +OPTION_C = "-c" +OPTION_CC1 = "-cc1" +OPTION_CC1AS = "-cc1as" +OPTION_FC1 = "-fc1" +OPTION_SLASH_C = "/c" +OPTION_T = "/T lib_6_7" +SLASH_SLASH = "// " +EXCLAMATION = "! " + +# Invalid usage of the driver options below causes unique output, so skip testing +exceptions_sequence = [ +"cc1", +"cc1as", +] + + +class DriverController: +"""Controller for data specific to each driver +shell_cmd_prefix: The beginning string of the command to be tested +lit_cmd_prefix: The beginning string of the Lit command +visibility_str: The corresponding visibility string from OptionVisibility in Options.td +shell_cmd_suffix: Strings near the end of the command to be tested +check_string: The string or regex to be sent to FileCheck +lit_cmd_end: String at the end of the Lit command + +supported_sequence: List of UnsupportedDriverOption objects for supported options +that are Kind KIND_JOINED*, as defined in Options.td +""" + +def __init__( +self, +shell_cmd_prefix="", +lit_cmd_prefix="", +visibility_str="", +shell_cmd_suffix="", +check_string="{{(unknown argument|n?N?o such file or directory)}}", +lit_cmd_end=" - < /dev/null 2>&1 | FileCheck -check-prefix=", +): +self.shell_cmd_prefix = shell_cmd_prefix +self.lit_cmd_prefix = lit_cmd_prefix +self.visibility_str = visibility_str +self.shell_cmd_suffix = shell_cmd_suffix +self.supported_sequence = [] +self.check_string = check_string +self.lit_cmd_end = lit_cmd_end + + +class UnsupportedDriverOption: +"""Defines an unsupported driver-option combination +driver: The driver string as defined by OptionVisibility in Options.td +option: The option object from Options.td +option_name: Corresponding string for an option. See "Name" for a given option in Options.td +prefix: String that precedes the option. Ex. "-" +is_error: Boolean indicating whether the corresponding command generates an error +""" + +def __init__(self, driver, option, option_name, prefix): +self.driver = driver +self.option = option +self.option_name = option_name +self.prefix = prefix +self.is_error = True + +# For sorting +def __len__(self): +return len(self.option_name) + + +def print_usage(): +"""Print valid usage of this script""" +sys.exit("usage: python " + sys.argv[0] + " /Options.td
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
@@ -0,0 +1,626 @@ +#!/usr/bin/env python3 + +""" generate_unsupported_in_drivermode.py + +usage: python generate_unsupported_in_drivermode.py /Options.td [/llvm-tblgen] + +This script generates a Lit regression test file that validates that options +are only exposed to intended driver modes. + +The options and driver modes are parsed from Options.td, whose path should be +provided on the command line. See clang/include/clang/Driver/Options.td + +The path to the TableGen executable can optionally be provided. Otherwise, the +script will search for it. + +The primary maintenance task for this script would be updating the expected return message for a driver mode if +there are changes over time. See the instantiations of DriverController, specifically the check_string. + +Logic: +1) For each option, (records of class "Option"), and for each driver, (records of class "OptionVisibility") +a. if the option's "Visibility" field includes the driver flavour, skip processing this option for this driver +b. if the option is part of an option group, (the record has the "Group" property), + and the group's "Visibility" field includes the driver flavour, skip processing this option for this driver +c. otherwise this option is not supported by this driver flavour, and this pairing is saved for testing +2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to parse for expected output. Ex: "error: unknown argument" +""" + +import sys +import shutil +import os +import json +import subprocess +import math +from pathlib import Path + +LLVM_TABLEGEN = "llvm-tblgen" +LIT_TEST_PATH = "../test/Driver/unsupported_in_drivermode.c" +LIT_TEST_PATH_FLANG = "../test/Driver/flang/unsupported_in_flang.f90" +INCLUDE_PATH = "../../llvm/include" + +# Strings defined in Options.td for the various driver flavours. See "OptionVisibility" +VISIBILITY_CC1AS = "CC1AsOption" +VISIBILITY_CC1 = "CC1Option" +VISIBILITY_CL = "CLOption" +VISIBILITY_DXC = "DXCOption" +VISIBILITY_DEFAULT = "DefaultVis" +VISIBILITY_FC1 = "FC1Option" +VISIBILITY_FLANG = "FlangOption" + +# Strings used in the commands to be tested +CLANG = "clang" +CLANG_CL = f"{CLANG} --driver-mode=cl" +CLANG_DXC = f"{CLANG} --driver-mode=dxc" +FLANG = f"{CLANG} --driver-mode=flang" +CLANG_LIT = "%clang" +CLANG_CL_LIT = "%clang_cl" +CLANG_DXC_LIT = "%clang_dxc" +FLANG_LIT = f"%{FLANG}" +OPTION_HASH = "-###" +OPTION_X = "-x" +OPTION_WX = "/WX" +OPTION_CPP = "c++" +OPTION_C = "-c" +OPTION_CC1 = "-cc1" +OPTION_CC1AS = "-cc1as" +OPTION_FC1 = "-fc1" +OPTION_SLASH_C = "/c" +OPTION_T = "/T lib_6_7" +SLASH_SLASH = "// " +EXCLAMATION = "! " + +# Invalid usage of the driver options below causes unique output, so skip testing +exceptions_sequence = [ +"cc1", +"cc1as", +] + + +class DriverController: +"""Controller for data specific to each driver +shell_cmd_prefix: The beginning string of the command to be tested +lit_cmd_prefix: The beginning string of the Lit command +visibility_str: The corresponding visibility string from OptionVisibility in Options.td +shell_cmd_suffix: Strings near the end of the command to be tested +check_string: The string or regex to be sent to FileCheck +lit_cmd_end: String at the end of the Lit command + +supported_sequence: List of UnsupportedDriverOption objects for supported options +that are Kind KIND_JOINED*, as defined in Options.td +""" + +def __init__( +self, +shell_cmd_prefix="", +lit_cmd_prefix="", +visibility_str="", +shell_cmd_suffix="", +check_string="{{(unknown argument|n?N?o such file or directory)}}", +lit_cmd_end=" - < /dev/null 2>&1 | FileCheck -check-prefix=", +): +self.shell_cmd_prefix = shell_cmd_prefix +self.lit_cmd_prefix = lit_cmd_prefix +self.visibility_str = visibility_str +self.shell_cmd_suffix = shell_cmd_suffix +self.supported_sequence = [] +self.check_string = check_string +self.lit_cmd_end = lit_cmd_end + + +class UnsupportedDriverOption: +"""Defines an unsupported driver-option combination +driver: The driver string as defined by OptionVisibility in Options.td +option: The option object from Options.td +option_name: Corresponding string for an option. See "Name" for a given option in Options.td +prefix: String that precedes the option. Ex. "-" +is_error: Boolean indicating whether the corresponding command generates an error +""" + +def __init__(self, driver, option, option_name, prefix): +self.driver = driver +self.option = option +self.option_name = option_name +self.prefix = prefix +self.is_error = True + +# For sorting +def __len__(self): +return len(self.option_name) + + +def print_usage(): +"""Print valid usage of this script""" +sys.exit("usage: python " + sys.argv[0] + " /Options.td
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
https://github.com/Maetveis requested changes to this pull request. Phew, first round in. Please don't take the number of suggestions as a negative, the basic structure looks good there's just many small tweaks to be made :). https://github.com/llvm/llvm-project/pull/120900 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
@@ -0,0 +1,626 @@ +#!/usr/bin/env python3 + +""" generate_unsupported_in_drivermode.py + +usage: python generate_unsupported_in_drivermode.py /Options.td [/llvm-tblgen] + +This script generates a Lit regression test file that validates that options +are only exposed to intended driver modes. + +The options and driver modes are parsed from Options.td, whose path should be +provided on the command line. See clang/include/clang/Driver/Options.td + +The path to the TableGen executable can optionally be provided. Otherwise, the +script will search for it. + +The primary maintenance task for this script would be updating the expected return message for a driver mode if +there are changes over time. See the instantiations of DriverController, specifically the check_string. + +Logic: +1) For each option, (records of class "Option"), and for each driver, (records of class "OptionVisibility") +a. if the option's "Visibility" field includes the driver flavour, skip processing this option for this driver +b. if the option is part of an option group, (the record has the "Group" property), + and the group's "Visibility" field includes the driver flavour, skip processing this option for this driver +c. otherwise this option is not supported by this driver flavour, and this pairing is saved for testing +2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to parse for expected output. Ex: "error: unknown argument" +""" + +import sys +import shutil +import os +import json +import subprocess +import math +from pathlib import Path + +LLVM_TABLEGEN = "llvm-tblgen" +LIT_TEST_PATH = "../test/Driver/unsupported_in_drivermode.c" +LIT_TEST_PATH_FLANG = "../test/Driver/flang/unsupported_in_flang.f90" +INCLUDE_PATH = "../../llvm/include" + +# Strings defined in Options.td for the various driver flavours. See "OptionVisibility" +VISIBILITY_CC1AS = "CC1AsOption" +VISIBILITY_CC1 = "CC1Option" +VISIBILITY_CL = "CLOption" +VISIBILITY_DXC = "DXCOption" +VISIBILITY_DEFAULT = "DefaultVis" +VISIBILITY_FC1 = "FC1Option" +VISIBILITY_FLANG = "FlangOption" + +# Strings used in the commands to be tested +CLANG = "clang" +CLANG_CL = f"{CLANG} --driver-mode=cl" +CLANG_DXC = f"{CLANG} --driver-mode=dxc" +FLANG = f"{CLANG} --driver-mode=flang" +CLANG_LIT = "%clang" +CLANG_CL_LIT = "%clang_cl" +CLANG_DXC_LIT = "%clang_dxc" +FLANG_LIT = f"%{FLANG}" +OPTION_HASH = "-###" +OPTION_X = "-x" +OPTION_WX = "/WX" +OPTION_CPP = "c++" +OPTION_C = "-c" +OPTION_CC1 = "-cc1" +OPTION_CC1AS = "-cc1as" +OPTION_FC1 = "-fc1" +OPTION_SLASH_C = "/c" +OPTION_T = "/T lib_6_7" +SLASH_SLASH = "// " +EXCLAMATION = "! " + +# Invalid usage of the driver options below causes unique output, so skip testing +exceptions_sequence = [ +"cc1", +"cc1as", +] + + +class DriverController: +"""Controller for data specific to each driver +shell_cmd_prefix: The beginning string of the command to be tested +lit_cmd_prefix: The beginning string of the Lit command +visibility_str: The corresponding visibility string from OptionVisibility in Options.td +shell_cmd_suffix: Strings near the end of the command to be tested +check_string: The string or regex to be sent to FileCheck +lit_cmd_end: String at the end of the Lit command + +supported_sequence: List of UnsupportedDriverOption objects for supported options +that are Kind KIND_JOINED*, as defined in Options.td +""" + +def __init__( +self, +shell_cmd_prefix="", +lit_cmd_prefix="", +visibility_str="", +shell_cmd_suffix="", +check_string="{{(unknown argument|n?N?o such file or directory)}}", +lit_cmd_end=" - < /dev/null 2>&1 | FileCheck -check-prefix=", +): +self.shell_cmd_prefix = shell_cmd_prefix +self.lit_cmd_prefix = lit_cmd_prefix +self.visibility_str = visibility_str +self.shell_cmd_suffix = shell_cmd_suffix +self.supported_sequence = [] +self.check_string = check_string +self.lit_cmd_end = lit_cmd_end + + +class UnsupportedDriverOption: +"""Defines an unsupported driver-option combination +driver: The driver string as defined by OptionVisibility in Options.td +option: The option object from Options.td +option_name: Corresponding string for an option. See "Name" for a given option in Options.td +prefix: String that precedes the option. Ex. "-" +is_error: Boolean indicating whether the corresponding command generates an error +""" + +def __init__(self, driver, option, option_name, prefix): +self.driver = driver +self.option = option +self.option_name = option_name +self.prefix = prefix +self.is_error = True + +# For sorting +def __len__(self): +return len(self.option_name) + + +def print_usage(): +"""Print valid usage of this script""" +sys.exit("usage: python " + sys.argv[0] + " /Options.td
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
@@ -0,0 +1,626 @@ +#!/usr/bin/env python3 + +""" generate_unsupported_in_drivermode.py + +usage: python generate_unsupported_in_drivermode.py /Options.td [/llvm-tblgen] + +This script generates a Lit regression test file that validates that options +are only exposed to intended driver modes. + +The options and driver modes are parsed from Options.td, whose path should be +provided on the command line. See clang/include/clang/Driver/Options.td + +The path to the TableGen executable can optionally be provided. Otherwise, the +script will search for it. + +The primary maintenance task for this script would be updating the expected return message for a driver mode if +there are changes over time. See the instantiations of DriverController, specifically the check_string. + +Logic: +1) For each option, (records of class "Option"), and for each driver, (records of class "OptionVisibility") +a. if the option's "Visibility" field includes the driver flavour, skip processing this option for this driver +b. if the option is part of an option group, (the record has the "Group" property), + and the group's "Visibility" field includes the driver flavour, skip processing this option for this driver +c. otherwise this option is not supported by this driver flavour, and this pairing is saved for testing +2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to parse for expected output. Ex: "error: unknown argument" +""" + +import sys +import shutil +import os +import json +import subprocess +import math +from pathlib import Path + +LLVM_TABLEGEN = "llvm-tblgen" +LIT_TEST_PATH = "../test/Driver/unsupported_in_drivermode.c" +LIT_TEST_PATH_FLANG = "../test/Driver/flang/unsupported_in_flang.f90" +INCLUDE_PATH = "../../llvm/include" + +# Strings defined in Options.td for the various driver flavours. See "OptionVisibility" +VISIBILITY_CC1AS = "CC1AsOption" +VISIBILITY_CC1 = "CC1Option" +VISIBILITY_CL = "CLOption" +VISIBILITY_DXC = "DXCOption" +VISIBILITY_DEFAULT = "DefaultVis" +VISIBILITY_FC1 = "FC1Option" +VISIBILITY_FLANG = "FlangOption" + +# Strings used in the commands to be tested +CLANG = "clang" +CLANG_CL = f"{CLANG} --driver-mode=cl" +CLANG_DXC = f"{CLANG} --driver-mode=dxc" +FLANG = f"{CLANG} --driver-mode=flang" +CLANG_LIT = "%clang" +CLANG_CL_LIT = "%clang_cl" +CLANG_DXC_LIT = "%clang_dxc" +FLANG_LIT = f"%{FLANG}" +OPTION_HASH = "-###" +OPTION_X = "-x" +OPTION_WX = "/WX" +OPTION_CPP = "c++" +OPTION_C = "-c" +OPTION_CC1 = "-cc1" +OPTION_CC1AS = "-cc1as" +OPTION_FC1 = "-fc1" +OPTION_SLASH_C = "/c" +OPTION_T = "/T lib_6_7" +SLASH_SLASH = "// " +EXCLAMATION = "! " + +# Invalid usage of the driver options below causes unique output, so skip testing +exceptions_sequence = [ +"cc1", +"cc1as", +] + + +class DriverController: +"""Controller for data specific to each driver +shell_cmd_prefix: The beginning string of the command to be tested +lit_cmd_prefix: The beginning string of the Lit command +visibility_str: The corresponding visibility string from OptionVisibility in Options.td +shell_cmd_suffix: Strings near the end of the command to be tested +check_string: The string or regex to be sent to FileCheck +lit_cmd_end: String at the end of the Lit command + +supported_sequence: List of UnsupportedDriverOption objects for supported options +that are Kind KIND_JOINED*, as defined in Options.td +""" + +def __init__( +self, +shell_cmd_prefix="", +lit_cmd_prefix="", +visibility_str="", +shell_cmd_suffix="", +check_string="{{(unknown argument|n?N?o such file or directory)}}", +lit_cmd_end=" - < /dev/null 2>&1 | FileCheck -check-prefix=", +): +self.shell_cmd_prefix = shell_cmd_prefix +self.lit_cmd_prefix = lit_cmd_prefix +self.visibility_str = visibility_str +self.shell_cmd_suffix = shell_cmd_suffix +self.supported_sequence = [] +self.check_string = check_string +self.lit_cmd_end = lit_cmd_end + + +class UnsupportedDriverOption: +"""Defines an unsupported driver-option combination +driver: The driver string as defined by OptionVisibility in Options.td +option: The option object from Options.td +option_name: Corresponding string for an option. See "Name" for a given option in Options.td +prefix: String that precedes the option. Ex. "-" +is_error: Boolean indicating whether the corresponding command generates an error +""" + +def __init__(self, driver, option, option_name, prefix): +self.driver = driver +self.option = option +self.option_name = option_name +self.prefix = prefix +self.is_error = True + +# For sorting +def __len__(self): +return len(self.option_name) + + +def print_usage(): +"""Print valid usage of this script""" +sys.exit("usage: python " + sys.argv[0] + " /Options.td
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
@@ -0,0 +1,626 @@ +#!/usr/bin/env python3 + +""" generate_unsupported_in_drivermode.py + +usage: python generate_unsupported_in_drivermode.py /Options.td [/llvm-tblgen] + +This script generates a Lit regression test file that validates that options +are only exposed to intended driver modes. + +The options and driver modes are parsed from Options.td, whose path should be +provided on the command line. See clang/include/clang/Driver/Options.td + +The path to the TableGen executable can optionally be provided. Otherwise, the +script will search for it. + +The primary maintenance task for this script would be updating the expected return message for a driver mode if +there are changes over time. See the instantiations of DriverController, specifically the check_string. + +Logic: +1) For each option, (records of class "Option"), and for each driver, (records of class "OptionVisibility") +a. if the option's "Visibility" field includes the driver flavour, skip processing this option for this driver +b. if the option is part of an option group, (the record has the "Group" property), + and the group's "Visibility" field includes the driver flavour, skip processing this option for this driver +c. otherwise this option is not supported by this driver flavour, and this pairing is saved for testing +2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to parse for expected output. Ex: "error: unknown argument" +""" + +import sys +import shutil +import os +import json +import subprocess +import math +from pathlib import Path + +LLVM_TABLEGEN = "llvm-tblgen" +LIT_TEST_PATH = "../test/Driver/unsupported_in_drivermode.c" +LIT_TEST_PATH_FLANG = "../test/Driver/flang/unsupported_in_flang.f90" +INCLUDE_PATH = "../../llvm/include" + +# Strings defined in Options.td for the various driver flavours. See "OptionVisibility" +VISIBILITY_CC1AS = "CC1AsOption" +VISIBILITY_CC1 = "CC1Option" +VISIBILITY_CL = "CLOption" +VISIBILITY_DXC = "DXCOption" +VISIBILITY_DEFAULT = "DefaultVis" +VISIBILITY_FC1 = "FC1Option" +VISIBILITY_FLANG = "FlangOption" + +# Strings used in the commands to be tested +CLANG = "clang" +CLANG_CL = f"{CLANG} --driver-mode=cl" +CLANG_DXC = f"{CLANG} --driver-mode=dxc" +FLANG = f"{CLANG} --driver-mode=flang" +CLANG_LIT = "%clang" +CLANG_CL_LIT = "%clang_cl" +CLANG_DXC_LIT = "%clang_dxc" +FLANG_LIT = f"%{FLANG}" +OPTION_HASH = "-###" +OPTION_X = "-x" +OPTION_WX = "/WX" +OPTION_CPP = "c++" +OPTION_C = "-c" +OPTION_CC1 = "-cc1" +OPTION_CC1AS = "-cc1as" +OPTION_FC1 = "-fc1" +OPTION_SLASH_C = "/c" +OPTION_T = "/T lib_6_7" +SLASH_SLASH = "// " +EXCLAMATION = "! " + +# Invalid usage of the driver options below causes unique output, so skip testing +exceptions_sequence = [ +"cc1", +"cc1as", +] + + +class DriverController: +"""Controller for data specific to each driver +shell_cmd_prefix: The beginning string of the command to be tested +lit_cmd_prefix: The beginning string of the Lit command +visibility_str: The corresponding visibility string from OptionVisibility in Options.td +shell_cmd_suffix: Strings near the end of the command to be tested +check_string: The string or regex to be sent to FileCheck +lit_cmd_end: String at the end of the Lit command + +supported_sequence: List of UnsupportedDriverOption objects for supported options +that are Kind KIND_JOINED*, as defined in Options.td +""" + +def __init__( +self, +shell_cmd_prefix="", +lit_cmd_prefix="", +visibility_str="", +shell_cmd_suffix="", +check_string="{{(unknown argument|n?N?o such file or directory)}}", +lit_cmd_end=" - < /dev/null 2>&1 | FileCheck -check-prefix=", +): +self.shell_cmd_prefix = shell_cmd_prefix +self.lit_cmd_prefix = lit_cmd_prefix +self.visibility_str = visibility_str +self.shell_cmd_suffix = shell_cmd_suffix +self.supported_sequence = [] +self.check_string = check_string +self.lit_cmd_end = lit_cmd_end + + +class UnsupportedDriverOption: +"""Defines an unsupported driver-option combination +driver: The driver string as defined by OptionVisibility in Options.td +option: The option object from Options.td +option_name: Corresponding string for an option. See "Name" for a given option in Options.td +prefix: String that precedes the option. Ex. "-" +is_error: Boolean indicating whether the corresponding command generates an error +""" + +def __init__(self, driver, option, option_name, prefix): +self.driver = driver +self.option = option +self.option_name = option_name +self.prefix = prefix +self.is_error = True + +# For sorting +def __len__(self): +return len(self.option_name) + + +def print_usage(): +"""Print valid usage of this script""" +sys.exit("usage: python " + sys.argv[0] + " /Options.td
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
@@ -0,0 +1,626 @@ +#!/usr/bin/env python3 + +""" generate_unsupported_in_drivermode.py + +usage: python generate_unsupported_in_drivermode.py /Options.td [/llvm-tblgen] + +This script generates a Lit regression test file that validates that options +are only exposed to intended driver modes. + +The options and driver modes are parsed from Options.td, whose path should be +provided on the command line. See clang/include/clang/Driver/Options.td + +The path to the TableGen executable can optionally be provided. Otherwise, the +script will search for it. + +The primary maintenance task for this script would be updating the expected return message for a driver mode if +there are changes over time. See the instantiations of DriverController, specifically the check_string. + +Logic: +1) For each option, (records of class "Option"), and for each driver, (records of class "OptionVisibility") +a. if the option's "Visibility" field includes the driver flavour, skip processing this option for this driver +b. if the option is part of an option group, (the record has the "Group" property), + and the group's "Visibility" field includes the driver flavour, skip processing this option for this driver +c. otherwise this option is not supported by this driver flavour, and this pairing is saved for testing +2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to parse for expected output. Ex: "error: unknown argument" +""" + +import sys +import shutil +import os +import json +import subprocess +import math +from pathlib import Path + +LLVM_TABLEGEN = "llvm-tblgen" +LIT_TEST_PATH = "../test/Driver/unsupported_in_drivermode.c" +LIT_TEST_PATH_FLANG = "../test/Driver/flang/unsupported_in_flang.f90" +INCLUDE_PATH = "../../llvm/include" + +# Strings defined in Options.td for the various driver flavours. See "OptionVisibility" +VISIBILITY_CC1AS = "CC1AsOption" +VISIBILITY_CC1 = "CC1Option" +VISIBILITY_CL = "CLOption" +VISIBILITY_DXC = "DXCOption" +VISIBILITY_DEFAULT = "DefaultVis" +VISIBILITY_FC1 = "FC1Option" +VISIBILITY_FLANG = "FlangOption" + +# Strings used in the commands to be tested +CLANG = "clang" +CLANG_CL = f"{CLANG} --driver-mode=cl" +CLANG_DXC = f"{CLANG} --driver-mode=dxc" +FLANG = f"{CLANG} --driver-mode=flang" +CLANG_LIT = "%clang" +CLANG_CL_LIT = "%clang_cl" +CLANG_DXC_LIT = "%clang_dxc" +FLANG_LIT = f"%{FLANG}" +OPTION_HASH = "-###" +OPTION_X = "-x" +OPTION_WX = "/WX" +OPTION_CPP = "c++" +OPTION_C = "-c" +OPTION_CC1 = "-cc1" +OPTION_CC1AS = "-cc1as" +OPTION_FC1 = "-fc1" +OPTION_SLASH_C = "/c" +OPTION_T = "/T lib_6_7" +SLASH_SLASH = "// " +EXCLAMATION = "! " + +# Invalid usage of the driver options below causes unique output, so skip testing +exceptions_sequence = [ +"cc1", +"cc1as", +] + + +class DriverController: +"""Controller for data specific to each driver +shell_cmd_prefix: The beginning string of the command to be tested +lit_cmd_prefix: The beginning string of the Lit command +visibility_str: The corresponding visibility string from OptionVisibility in Options.td +shell_cmd_suffix: Strings near the end of the command to be tested +check_string: The string or regex to be sent to FileCheck +lit_cmd_end: String at the end of the Lit command + +supported_sequence: List of UnsupportedDriverOption objects for supported options +that are Kind KIND_JOINED*, as defined in Options.td +""" + +def __init__( +self, +shell_cmd_prefix="", +lit_cmd_prefix="", +visibility_str="", +shell_cmd_suffix="", +check_string="{{(unknown argument|n?N?o such file or directory)}}", +lit_cmd_end=" - < /dev/null 2>&1 | FileCheck -check-prefix=", +): +self.shell_cmd_prefix = shell_cmd_prefix +self.lit_cmd_prefix = lit_cmd_prefix +self.visibility_str = visibility_str +self.shell_cmd_suffix = shell_cmd_suffix +self.supported_sequence = [] +self.check_string = check_string +self.lit_cmd_end = lit_cmd_end + + +class UnsupportedDriverOption: +"""Defines an unsupported driver-option combination +driver: The driver string as defined by OptionVisibility in Options.td +option: The option object from Options.td +option_name: Corresponding string for an option. See "Name" for a given option in Options.td +prefix: String that precedes the option. Ex. "-" +is_error: Boolean indicating whether the corresponding command generates an error +""" + +def __init__(self, driver, option, option_name, prefix): +self.driver = driver +self.option = option +self.option_name = option_name +self.prefix = prefix +self.is_error = True + +# For sorting +def __len__(self): +return len(self.option_name) + + +def print_usage(): +"""Print valid usage of this script""" +sys.exit("usage: python " + sys.argv[0] + " /Options.td
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
@@ -0,0 +1,626 @@ +#!/usr/bin/env python3 + +""" generate_unsupported_in_drivermode.py + +usage: python generate_unsupported_in_drivermode.py /Options.td [/llvm-tblgen] + +This script generates a Lit regression test file that validates that options +are only exposed to intended driver modes. + +The options and driver modes are parsed from Options.td, whose path should be +provided on the command line. See clang/include/clang/Driver/Options.td + +The path to the TableGen executable can optionally be provided. Otherwise, the +script will search for it. + +The primary maintenance task for this script would be updating the expected return message for a driver mode if +there are changes over time. See the instantiations of DriverController, specifically the check_string. + +Logic: +1) For each option, (records of class "Option"), and for each driver, (records of class "OptionVisibility") +a. if the option's "Visibility" field includes the driver flavour, skip processing this option for this driver +b. if the option is part of an option group, (the record has the "Group" property), + and the group's "Visibility" field includes the driver flavour, skip processing this option for this driver +c. otherwise this option is not supported by this driver flavour, and this pairing is saved for testing +2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to parse for expected output. Ex: "error: unknown argument" +""" + +import sys +import shutil +import os +import json +import subprocess +import math +from pathlib import Path + +LLVM_TABLEGEN = "llvm-tblgen" +LIT_TEST_PATH = "../test/Driver/unsupported_in_drivermode.c" +LIT_TEST_PATH_FLANG = "../test/Driver/flang/unsupported_in_flang.f90" +INCLUDE_PATH = "../../llvm/include" + +# Strings defined in Options.td for the various driver flavours. See "OptionVisibility" +VISIBILITY_CC1AS = "CC1AsOption" +VISIBILITY_CC1 = "CC1Option" +VISIBILITY_CL = "CLOption" +VISIBILITY_DXC = "DXCOption" +VISIBILITY_DEFAULT = "DefaultVis" +VISIBILITY_FC1 = "FC1Option" +VISIBILITY_FLANG = "FlangOption" + +# Strings used in the commands to be tested +CLANG = "clang" +CLANG_CL = f"{CLANG} --driver-mode=cl" +CLANG_DXC = f"{CLANG} --driver-mode=dxc" +FLANG = f"{CLANG} --driver-mode=flang" +CLANG_LIT = "%clang" +CLANG_CL_LIT = "%clang_cl" +CLANG_DXC_LIT = "%clang_dxc" +FLANG_LIT = f"%{FLANG}" +OPTION_HASH = "-###" +OPTION_X = "-x" +OPTION_WX = "/WX" +OPTION_CPP = "c++" +OPTION_C = "-c" +OPTION_CC1 = "-cc1" +OPTION_CC1AS = "-cc1as" +OPTION_FC1 = "-fc1" +OPTION_SLASH_C = "/c" +OPTION_T = "/T lib_6_7" +SLASH_SLASH = "// " +EXCLAMATION = "! " + +# Invalid usage of the driver options below causes unique output, so skip testing +exceptions_sequence = [ +"cc1", +"cc1as", +] + + +class DriverController: +"""Controller for data specific to each driver +shell_cmd_prefix: The beginning string of the command to be tested +lit_cmd_prefix: The beginning string of the Lit command +visibility_str: The corresponding visibility string from OptionVisibility in Options.td +shell_cmd_suffix: Strings near the end of the command to be tested +check_string: The string or regex to be sent to FileCheck +lit_cmd_end: String at the end of the Lit command + +supported_sequence: List of UnsupportedDriverOption objects for supported options +that are Kind KIND_JOINED*, as defined in Options.td +""" + +def __init__( +self, +shell_cmd_prefix="", +lit_cmd_prefix="", +visibility_str="", +shell_cmd_suffix="", +check_string="{{(unknown argument|n?N?o such file or directory)}}", +lit_cmd_end=" - < /dev/null 2>&1 | FileCheck -check-prefix=", +): +self.shell_cmd_prefix = shell_cmd_prefix +self.lit_cmd_prefix = lit_cmd_prefix +self.visibility_str = visibility_str +self.shell_cmd_suffix = shell_cmd_suffix +self.supported_sequence = [] +self.check_string = check_string +self.lit_cmd_end = lit_cmd_end + + +class UnsupportedDriverOption: +"""Defines an unsupported driver-option combination +driver: The driver string as defined by OptionVisibility in Options.td +option: The option object from Options.td +option_name: Corresponding string for an option. See "Name" for a given option in Options.td +prefix: String that precedes the option. Ex. "-" +is_error: Boolean indicating whether the corresponding command generates an error +""" + +def __init__(self, driver, option, option_name, prefix): +self.driver = driver +self.option = option +self.option_name = option_name +self.prefix = prefix +self.is_error = True + +# For sorting +def __len__(self): +return len(self.option_name) + + +def print_usage(): +"""Print valid usage of this script""" +sys.exit("usage: python " + sys.argv[0] + " /Options.td
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
@@ -0,0 +1,626 @@ +#!/usr/bin/env python3 + +""" generate_unsupported_in_drivermode.py + +usage: python generate_unsupported_in_drivermode.py /Options.td [/llvm-tblgen] + +This script generates a Lit regression test file that validates that options +are only exposed to intended driver modes. + +The options and driver modes are parsed from Options.td, whose path should be +provided on the command line. See clang/include/clang/Driver/Options.td + +The path to the TableGen executable can optionally be provided. Otherwise, the +script will search for it. + +The primary maintenance task for this script would be updating the expected return message for a driver mode if +there are changes over time. See the instantiations of DriverController, specifically the check_string. + +Logic: +1) For each option, (records of class "Option"), and for each driver, (records of class "OptionVisibility") +a. if the option's "Visibility" field includes the driver flavour, skip processing this option for this driver +b. if the option is part of an option group, (the record has the "Group" property), + and the group's "Visibility" field includes the driver flavour, skip processing this option for this driver +c. otherwise this option is not supported by this driver flavour, and this pairing is saved for testing +2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to parse for expected output. Ex: "error: unknown argument" +""" + +import sys +import shutil +import os +import json +import subprocess +import math +from pathlib import Path + +LLVM_TABLEGEN = "llvm-tblgen" +LIT_TEST_PATH = "../test/Driver/unsupported_in_drivermode.c" +LIT_TEST_PATH_FLANG = "../test/Driver/flang/unsupported_in_flang.f90" +INCLUDE_PATH = "../../llvm/include" + +# Strings defined in Options.td for the various driver flavours. See "OptionVisibility" +VISIBILITY_CC1AS = "CC1AsOption" +VISIBILITY_CC1 = "CC1Option" +VISIBILITY_CL = "CLOption" +VISIBILITY_DXC = "DXCOption" +VISIBILITY_DEFAULT = "DefaultVis" +VISIBILITY_FC1 = "FC1Option" +VISIBILITY_FLANG = "FlangOption" + +# Strings used in the commands to be tested +CLANG = "clang" +CLANG_CL = f"{CLANG} --driver-mode=cl" +CLANG_DXC = f"{CLANG} --driver-mode=dxc" +FLANG = f"{CLANG} --driver-mode=flang" +CLANG_LIT = "%clang" +CLANG_CL_LIT = "%clang_cl" +CLANG_DXC_LIT = "%clang_dxc" +FLANG_LIT = f"%{FLANG}" +OPTION_HASH = "-###" +OPTION_X = "-x" +OPTION_WX = "/WX" +OPTION_CPP = "c++" +OPTION_C = "-c" +OPTION_CC1 = "-cc1" +OPTION_CC1AS = "-cc1as" +OPTION_FC1 = "-fc1" +OPTION_SLASH_C = "/c" +OPTION_T = "/T lib_6_7" +SLASH_SLASH = "// " +EXCLAMATION = "! " + +# Invalid usage of the driver options below causes unique output, so skip testing +exceptions_sequence = [ +"cc1", +"cc1as", +] + + +class DriverController: +"""Controller for data specific to each driver +shell_cmd_prefix: The beginning string of the command to be tested +lit_cmd_prefix: The beginning string of the Lit command +visibility_str: The corresponding visibility string from OptionVisibility in Options.td +shell_cmd_suffix: Strings near the end of the command to be tested +check_string: The string or regex to be sent to FileCheck +lit_cmd_end: String at the end of the Lit command + +supported_sequence: List of UnsupportedDriverOption objects for supported options +that are Kind KIND_JOINED*, as defined in Options.td +""" + +def __init__( +self, +shell_cmd_prefix="", +lit_cmd_prefix="", +visibility_str="", +shell_cmd_suffix="", +check_string="{{(unknown argument|n?N?o such file or directory)}}", +lit_cmd_end=" - < /dev/null 2>&1 | FileCheck -check-prefix=", +): +self.shell_cmd_prefix = shell_cmd_prefix +self.lit_cmd_prefix = lit_cmd_prefix +self.visibility_str = visibility_str +self.shell_cmd_suffix = shell_cmd_suffix +self.supported_sequence = [] +self.check_string = check_string +self.lit_cmd_end = lit_cmd_end + + +class UnsupportedDriverOption: +"""Defines an unsupported driver-option combination +driver: The driver string as defined by OptionVisibility in Options.td +option: The option object from Options.td +option_name: Corresponding string for an option. See "Name" for a given option in Options.td +prefix: String that precedes the option. Ex. "-" +is_error: Boolean indicating whether the corresponding command generates an error +""" + +def __init__(self, driver, option, option_name, prefix): +self.driver = driver +self.option = option +self.option_name = option_name +self.prefix = prefix +self.is_error = True + +# For sorting +def __len__(self): +return len(self.option_name) + + +def print_usage(): +"""Print valid usage of this script""" +sys.exit("usage: python " + sys.argv[0] + " /Options.td
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
@@ -0,0 +1,626 @@ +#!/usr/bin/env python3 + +""" generate_unsupported_in_drivermode.py + +usage: python generate_unsupported_in_drivermode.py /Options.td [/llvm-tblgen] + +This script generates a Lit regression test file that validates that options +are only exposed to intended driver modes. + +The options and driver modes are parsed from Options.td, whose path should be +provided on the command line. See clang/include/clang/Driver/Options.td + +The path to the TableGen executable can optionally be provided. Otherwise, the +script will search for it. + +The primary maintenance task for this script would be updating the expected return message for a driver mode if +there are changes over time. See the instantiations of DriverController, specifically the check_string. + +Logic: +1) For each option, (records of class "Option"), and for each driver, (records of class "OptionVisibility") +a. if the option's "Visibility" field includes the driver flavour, skip processing this option for this driver +b. if the option is part of an option group, (the record has the "Group" property), + and the group's "Visibility" field includes the driver flavour, skip processing this option for this driver +c. otherwise this option is not supported by this driver flavour, and this pairing is saved for testing +2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to parse for expected output. Ex: "error: unknown argument" +""" + +import sys +import shutil +import os +import json +import subprocess +import math +from pathlib import Path + +LLVM_TABLEGEN = "llvm-tblgen" +LIT_TEST_PATH = "../test/Driver/unsupported_in_drivermode.c" +LIT_TEST_PATH_FLANG = "../test/Driver/flang/unsupported_in_flang.f90" +INCLUDE_PATH = "../../llvm/include" + +# Strings defined in Options.td for the various driver flavours. See "OptionVisibility" +VISIBILITY_CC1AS = "CC1AsOption" +VISIBILITY_CC1 = "CC1Option" +VISIBILITY_CL = "CLOption" +VISIBILITY_DXC = "DXCOption" +VISIBILITY_DEFAULT = "DefaultVis" +VISIBILITY_FC1 = "FC1Option" +VISIBILITY_FLANG = "FlangOption" + +# Strings used in the commands to be tested +CLANG = "clang" +CLANG_CL = f"{CLANG} --driver-mode=cl" +CLANG_DXC = f"{CLANG} --driver-mode=dxc" +FLANG = f"{CLANG} --driver-mode=flang" +CLANG_LIT = "%clang" +CLANG_CL_LIT = "%clang_cl" +CLANG_DXC_LIT = "%clang_dxc" +FLANG_LIT = f"%{FLANG}" +OPTION_HASH = "-###" +OPTION_X = "-x" +OPTION_WX = "/WX" +OPTION_CPP = "c++" +OPTION_C = "-c" +OPTION_CC1 = "-cc1" +OPTION_CC1AS = "-cc1as" +OPTION_FC1 = "-fc1" +OPTION_SLASH_C = "/c" +OPTION_T = "/T lib_6_7" +SLASH_SLASH = "// " +EXCLAMATION = "! " + +# Invalid usage of the driver options below causes unique output, so skip testing +exceptions_sequence = [ +"cc1", +"cc1as", +] + + +class DriverController: +"""Controller for data specific to each driver +shell_cmd_prefix: The beginning string of the command to be tested +lit_cmd_prefix: The beginning string of the Lit command +visibility_str: The corresponding visibility string from OptionVisibility in Options.td +shell_cmd_suffix: Strings near the end of the command to be tested +check_string: The string or regex to be sent to FileCheck +lit_cmd_end: String at the end of the Lit command + +supported_sequence: List of UnsupportedDriverOption objects for supported options +that are Kind KIND_JOINED*, as defined in Options.td +""" + +def __init__( +self, +shell_cmd_prefix="", +lit_cmd_prefix="", +visibility_str="", +shell_cmd_suffix="", +check_string="{{(unknown argument|n?N?o such file or directory)}}", +lit_cmd_end=" - < /dev/null 2>&1 | FileCheck -check-prefix=", +): +self.shell_cmd_prefix = shell_cmd_prefix +self.lit_cmd_prefix = lit_cmd_prefix +self.visibility_str = visibility_str +self.shell_cmd_suffix = shell_cmd_suffix +self.supported_sequence = [] +self.check_string = check_string +self.lit_cmd_end = lit_cmd_end + + +class UnsupportedDriverOption: +"""Defines an unsupported driver-option combination +driver: The driver string as defined by OptionVisibility in Options.td +option: The option object from Options.td +option_name: Corresponding string for an option. See "Name" for a given option in Options.td +prefix: String that precedes the option. Ex. "-" +is_error: Boolean indicating whether the corresponding command generates an error +""" + +def __init__(self, driver, option, option_name, prefix): +self.driver = driver +self.option = option +self.option_name = option_name +self.prefix = prefix +self.is_error = True + +# For sorting +def __len__(self): +return len(self.option_name) + + +def print_usage(): +"""Print valid usage of this script""" +sys.exit("usage: python " + sys.argv[0] + " /Options.td
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
@@ -0,0 +1,626 @@ +#!/usr/bin/env python3 + +""" generate_unsupported_in_drivermode.py + +usage: python generate_unsupported_in_drivermode.py /Options.td [/llvm-tblgen] + +This script generates a Lit regression test file that validates that options +are only exposed to intended driver modes. + +The options and driver modes are parsed from Options.td, whose path should be +provided on the command line. See clang/include/clang/Driver/Options.td + +The path to the TableGen executable can optionally be provided. Otherwise, the +script will search for it. + +The primary maintenance task for this script would be updating the expected return message for a driver mode if +there are changes over time. See the instantiations of DriverController, specifically the check_string. + +Logic: +1) For each option, (records of class "Option"), and for each driver, (records of class "OptionVisibility") +a. if the option's "Visibility" field includes the driver flavour, skip processing this option for this driver +b. if the option is part of an option group, (the record has the "Group" property), + and the group's "Visibility" field includes the driver flavour, skip processing this option for this driver +c. otherwise this option is not supported by this driver flavour, and this pairing is saved for testing +2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to parse for expected output. Ex: "error: unknown argument" +""" + +import sys +import shutil +import os +import json +import subprocess +import math +from pathlib import Path + +LLVM_TABLEGEN = "llvm-tblgen" +LIT_TEST_PATH = "../test/Driver/unsupported_in_drivermode.c" +LIT_TEST_PATH_FLANG = "../test/Driver/flang/unsupported_in_flang.f90" +INCLUDE_PATH = "../../llvm/include" + +# Strings defined in Options.td for the various driver flavours. See "OptionVisibility" +VISIBILITY_CC1AS = "CC1AsOption" +VISIBILITY_CC1 = "CC1Option" +VISIBILITY_CL = "CLOption" +VISIBILITY_DXC = "DXCOption" +VISIBILITY_DEFAULT = "DefaultVis" +VISIBILITY_FC1 = "FC1Option" +VISIBILITY_FLANG = "FlangOption" + +# Strings used in the commands to be tested +CLANG = "clang" +CLANG_CL = f"{CLANG} --driver-mode=cl" +CLANG_DXC = f"{CLANG} --driver-mode=dxc" +FLANG = f"{CLANG} --driver-mode=flang" +CLANG_LIT = "%clang" +CLANG_CL_LIT = "%clang_cl" +CLANG_DXC_LIT = "%clang_dxc" +FLANG_LIT = f"%{FLANG}" +OPTION_HASH = "-###" +OPTION_X = "-x" +OPTION_WX = "/WX" +OPTION_CPP = "c++" +OPTION_C = "-c" +OPTION_CC1 = "-cc1" +OPTION_CC1AS = "-cc1as" +OPTION_FC1 = "-fc1" +OPTION_SLASH_C = "/c" +OPTION_T = "/T lib_6_7" +SLASH_SLASH = "// " +EXCLAMATION = "! " + +# Invalid usage of the driver options below causes unique output, so skip testing +exceptions_sequence = [ +"cc1", +"cc1as", +] + + +class DriverController: +"""Controller for data specific to each driver +shell_cmd_prefix: The beginning string of the command to be tested +lit_cmd_prefix: The beginning string of the Lit command +visibility_str: The corresponding visibility string from OptionVisibility in Options.td +shell_cmd_suffix: Strings near the end of the command to be tested +check_string: The string or regex to be sent to FileCheck +lit_cmd_end: String at the end of the Lit command + +supported_sequence: List of UnsupportedDriverOption objects for supported options +that are Kind KIND_JOINED*, as defined in Options.td +""" + +def __init__( +self, +shell_cmd_prefix="", +lit_cmd_prefix="", +visibility_str="", +shell_cmd_suffix="", +check_string="{{(unknown argument|n?N?o such file or directory)}}", +lit_cmd_end=" - < /dev/null 2>&1 | FileCheck -check-prefix=", +): +self.shell_cmd_prefix = shell_cmd_prefix +self.lit_cmd_prefix = lit_cmd_prefix +self.visibility_str = visibility_str +self.shell_cmd_suffix = shell_cmd_suffix +self.supported_sequence = [] +self.check_string = check_string +self.lit_cmd_end = lit_cmd_end + + +class UnsupportedDriverOption: +"""Defines an unsupported driver-option combination +driver: The driver string as defined by OptionVisibility in Options.td +option: The option object from Options.td +option_name: Corresponding string for an option. See "Name" for a given option in Options.td +prefix: String that precedes the option. Ex. "-" +is_error: Boolean indicating whether the corresponding command generates an error +""" + +def __init__(self, driver, option, option_name, prefix): +self.driver = driver +self.option = option +self.option_name = option_name +self.prefix = prefix +self.is_error = True + +# For sorting +def __len__(self): +return len(self.option_name) + + +def print_usage(): +"""Print valid usage of this script""" +sys.exit("usage: python " + sys.argv[0] + " /Options.td
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
@@ -0,0 +1,626 @@ +#!/usr/bin/env python3 + +""" generate_unsupported_in_drivermode.py + +usage: python generate_unsupported_in_drivermode.py /Options.td [/llvm-tblgen] + +This script generates a Lit regression test file that validates that options +are only exposed to intended driver modes. + +The options and driver modes are parsed from Options.td, whose path should be +provided on the command line. See clang/include/clang/Driver/Options.td + +The path to the TableGen executable can optionally be provided. Otherwise, the +script will search for it. + +The primary maintenance task for this script would be updating the expected return message for a driver mode if +there are changes over time. See the instantiations of DriverController, specifically the check_string. + +Logic: +1) For each option, (records of class "Option"), and for each driver, (records of class "OptionVisibility") +a. if the option's "Visibility" field includes the driver flavour, skip processing this option for this driver +b. if the option is part of an option group, (the record has the "Group" property), + and the group's "Visibility" field includes the driver flavour, skip processing this option for this driver +c. otherwise this option is not supported by this driver flavour, and this pairing is saved for testing +2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to parse for expected output. Ex: "error: unknown argument" +""" + +import sys +import shutil +import os +import json +import subprocess +import math +from pathlib import Path + +LLVM_TABLEGEN = "llvm-tblgen" +LIT_TEST_PATH = "../test/Driver/unsupported_in_drivermode.c" +LIT_TEST_PATH_FLANG = "../test/Driver/flang/unsupported_in_flang.f90" +INCLUDE_PATH = "../../llvm/include" + +# Strings defined in Options.td for the various driver flavours. See "OptionVisibility" +VISIBILITY_CC1AS = "CC1AsOption" +VISIBILITY_CC1 = "CC1Option" +VISIBILITY_CL = "CLOption" +VISIBILITY_DXC = "DXCOption" +VISIBILITY_DEFAULT = "DefaultVis" +VISIBILITY_FC1 = "FC1Option" +VISIBILITY_FLANG = "FlangOption" + +# Strings used in the commands to be tested +CLANG = "clang" +CLANG_CL = f"{CLANG} --driver-mode=cl" +CLANG_DXC = f"{CLANG} --driver-mode=dxc" +FLANG = f"{CLANG} --driver-mode=flang" +CLANG_LIT = "%clang" +CLANG_CL_LIT = "%clang_cl" +CLANG_DXC_LIT = "%clang_dxc" +FLANG_LIT = f"%{FLANG}" +OPTION_HASH = "-###" +OPTION_X = "-x" +OPTION_WX = "/WX" +OPTION_CPP = "c++" +OPTION_C = "-c" +OPTION_CC1 = "-cc1" +OPTION_CC1AS = "-cc1as" +OPTION_FC1 = "-fc1" +OPTION_SLASH_C = "/c" +OPTION_T = "/T lib_6_7" +SLASH_SLASH = "// " +EXCLAMATION = "! " + +# Invalid usage of the driver options below causes unique output, so skip testing +exceptions_sequence = [ +"cc1", +"cc1as", +] + + +class DriverController: +"""Controller for data specific to each driver +shell_cmd_prefix: The beginning string of the command to be tested +lit_cmd_prefix: The beginning string of the Lit command +visibility_str: The corresponding visibility string from OptionVisibility in Options.td +shell_cmd_suffix: Strings near the end of the command to be tested +check_string: The string or regex to be sent to FileCheck +lit_cmd_end: String at the end of the Lit command + +supported_sequence: List of UnsupportedDriverOption objects for supported options +that are Kind KIND_JOINED*, as defined in Options.td +""" + +def __init__( +self, +shell_cmd_prefix="", +lit_cmd_prefix="", +visibility_str="", +shell_cmd_suffix="", +check_string="{{(unknown argument|n?N?o such file or directory)}}", +lit_cmd_end=" - < /dev/null 2>&1 | FileCheck -check-prefix=", +): +self.shell_cmd_prefix = shell_cmd_prefix +self.lit_cmd_prefix = lit_cmd_prefix +self.visibility_str = visibility_str +self.shell_cmd_suffix = shell_cmd_suffix +self.supported_sequence = [] +self.check_string = check_string +self.lit_cmd_end = lit_cmd_end + + +class UnsupportedDriverOption: +"""Defines an unsupported driver-option combination +driver: The driver string as defined by OptionVisibility in Options.td +option: The option object from Options.td +option_name: Corresponding string for an option. See "Name" for a given option in Options.td +prefix: String that precedes the option. Ex. "-" +is_error: Boolean indicating whether the corresponding command generates an error +""" + +def __init__(self, driver, option, option_name, prefix): +self.driver = driver +self.option = option +self.option_name = option_name +self.prefix = prefix +self.is_error = True + +# For sorting +def __len__(self): +return len(self.option_name) + + +def print_usage(): +"""Print valid usage of this script""" +sys.exit("usage: python " + sys.argv[0] + " /Options.td
[clang] [Clang] Correctly determine constexprness of dependent lambdas. (PR #124468)
https://github.com/Sirraide approved this pull request. Makes sense. After thinking about this for a bit, I don’t think there is a reason why we’d ever need to care about the parent context at all for the purpose of determining `constexpr`ness, is there? https://github.com/llvm/llvm-project/pull/124468 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Correctly determine constexprness of dependent lambdas. (PR #124468)
https://github.com/Sirraide edited https://github.com/llvm/llvm-project/pull/124468 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Correctly determine constexprness of dependent lambdas. (PR #124468)
https://github.com/cor3ntin created https://github.com/llvm/llvm-project/pull/124468 We skipped checking if a lambda is constexpr if the parent context was dependent, even if the lambda itself wasn't (and there is no other opportunity to establish constexprness) >From bf293df31802bdfd6b5fdbdf87b142318a3ce567 Mon Sep 17 00:00:00 2001 From: Corentin Jabot Date: Sun, 26 Jan 2025 15:22:19 +0100 Subject: [PATCH] [Clang] Correctly determine constexprness of dependent lambdas. We skipped checking if a lambda is constexpr if the parent context was dependent, even if the lambda itself wasn't (and there is no other opportunity to establish constexprness) --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaLambda.cpp | 12 +- .../test/SemaCXX/cxx1z-constexpr-lambdas.cpp | 24 +++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e9fffddd507c66..6083efdea09ddb 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -991,6 +991,7 @@ Bug Fixes to C++ Support - Fixed assertions or false compiler diagnostics in the case of C++ modules for lambda functions or inline friend functions defined inside templates (#GH122493). - Clang now rejects declaring an alias template with the same name as its template parameter. (#GH123423) +- Correctly determine the implicit constexprness of dependent lambdas. (#GH97958) (#GH114234) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp index 87b3ca53cefaf2..88693dace45e95 100644 --- a/clang/lib/Sema/SemaLambda.cpp +++ b/clang/lib/Sema/SemaLambda.cpp @@ -2239,18 +2239,18 @@ ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, Cleanup.mergeFrom(LambdaCleanup); - LambdaExpr *Lambda = LambdaExpr::Create(Context, Class, IntroducerRange, - CaptureDefault, CaptureDefaultLoc, - ExplicitParams, ExplicitResultType, - CaptureInits, EndLoc, - ContainsUnexpandedParameterPack); + LambdaExpr *Lambda = + LambdaExpr::Create(Context, Class, IntroducerRange, CaptureDefault, + CaptureDefaultLoc, ExplicitParams, ExplicitResultType, + CaptureInits, EndLoc, ContainsUnexpandedParameterPack); + // If the lambda expression's call operator is not explicitly marked constexpr // and we are not in a dependent context, analyze the call operator to infer // its constexpr-ness, suppressing diagnostics while doing so. if (getLangOpts().CPlusPlus17 && !CallOperator->isInvalidDecl() && !CallOperator->isConstexpr() && !isa(CallOperator->getBody()) && - !Class->getDeclContext()->isDependentContext()) { + !Class->isDependentContext()) { CallOperator->setConstexprKind( CheckConstexprFunctionDefinition(CallOperator, CheckConstexprKind::CheckValid) diff --git a/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp b/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp index 6a1f48bf7958fd..0c20dd9dc58c63 100644 --- a/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp +++ b/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp @@ -349,3 +349,27 @@ static_assert(OtherCaptures(), ""); } // namespace PR36054 #endif // ndef CPP14_AND_EARLIER + + +#if __cpp_constexpr >= 201907L +namespace GH114234 { +template +auto g() { return Arg; } + +template +auto f() { +[]() { +g<[] { return 123; }()>(); +}.template operator()(); +} + +void test() { f(); } +} + +namespace GH97958 { +static_assert( + []() -> decltype([]{ return true; }) + { return {}; }()()); +} + +#endif ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Correctly determine constexprness of dependent lambdas. (PR #124468)
https://github.com/cor3ntin edited https://github.com/llvm/llvm-project/pull/124468 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Correctly determine constexprness of dependent lambdas. (PR #124468)
@@ -2239,18 +2239,18 @@ ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, Cleanup.mergeFrom(LambdaCleanup); - LambdaExpr *Lambda = LambdaExpr::Create(Context, Class, IntroducerRange, - CaptureDefault, CaptureDefaultLoc, - ExplicitParams, ExplicitResultType, - CaptureInits, EndLoc, - ContainsUnexpandedParameterPack); + LambdaExpr *Lambda = + LambdaExpr::Create(Context, Class, IntroducerRange, CaptureDefault, + CaptureDefaultLoc, ExplicitParams, ExplicitResultType, + CaptureInits, EndLoc, ContainsUnexpandedParameterPack); + // If the lambda expression's call operator is not explicitly marked constexpr // and we are not in a dependent context, analyze the call operator to infer // its constexpr-ness, suppressing diagnostics while doing so. Sirraide wrote: Maybe this comment needs updating now? https://github.com/llvm/llvm-project/pull/124468 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
@@ -0,0 +1,626 @@ +#!/usr/bin/env python3 + +""" generate_unsupported_in_drivermode.py + +usage: python generate_unsupported_in_drivermode.py /Options.td [/llvm-tblgen] + +This script generates a Lit regression test file that validates that options +are only exposed to intended driver modes. + +The options and driver modes are parsed from Options.td, whose path should be +provided on the command line. See clang/include/clang/Driver/Options.td + +The path to the TableGen executable can optionally be provided. Otherwise, the +script will search for it. + +The primary maintenance task for this script would be updating the expected return message for a driver mode if +there are changes over time. See the instantiations of DriverController, specifically the check_string. + +Logic: +1) For each option, (records of class "Option"), and for each driver, (records of class "OptionVisibility") +a. if the option's "Visibility" field includes the driver flavour, skip processing this option for this driver +b. if the option is part of an option group, (the record has the "Group" property), + and the group's "Visibility" field includes the driver flavour, skip processing this option for this driver +c. otherwise this option is not supported by this driver flavour, and this pairing is saved for testing +2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to parse for expected output. Ex: "error: unknown argument" +""" + +import sys +import shutil +import os +import json +import subprocess +import math +from pathlib import Path + +LLVM_TABLEGEN = "llvm-tblgen" +LIT_TEST_PATH = "../test/Driver/unsupported_in_drivermode.c" +LIT_TEST_PATH_FLANG = "../test/Driver/flang/unsupported_in_flang.f90" +INCLUDE_PATH = "../../llvm/include" + +# Strings defined in Options.td for the various driver flavours. See "OptionVisibility" +VISIBILITY_CC1AS = "CC1AsOption" +VISIBILITY_CC1 = "CC1Option" +VISIBILITY_CL = "CLOption" +VISIBILITY_DXC = "DXCOption" +VISIBILITY_DEFAULT = "DefaultVis" +VISIBILITY_FC1 = "FC1Option" +VISIBILITY_FLANG = "FlangOption" + +# Strings used in the commands to be tested +CLANG = "clang" +CLANG_CL = f"{CLANG} --driver-mode=cl" +CLANG_DXC = f"{CLANG} --driver-mode=dxc" +FLANG = f"{CLANG} --driver-mode=flang" +CLANG_LIT = "%clang" +CLANG_CL_LIT = "%clang_cl" +CLANG_DXC_LIT = "%clang_dxc" +FLANG_LIT = f"%{FLANG}" +OPTION_HASH = "-###" +OPTION_X = "-x" +OPTION_WX = "/WX" +OPTION_CPP = "c++" +OPTION_C = "-c" +OPTION_CC1 = "-cc1" +OPTION_CC1AS = "-cc1as" +OPTION_FC1 = "-fc1" +OPTION_SLASH_C = "/c" +OPTION_T = "/T lib_6_7" +SLASH_SLASH = "// " +EXCLAMATION = "! " + +# Invalid usage of the driver options below causes unique output, so skip testing +exceptions_sequence = [ +"cc1", +"cc1as", +] + + +class DriverController: +"""Controller for data specific to each driver +shell_cmd_prefix: The beginning string of the command to be tested +lit_cmd_prefix: The beginning string of the Lit command +visibility_str: The corresponding visibility string from OptionVisibility in Options.td +shell_cmd_suffix: Strings near the end of the command to be tested +check_string: The string or regex to be sent to FileCheck +lit_cmd_end: String at the end of the Lit command + +supported_sequence: List of UnsupportedDriverOption objects for supported options +that are Kind KIND_JOINED*, as defined in Options.td +""" + +def __init__( +self, +shell_cmd_prefix="", +lit_cmd_prefix="", +visibility_str="", +shell_cmd_suffix="", +check_string="{{(unknown argument|n?N?o such file or directory)}}", +lit_cmd_end=" - < /dev/null 2>&1 | FileCheck -check-prefix=", +): +self.shell_cmd_prefix = shell_cmd_prefix +self.lit_cmd_prefix = lit_cmd_prefix +self.visibility_str = visibility_str +self.shell_cmd_suffix = shell_cmd_suffix +self.supported_sequence = [] +self.check_string = check_string +self.lit_cmd_end = lit_cmd_end + + +class UnsupportedDriverOption: +"""Defines an unsupported driver-option combination +driver: The driver string as defined by OptionVisibility in Options.td +option: The option object from Options.td +option_name: Corresponding string for an option. See "Name" for a given option in Options.td +prefix: String that precedes the option. Ex. "-" +is_error: Boolean indicating whether the corresponding command generates an error +""" + +def __init__(self, driver, option, option_name, prefix): +self.driver = driver +self.option = option +self.option_name = option_name +self.prefix = prefix +self.is_error = True + +# For sorting +def __len__(self): +return len(self.option_name) + + +def print_usage(): +"""Print valid usage of this script""" +sys.exit("usage: python " + sys.argv[0] + " /Options.td
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
@@ -0,0 +1,626 @@ +#!/usr/bin/env python3 + +""" generate_unsupported_in_drivermode.py + +usage: python generate_unsupported_in_drivermode.py /Options.td [/llvm-tblgen] + +This script generates a Lit regression test file that validates that options +are only exposed to intended driver modes. + +The options and driver modes are parsed from Options.td, whose path should be +provided on the command line. See clang/include/clang/Driver/Options.td + +The path to the TableGen executable can optionally be provided. Otherwise, the +script will search for it. + +The primary maintenance task for this script would be updating the expected return message for a driver mode if +there are changes over time. See the instantiations of DriverController, specifically the check_string. + +Logic: +1) For each option, (records of class "Option"), and for each driver, (records of class "OptionVisibility") +a. if the option's "Visibility" field includes the driver flavour, skip processing this option for this driver +b. if the option is part of an option group, (the record has the "Group" property), + and the group's "Visibility" field includes the driver flavour, skip processing this option for this driver +c. otherwise this option is not supported by this driver flavour, and this pairing is saved for testing +2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to parse for expected output. Ex: "error: unknown argument" +""" + +import sys +import shutil +import os +import json +import subprocess +import math +from pathlib import Path + +LLVM_TABLEGEN = "llvm-tblgen" +LIT_TEST_PATH = "../test/Driver/unsupported_in_drivermode.c" +LIT_TEST_PATH_FLANG = "../test/Driver/flang/unsupported_in_flang.f90" +INCLUDE_PATH = "../../llvm/include" + +# Strings defined in Options.td for the various driver flavours. See "OptionVisibility" +VISIBILITY_CC1AS = "CC1AsOption" +VISIBILITY_CC1 = "CC1Option" +VISIBILITY_CL = "CLOption" +VISIBILITY_DXC = "DXCOption" +VISIBILITY_DEFAULT = "DefaultVis" +VISIBILITY_FC1 = "FC1Option" +VISIBILITY_FLANG = "FlangOption" + +# Strings used in the commands to be tested +CLANG = "clang" +CLANG_CL = f"{CLANG} --driver-mode=cl" +CLANG_DXC = f"{CLANG} --driver-mode=dxc" +FLANG = f"{CLANG} --driver-mode=flang" +CLANG_LIT = "%clang" +CLANG_CL_LIT = "%clang_cl" +CLANG_DXC_LIT = "%clang_dxc" +FLANG_LIT = f"%{FLANG}" +OPTION_HASH = "-###" +OPTION_X = "-x" +OPTION_WX = "/WX" +OPTION_CPP = "c++" +OPTION_C = "-c" +OPTION_CC1 = "-cc1" +OPTION_CC1AS = "-cc1as" +OPTION_FC1 = "-fc1" +OPTION_SLASH_C = "/c" +OPTION_T = "/T lib_6_7" +SLASH_SLASH = "// " +EXCLAMATION = "! " + +# Invalid usage of the driver options below causes unique output, so skip testing +exceptions_sequence = [ +"cc1", +"cc1as", +] + + +class DriverController: Maetveis wrote: There's no code in this class, so its not a "controller". Additionally this can just be a [dataclass](https://docs.python.org/3/library/dataclasses.html) IMO. https://github.com/llvm/llvm-project/pull/120900 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Correctly determine constexprness of dependent lambdas. (PR #124468)
https://github.com/cor3ntin updated https://github.com/llvm/llvm-project/pull/124468 >From bf293df31802bdfd6b5fdbdf87b142318a3ce567 Mon Sep 17 00:00:00 2001 From: Corentin Jabot Date: Sun, 26 Jan 2025 15:22:19 +0100 Subject: [PATCH 1/2] [Clang] Correctly determine constexprness of dependent lambdas. We skipped checking if a lambda is constexpr if the parent context was dependent, even if the lambda itself wasn't (and there is no other opportunity to establish constexprness) --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaLambda.cpp | 12 +- .../test/SemaCXX/cxx1z-constexpr-lambdas.cpp | 24 +++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e9fffddd507c66..6083efdea09ddb 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -991,6 +991,7 @@ Bug Fixes to C++ Support - Fixed assertions or false compiler diagnostics in the case of C++ modules for lambda functions or inline friend functions defined inside templates (#GH122493). - Clang now rejects declaring an alias template with the same name as its template parameter. (#GH123423) +- Correctly determine the implicit constexprness of dependent lambdas. (#GH97958) (#GH114234) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp index 87b3ca53cefaf2..88693dace45e95 100644 --- a/clang/lib/Sema/SemaLambda.cpp +++ b/clang/lib/Sema/SemaLambda.cpp @@ -2239,18 +2239,18 @@ ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, Cleanup.mergeFrom(LambdaCleanup); - LambdaExpr *Lambda = LambdaExpr::Create(Context, Class, IntroducerRange, - CaptureDefault, CaptureDefaultLoc, - ExplicitParams, ExplicitResultType, - CaptureInits, EndLoc, - ContainsUnexpandedParameterPack); + LambdaExpr *Lambda = + LambdaExpr::Create(Context, Class, IntroducerRange, CaptureDefault, + CaptureDefaultLoc, ExplicitParams, ExplicitResultType, + CaptureInits, EndLoc, ContainsUnexpandedParameterPack); + // If the lambda expression's call operator is not explicitly marked constexpr // and we are not in a dependent context, analyze the call operator to infer // its constexpr-ness, suppressing diagnostics while doing so. if (getLangOpts().CPlusPlus17 && !CallOperator->isInvalidDecl() && !CallOperator->isConstexpr() && !isa(CallOperator->getBody()) && - !Class->getDeclContext()->isDependentContext()) { + !Class->isDependentContext()) { CallOperator->setConstexprKind( CheckConstexprFunctionDefinition(CallOperator, CheckConstexprKind::CheckValid) diff --git a/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp b/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp index 6a1f48bf7958fd..0c20dd9dc58c63 100644 --- a/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp +++ b/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp @@ -349,3 +349,27 @@ static_assert(OtherCaptures(), ""); } // namespace PR36054 #endif // ndef CPP14_AND_EARLIER + + +#if __cpp_constexpr >= 201907L +namespace GH114234 { +template +auto g() { return Arg; } + +template +auto f() { +[]() { +g<[] { return 123; }()>(); +}.template operator()(); +} + +void test() { f(); } +} + +namespace GH97958 { +static_assert( + []() -> decltype([]{ return true; }) + { return {}; }()()); +} + +#endif >From c9dd183eef90dd3fd147f6a4702abaa2b8d0f4a5 Mon Sep 17 00:00:00 2001 From: Corentin Jabot Date: Sun, 26 Jan 2025 15:46:37 +0100 Subject: [PATCH 2/2] Address Sirraide's comments --- clang/docs/ReleaseNotes.rst | 2 +- clang/lib/Sema/SemaLambda.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 6083efdea09ddb..b1238db7588456 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -991,7 +991,7 @@ Bug Fixes to C++ Support - Fixed assertions or false compiler diagnostics in the case of C++ modules for lambda functions or inline friend functions defined inside templates (#GH122493). - Clang now rejects declaring an alias template with the same name as its template parameter. (#GH123423) -- Correctly determine the implicit constexprness of dependent lambdas. (#GH97958) (#GH114234) +- Correctly determine the implicit constexprness of lambdas in dependent contexts. (#GH97958) (#GH114234) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp index 88693dace45e95..ceb32ee15dfa39 100644 --- a/clang/lib/Sema/SemaLambda.cpp +++ b/clang/lib/Sema/SemaLambda.cpp @@ -22
[clang] [Clang] Correctly determine constexprness of dependent lambdas. (PR #124468)
@@ -991,6 +991,7 @@ Bug Fixes to C++ Support - Fixed assertions or false compiler diagnostics in the case of C++ modules for lambda functions or inline friend functions defined inside templates (#GH122493). - Clang now rejects declaring an alias template with the same name as its template parameter. (#GH123423) +- Correctly determine the implicit constexprness of dependent lambdas. (#GH97958) (#GH114234) Sirraide wrote: ```suggestion - Correctly determine the implicit constexprness of lambdas in dependent contexts. (#GH97958) (#GH114234) ``` Maybe this is a bit clearer because strictly speaking this is about cases where the lambda itself *isn’t* dependent. https://github.com/llvm/llvm-project/pull/124468 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add GCC's __builtin_stack_address() to Clang. (PR #121332)
aalhwc wrote: Ping https://github.com/llvm/llvm-project/pull/121332 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Correctly determine constexprness of dependent lambdas. (PR #124468)
@@ -2239,18 +2239,18 @@ ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, Cleanup.mergeFrom(LambdaCleanup); - LambdaExpr *Lambda = LambdaExpr::Create(Context, Class, IntroducerRange, - CaptureDefault, CaptureDefaultLoc, - ExplicitParams, ExplicitResultType, - CaptureInits, EndLoc, - ContainsUnexpandedParameterPack); + LambdaExpr *Lambda = + LambdaExpr::Create(Context, Class, IntroducerRange, CaptureDefault, + CaptureDefaultLoc, ExplicitParams, ExplicitResultType, + CaptureInits, EndLoc, ContainsUnexpandedParameterPack); + // If the lambda expression's call operator is not explicitly marked constexpr // and we are not in a dependent context, analyze the call operator to infer // its constexpr-ness, suppressing diagnostics while doing so. cor3ntin wrote: Indeed, thanks for catching that https://github.com/llvm/llvm-project/pull/124468 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
Maetveis wrote: > Hi @Maetveis . This is ready for review. > > There are a few things that I came across while making the script that I > should highlight : > > 1. clang -cc1 test directory > > > [test/Driver/lit.local.cfg](https://github.com/llvm/llvm-project/blob/e10d551aa482ee185a80216b2670a2947a8bdeb0/clang/test/Driver/lit.local.cfg#L27) > says, '_("%clang_cc1", """*** Do not use 'clang -cc1' in Driver tests. > ***""")_', yet I see various tests in that directory that do so, like > [linker-wrapper.c](https://github.com/llvm/llvm-project/blob/e10d551aa482ee185a80216b2670a2947a8bdeb0/clang/test/Driver/linker-wrapper.c#L10). > If there's no opposition, I'll leave the cc1 tests in the main Lit test > file, Driver/unsupported_in_drivermode.c. I think this should be fine, but we'll see if other reviewers disagree. > > 2. flang vs flang -fc1 > > > As per > [clang/test/Driver/flang/flang.f90](https://github.com/llvm/llvm-project/blob/e10d551aa482ee185a80216b2670a2947a8bdeb0/clang/test/Driver/flang/flang.f90#L1), > "flang -fc1 is invoked when in --driver-mode=flang", so I disabled the plain > flang tests since there's no distinction. I don't think that comment means that `flang` and `flang -fc1` take the same options, the test is verifying that the driver (plain `flang`) calls the backend compiler (`flang -fc1`), but the supported options are not going to be the same between these two. > I disabled the tests on Windows given the following recursion error that > occurs on Windows regression machines. I think this might be caused by the sheer amount of `RUN:` lines in the generated test, I have an idea on how to fix it, that would also make the test faster to run. I'll post it as part of the review. https://github.com/llvm/llvm-project/pull/120900 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Correctly determine constexprness of dependent lambdas. (PR #124468)
https://github.com/zyn0217 approved this pull request. Thanks https://github.com/llvm/llvm-project/pull/124468 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] only inherit the parent eval context inside of lambdas (PR #124426)
@@ -35,6 +36,12 @@ inline bool isLambdaCallOperator(const DeclContext *DC) { return isLambdaCallOperator(cast(DC)); } +inline bool isLambdaMethod(const DeclContext *DC) { + if (auto *MD = dyn_cast_or_null(DC); MD) tbaederr wrote: ```suggestion if (const auto *MD = dyn_cast_if_present(DC)) ``` https://github.com/llvm/llvm-project/pull/124426 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] e451429 - [Clang] Correctly determine constexprness of dependent lambdas. (#124468)
Author: cor3ntin Date: 2025-01-26T16:17:21+01:00 New Revision: e4514293f99962b47d881d5b40722c6b56a1f425 URL: https://github.com/llvm/llvm-project/commit/e4514293f99962b47d881d5b40722c6b56a1f425 DIFF: https://github.com/llvm/llvm-project/commit/e4514293f99962b47d881d5b40722c6b56a1f425.diff LOG: [Clang] Correctly determine constexprness of dependent lambdas. (#124468) We skipped checking if a lambda is constexpr if the parent context was dependent, even if the lambda itself wasn't (and there is no other opportunity to establish constexprness) Fixes #114234 Fixes #97958 Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaLambda.cpp clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp Removed: diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e9fffddd507c66..b1238db7588456 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -991,6 +991,7 @@ Bug Fixes to C++ Support - Fixed assertions or false compiler diagnostics in the case of C++ modules for lambda functions or inline friend functions defined inside templates (#GH122493). - Clang now rejects declaring an alias template with the same name as its template parameter. (#GH123423) +- Correctly determine the implicit constexprness of lambdas in dependent contexts. (#GH97958) (#GH114234) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp index 87b3ca53cefaf2..ceb32ee15dfa39 100644 --- a/clang/lib/Sema/SemaLambda.cpp +++ b/clang/lib/Sema/SemaLambda.cpp @@ -2239,18 +2239,18 @@ ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, Cleanup.mergeFrom(LambdaCleanup); - LambdaExpr *Lambda = LambdaExpr::Create(Context, Class, IntroducerRange, - CaptureDefault, CaptureDefaultLoc, - ExplicitParams, ExplicitResultType, - CaptureInits, EndLoc, - ContainsUnexpandedParameterPack); + LambdaExpr *Lambda = + LambdaExpr::Create(Context, Class, IntroducerRange, CaptureDefault, + CaptureDefaultLoc, ExplicitParams, ExplicitResultType, + CaptureInits, EndLoc, ContainsUnexpandedParameterPack); + // If the lambda expression's call operator is not explicitly marked constexpr - // and we are not in a dependent context, analyze the call operator to infer + // and is not dependent, analyze the call operator to infer // its constexpr-ness, suppressing diagnostics while doing so. if (getLangOpts().CPlusPlus17 && !CallOperator->isInvalidDecl() && !CallOperator->isConstexpr() && !isa(CallOperator->getBody()) && - !Class->getDeclContext()->isDependentContext()) { + !Class->isDependentContext()) { CallOperator->setConstexprKind( CheckConstexprFunctionDefinition(CallOperator, CheckConstexprKind::CheckValid) diff --git a/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp b/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp index 6a1f48bf7958fd..0c20dd9dc58c63 100644 --- a/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp +++ b/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp @@ -349,3 +349,27 @@ static_assert(OtherCaptures(), ""); } // namespace PR36054 #endif // ndef CPP14_AND_EARLIER + + +#if __cpp_constexpr >= 201907L +namespace GH114234 { +template +auto g() { return Arg; } + +template +auto f() { +[]() { +g<[] { return 123; }()>(); +}.template operator()(); +} + +void test() { f(); } +} + +namespace GH97958 { +static_assert( + []() -> decltype([]{ return true; }) + { return {}; }()()); +} + +#endif ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add dump() support for lvalue APValues (PR #124476)
Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/124476 >From 89b0e78879578fb740948badca141cf6acb21357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sun, 26 Jan 2025 19:17:28 +0100 Subject: [PATCH 1/2] [clang] Add dump() support for lvalue APValues Add some lvalue information to the `dump()` output of lvalue APValues. --- clang/lib/AST/TextNodeDumper.cpp | 33 +- clang/test/AST/ast-dump-APValue-lvalue.cpp | 50 ++ clang/test/AST/ast-dump-APValue-todo.cpp | 4 -- 3 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 clang/test/AST/ast-dump-APValue-lvalue.cpp diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp index 670641242cae2f..7ff758d5f78a13 100644 --- a/clang/lib/AST/TextNodeDumper.cpp +++ b/clang/lib/AST/TextNodeDumper.cpp @@ -710,10 +710,39 @@ void TextNodeDumper::Visit(const APValue &Value, QualType Ty) { << GetApproxValue(Value.getComplexFloatImag()) << 'i'; } return; - case APValue::LValue: + case APValue::LValue: { (void)Context; -OS << "LValue "; +OS << "LValue Base="; +APValue::LValueBase B = Value.getLValueBase(); +if (B.isNull()) + OS << "null"; +else if (const auto *BE = B.dyn_cast()) { + OS << BE->getStmtClassName() << ' '; + dumpPointer(BE); +} else { + const auto *VDB = B.get(); + OS << VDB->getDeclKindName() << "Decl"; + dumpPointer(VDB); +} +OS << ", Null=" << Value.isNullPointer() + << ", Offset=" << Value.getLValueOffset().getQuantity() + << ", HasPath=" << Value.hasLValuePath(); +if (Value.hasLValuePath()) { + OS << ", PathLength=" << Value.getLValuePath().size(); + OS << ", Path=("; + bool First = true; + for (const auto &PathEntry : Value.getLValuePath()) { +// We're printing all entries as array indices because don't have the +// type information here to do anything else. +OS << PathEntry.getAsArrayIndex(); +if (First && Value.getLValuePath().size() > 1) + OS << ", "; +First = false; + } + OS << ")"; +} return; + } case APValue::Array: { unsigned ArraySize = Value.getArraySize(); unsigned NumInitializedElements = Value.getArrayInitializedElts(); diff --git a/clang/test/AST/ast-dump-APValue-lvalue.cpp b/clang/test/AST/ast-dump-APValue-lvalue.cpp new file mode 100644 index 00..d2efbc201406bd --- /dev/null +++ b/clang/test/AST/ast-dump-APValue-lvalue.cpp @@ -0,0 +1,50 @@ +// Test without serialization: +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value -std=gnu++17 \ +// RUN:-ast-dump %s -ast-dump-filter Test \ +// RUN: | FileCheck --strict-whitespace --match-full-lines %s +// +// Test with serialization: +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value -std=gnu++17 -emit-pch -o %t %s +// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -Wno-unused-value -std=gnu++17 \ +// RUN: -include-pch %t -ast-dump-all -ast-dump-filter Test /dev/null \ +// RUN: | sed -e "s/ //" -e "s/ imported//" \ +// RUN: | FileCheck --strict-whitespace --match-full-lines %s + +int i; +struct S { + int i; + int ii; +}; +S s; + +struct F { + char padding[12]; + S s; +}; +F f; + +void Test() { + constexpr int *pi = &i; + // CHECK: | `-VarDecl {{.*}} col:{{.*}} pi 'int *const' constexpr cinit + // CHECK-NEXT: | |-value: LValue Base=VarDecl {{.*}}, Null=0, Offset=0, HasPath=1, PathLength=0, Path=() + + constexpr int *psi = &s.i; + // CHECK: | `-VarDecl {{.*}} col:{{.*}} psi 'int *const' constexpr cinit + // CHECK-NEXT: | |-value: LValue Base=VarDecl {{.*}}, Null=0, Offset=0, HasPath=1, PathLength=1, Path=({{.*}}) + + constexpr int *psii = &s.ii; + // CHECK: | `-VarDecl {{.*}} col:{{.*}} psii 'int *const' constexpr cinit + // CHECK-NEXT: | |-value: LValue Base=VarDecl {{.*}}, Null=0, Offset=4, HasPath=1, PathLength=1, Path=({{.*}}) + + constexpr int *pf = &f.s.ii; + // CHECK: | `-VarDecl {{.*}} col:{{.*}} pf 'int *const' constexpr cinit + // CHECK-NEXT: | |-value: LValue Base=VarDecl {{.*}}, Null=0, Offset=12, HasPath=1, PathLength=2, Path=({{.*}}, {{.*}}) + + constexpr char *pc = &f.padding[2]; + // CHECK: | `-VarDecl {{.*}} col:{{.*}} pf 'char *const' constexpr cinit + // CHECK-NEXT: | |-value: LValue Base=VarDecl {{.*}}, Null=0, Offset=2, HasPath=1, PathLength=2, Path=({{.*}}, 2) + + constexpr const int *n = nullptr; + // CHECK:`-VarDecl {{.*}} col:{{.*}} n 'const int *const' constexpr cinit + // CHECK-NEXT: |-value: LValue Base=null, Null=1, Offset=0, HasPath=1, PathLength=0, Path=() +} diff --git a/clang/test/AST/ast-dump-APValue-todo.cpp b/clang/test/AST/ast-dump-APValue-todo.cpp index 78cc9cf36c73c1..acaa82ba53b6fd 100644 --- a/clang/test/AST/ast-dump-APValue-t
[clang] [clang] Fix ASTWriter crash after merging named enums (PR #114240)
https://github.com/michael-jabbour-sonarsource updated https://github.com/llvm/llvm-project/pull/114240 >From cc3cf25da67c9f8b9edabb318c6011cad9bd2f58 Mon Sep 17 00:00:00 2001 From: Michael Jabbour Date: Tue, 29 Oct 2024 11:16:09 +0100 Subject: [PATCH 1/8] [NFC] Factor out RetireNodesFromMergedDecl --- clang/include/clang/Sema/Sema.h | 6 ++ clang/lib/Sema/SemaDecl.cpp | 27 +++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 93d98e1cbb9c81..70bbb882eb2b13 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -4034,6 +4034,12 @@ class Sema final : public SemaBase { void MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New, LookupResult &OldDecls); + /// RetireNodesFromMergedDecl - We have just merged the decl 'New' by making + /// another definition visible. + /// This method performs any necessary cleanup on the parser state to discard + /// child nodes from newly parsed decl we are retiring. + void RetireNodesFromMergedDecl(Scope *S, Decl *New); + /// MergeFunctionDecl - We just parsed a function 'New' from /// declarator D which has the same name and scope as a previous /// declaration 'Old'. Figure out how to resolve this situation, diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index f8e5f3c6d309d6..54c4c5f4e5395e 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -2551,18 +2551,7 @@ void Sema::MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New, // Make the old tag definition visible. makeMergedDefinitionVisible(Hidden); - // If this was an unscoped enumeration, yank all of its enumerators - // out of the scope. - if (isa(NewTag)) { -Scope *EnumScope = getNonFieldDeclScope(S); -for (auto *D : NewTag->decls()) { - auto *ED = cast(D); - assert(EnumScope->isDeclScope(ED)); - EnumScope->RemoveDecl(ED); - IdResolver.RemoveDecl(ED); - ED->getLexicalDeclContext()->removeDecl(ED); -} - } + RetireNodesFromMergedDecl(S, NewTag); } } @@ -2639,6 +2628,20 @@ void Sema::MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New, notePreviousDefinition(Old, New->getLocation()); } +void Sema::RetireNodesFromMergedDecl(Scope *S, Decl *New) { + // If this was an unscoped enumeration, yank all of its enumerators + // out of the scope. + if (auto *ED = dyn_cast(New); ED) { +Scope *EnumScope = getNonFieldDeclScope(S); +for (auto *ECD : ED->enumerators()) { + assert(EnumScope->isDeclScope(ECD)); + EnumScope->RemoveDecl(ECD); + IdResolver.RemoveDecl(ECD); + ECD->getLexicalDeclContext()->removeDecl(ECD); +} + } +} + /// DeclhasAttr - returns true if decl Declaration already has the target /// attribute. static bool DeclHasAttr(const Decl *D, const Attr *A) { >From f07904ae5468658a3e7e4a649cd183734479d6cc Mon Sep 17 00:00:00 2001 From: Michael Jabbour Date: Tue, 29 Oct 2024 12:07:29 +0100 Subject: [PATCH 2/8] Drop enumerators when merging named enums This fixes a crash in ASTWriter when the stale IdResolver entries are used when writing the identifier table. assert(DeclIDs.contains(D) && "Declaration not emitted!"); --- clang/include/clang/Sema/Sema.h | 2 +- clang/lib/Parse/ParseDecl.cpp | 2 +- clang/lib/Parse/ParseDeclCXX.cpp| 3 +- clang/lib/Sema/SemaDecl.cpp | 6 ++- clang/test/Modules/modules-merge-enum.m | 52 + 5 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 clang/test/Modules/modules-merge-enum.m diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 70bbb882eb2b13..d53bcf63dd1bd9 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -3910,7 +3910,7 @@ class Sema final : public SemaBase { /// Perform ODR-like check for C/ObjC when merging tag types from modules. /// Differently from C++, actually parse the body and reject / error out /// in case of a structural mismatch. - bool ActOnDuplicateDefinition(Decl *Prev, SkipBodyInfo &SkipBody); + bool ActOnDuplicateDefinition(Scope *S, Decl *Prev, SkipBodyInfo &SkipBody); typedef void *SkippedDefinitionContext; diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 31984453487aef..750301a9155d79 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -5645,7 +5645,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS, Decl *D = SkipBody.CheckSameAsPrevious ? SkipBody.New : TagDecl; ParseEnumBody(StartLoc, D); if (SkipBody.CheckSameAsPrevious && -!Actions.ActOnDuplicateDefinition(TagDecl, SkipBody)) { +!Actions.ActOnDuplicateDefinition(getCurScope(), TagDecl, SkipBody)) { DS.SetT
[clang] [clang] Fix ASTWriter crash after merging named enums (PR #114240)
michael-jabbour-sonarsource wrote: @vsapsai Thanks again for the feedback :pray: > I've realized that the test doesn't have to be Objective-C, the failure is > reproducible in C. Curiously, we aren't hitting the assertion in > C++/Objective-C++ but I don't know why. I dug a bit into this today, and I could find a few differences: 1. ODR checks seem to be implemented on C and ObjC only (see df0ee34bc2523f11b907311670c776cb3de108c1). As far as I understand, in the C++ case, `Sema::ActOnTag` sets [`SkipBody.ShouldSkip` to true](https://github.com/llvm/llvm-project/blob/cd708029e0b2869e80abe31ddb175f7c35361f90/clang/lib/Sema/SemaDecl.cpp#L17616), causing `ParseEnumSpecifier` to [skip the body and return early](https://github.com/llvm/llvm-project/blob/cd708029e0b2869e80abe31ddb175f7c35361f90/clang/lib/Parse/ParseDecl.cpp#L5553-L5561) before it would otherwise [call `ParseEnumBody`](https://github.com/llvm/llvm-project/blob/cd708029e0b2869e80abe31ddb175f7c35361f90/clang/lib/Parse/ParseDecl.cpp#L5603) and create the `EnumDeclConstant` AST node (that we need to clean up in the C/Objective-C case). 2. Another difference, which doesn't seem to contribute directly to the divergence in this specific case, is that in C++, `ASTReader` pre-loads a set of interesting identifiers, see 33e0f7ef94124a53404555879666cef0e370f8c2. > I wanted to try defining the enums in different scopes (e.g. in a struct) and > see how it works. Consequences for scopes aren't clear, so that's worth > taking another look. I added one more test case for this. I got the same stack trace, and the crash seems to be fixed after the PR as well. However, I couldn’t reproduce the stack trace with `WriteCUDAPragmas`, so I might be missing something. See the scoped example [on CE](https://godbolt.org/#z:OYLghAFBqd5QCxAFwE4FN0BoCWIIDGAtgIYDW6AgqsAM4gDkAtACIDCAspQNICiA%2BgCEAqgEkAMi34AVAJoAFXgFIAzCxboARgFdgDLAQD2RAA44ANulTiSAO2DaSwdKIAmIAkoBMg74IPatMjGAPLayCbhAGIW6LYkROgo6EFYAGax9LDorjjBqG4gXumxhSollvGJILQIJBiuAHQIWKAM%2Bji0orYE5tquOYwADB20HCQ4tgDKhtqoBEkMAIyjISZxw/rmdsCF7QCUWBA5eYYF7uUZloUALBVxCUnoAB4JJpaNBCYmrYyj3b1%2BoMGCNcGMJtNZvNFqDOmsNiCtjs9gxDsdcvlCkt7oUAGz3KpJIiGVzaD7E1ykH5tf49PoDdyIsHjSYzOYLRgrMHw2ybLDbeyFTw%2BPxok6Y9x3K4udwAdgJjxAHBJlBiliWzV%2B7TBAPpwNh4NZUI5y1W615TIFu3cwt8PjFGLOhQArDj3AAOBXVZWuVWxLyamk6ulAxkGlmQ9mLLlw818q1Cvyio7ip3ufHSwoATi9SR9gjV6EDf2DgIZfM6EbZ0M5ZoRoITNqT9sOnU45HQ8lQhgAVugCMha1geyBsbZ0AB3QtYoaHcyMZ36C2gwyMaQYdAAam8Ki5g8RaKQRgGvEdqFw%2BGlhJqxqLCG%2B6UMtmQUwIJEso6lT%2BQwloneefIjsUVoeM2/gmHY6AAHKKrU9Q5Jqf6WAOOBPvgcSuGwhh9EQvIqHcGHiJM0HaEQmhWEUWAmIYtB5KhthYTheF3NRtHIPRRHjlBpHkaglFIf27FPlMyD1MgjGkcxWACShwmiagyCcSRZEUcUQRiRJuEgPh0nyYpxHcSpfFeIctC3owQSoNoA6bhwACeIlWTZSiyr4QyUJum5xKRtl2bwtikc626ub5ABq778CwwVRTE6DmK4qhuZQLksIlqL8guS58qucENJq%2B4jIeHgkugp6nOeeAQFeiqkJMnwPmk36vu%2BSRLF%2Bz6/v%2BgHafyOygSKPhUZBMHVC8bwfF8PwyUJvLHLYmHYZJo5YIRBk8RRLE0XRT6aby2KsdtthKYZvEgHc030SJGmLVp2IXXJYnHetfHnXpu3LepClPUZZ2meZDA7pMZZbt4Xj5oWzSg0o7nQ5QkzIJutW2BA%2BzBYIm4YMgcy2GFEWpSo6MpbD6Xzgwi5YMu%2BirmNpgTQ%2BBXpRAR4lWV%2BQXlVsTXqaj7Ps1H5tTzP5/vIAFMiO2IgbafhDVxNUkmSRYUlS0lxYJ9HofN73YqtXHPaO%2BIHTNWtUVtM3fadSz4vd0xvTde0q8hM1XV9a0/ZbunXUxH16ebFGW39UaMBSCu2SqaOw55weWKHvqFks4fuZ5nkIOgJADKg25eGDKpx5DWcR0nLzUQpm4AFQF0TieI/L0c%2Bn6lheAnHlJynadWJn2ex/6edeAXnlF2cCPl1XlfJbKqUw%2B5UdbvmTfJ6n6cd%2BDsQ9wXA8l8PY8T5QJOZRT2UgNPjRKyQPwM0Vx6lWe7PVdU3ONbzb78%2B1QtdWLZ29fY/V2uBw2KnXucWjWw1gtL22t5q%2B2MibNi9FjaGw4q7U6alVayRtp7Jad0UFOx9og1SHsFLG0%2BvpXWP0TLSX%2BoDEMAwO65QQggKG7ld5kyykyVcADYgahaOfI4zMTzX0qrfaM%2BgH4vifq1F%2BnURbdVdJLMCMtoL/xzt3IBWD1ZzVARglaEDcFQPgTtO2y09FHR0fxVRD0CEGMwY7S6OCSFIPweJSxDjIFFADjWBgAB6Dxm5eCmGQHZTc0piZzj3pTLAbClEN3ypsC%2BLN%2BGXk5oqe%2BTUxGfkFpI0WoIRz4lkQNX%2BstvQkgLCvFR1i0LqONjrZSp1XRGLgabBBdiKKumts7RxYCHZq3McQ6pzSHGENsb0vizo3Emi8THYp0cBjmlcLQTcT4Y713QAGBA8zbDmDso0WGlDgZL0ics1e7lxm6n6JMYAm5aFNFWSnDAm43yBBSJuKY6BSCbmCIjKwzg3kp03JQKY0hNy2BKnMtI3YiAXLqHlVZE48irOQD8hAOBXADBxk%2BR5oLjCLK2TDLwKggZ6hoZCuhDCd4hOYfvVhSoikQy4TEw4rd074EOGQEAzohgZQYDcfQRBRxDHZWE1c2p6DYm4XAWAMBEDFVMLECq%2BAjDSssHxXoOx%2BAkFoH%2BBS9FaD8DQNoWwZAKjICsPQCAmg%2BSaEmPUOyQ4LXxFQHZEImg%2BwDiHPKxIz4QjrOtUyAYOhgBsHfOYeg3MBikHsB%2BH1OAMAoQAG4pD5C8fs4QhG4GfHFeMOBNCoCtVhAYfI0A4B5dzONqBNA0XQBoMNwBzBnJiekbYdBQo4EnDyIcIi%2BbiPScLTJ%2Bhxaf1AFLQaNbNBZBRuEkwM1g1MGeHczcTA0jTzmfO6eTAqTztiKoFgR8T4mDnWkWgdlnwkGeEwJ8GyqYltQEi%2BNkBTJmNmhhd6NxXRVJOhRcodSDHPugYdFx5RWm2y9t%2BgDj0TH/sA0tYDgy318RUIcNAmBRxkvJgKxgm5njulxEwXENw7lWk3BANVGrJ1vKsvq1GEB1yYEzrufY%2Bhz70oXhRMdpMuVYB5Sod0jRcWylxLKJYspMPOndEMG4KhXSoaFSAdloqJVMxALMCI4R2byrMIqkaiwMNYZw3hnYm4lhZkaBqUE7bUkCxERk7qIqNxIuWhObNJhazIZYSuRgYQlMI0MGkdDmHsO4eVfYAjRGrAkd1eRgjWEFXtx3EsOjWAGMcrYzy3EGpeO4q8O6LwSx8IGedPiST%2Bh6AybpVgFlbKOUqBc1TEsCXSZeCq%2BEmrJWS20TQjcIAA%3D). https://github.com/llvm/llvm-project/pull/114240 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [StaticAnalyzer] Fix state update in VisitObjCForCollectionStmt (PR #124477)
https://github.com/ziqingluo-90 unassigned https://github.com/llvm/llvm-project/pull/124477 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix createConstexprUnknownAPValues to use zero offset when ceating APValue (PR #124478)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `flang-aarch64-dylib` running on `linaro-flang-aarch64-dylib` while building `clang` at step 5 "build-unified-tree". Full details are available at: https://lab.llvm.org/buildbot/#/builders/50/builds/9430 Here is the relevant piece of the build log for the reference ``` Step 5 (build-unified-tree) failure: build (failure) ... 420.886 [2030/1/4791] Building CXX object tools/mlir/lib/Dialect/Linalg/Transforms/CMakeFiles/obj.MLIRLinalgTransforms.dir/BubbleUpExtractSlice.cpp.o 421.021 [2029/1/4792] Building CXX object tools/mlir/lib/Conversion/FuncToSPIRV/CMakeFiles/obj.MLIRFuncToSPIRV.dir/FuncToSPIRVPass.cpp.o 421.136 [2028/1/4793] Building CXX object tools/mlir/lib/Dialect/Transform/Transforms/CMakeFiles/obj.MLIRTransformDialectTransforms.dir/CheckUses.cpp.o 421.257 [2027/1/4794] Building CXX object tools/mlir/lib/CAPI/IR/CMakeFiles/obj.MLIRCAPIIR.dir/AffineMap.cpp.o 421.493 [2026/1/4795] Building CXX object tools/mlir/lib/CAPI/IR/CMakeFiles/obj.MLIRCAPIIR.dir/BuiltinAttributes.cpp.o 421.677 [2025/1/4796] Building CXX object tools/mlir/lib/CAPI/Transforms/CMakeFiles/obj.MLIRCAPITransforms.dir/Rewrite.cpp.o 421.829 [2024/1/4797] Building CXX object tools/mlir/test/lib/Conversion/VectorToSPIRV/CMakeFiles/MLIRTestVectorToSPIRV.dir/TestVectorReductionToSPIRVDotProd.cpp.o 421.898 [2023/1/4798] Building CXX object tools/mlir/tools/mlir-parser-fuzzer/bytecode/CMakeFiles/mlir-bytecode-parser-fuzzer.dir/DummyParserFuzzer.cpp.o 422.041 [2022/1/4799] Building CXX object tools/mlir/test/lib/IR/CMakeFiles/MLIRTestIR.dir/TestVisitors.cpp.o 435.074 [2021/1/4800] Building CXX object tools/mlir/test/lib/IR/CMakeFiles/MLIRTestIR.dir/TestVisitorsGeneric.cpp.o FAILED: tools/mlir/test/lib/IR/CMakeFiles/MLIRTestIR.dir/TestVisitorsGeneric.cpp.o /usr/local/bin/c++ -DGTEST_HAS_RTTI=0 -DMLIR_INCLUDE_TESTS -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/tcwg-buildbot/worker/flang-aarch64-dylib/build/tools/mlir/test/lib/IR -I/home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/mlir/test/lib/IR -I/home/tcwg-buildbot/worker/flang-aarch64-dylib/build/tools/mlir/include -I/home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/mlir/include -I/home/tcwg-buildbot/worker/flang-aarch64-dylib/build/include -I/home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/llvm/include -I/home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/mlir/test/lib/IR/../Dialect/Test -I/home/tcwg-buildbot/worker/flang-aarch64-dylib/build/tools/mlir/test/lib/IR/../Dialect/Test -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wundef -Werror=mismatched-tags -O3 -DNDEBUG -std=c++17 -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT tools/mlir/test/lib/IR/CMakeFiles/MLIRTestIR.dir/TestVisitorsGeneric.cpp.o -MF tools/mlir/test/lib/IR/CMakeFiles/MLIRTestIR.dir/TestVisitorsGeneric.cpp.o.d -o tools/mlir/test/lib/IR/CMakeFiles/MLIRTestIR.dir/TestVisitorsGeneric.cpp.o -c /home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/mlir/test/lib/IR/TestVisitorsGeneric.cpp In file included from /home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/mlir/test/lib/IR/TestVisitorsGeneric.cpp:9: /home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/mlir/test/lib/IR/../Dialect/Test/TestOps.h:148:10: fatal error: 'TestOps.h.inc' file not found 148 | #include "TestOps.h.inc" | ^~~ 1 error generated. ninja: build stopped: subcommand failed. ``` https://github.com/llvm/llvm-project/pull/124478 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix createConstexprUnknownAPValues to use zero offset when ceating APValue (PR #124478)
https://github.com/shafik closed https://github.com/llvm/llvm-project/pull/124478 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] c9637af - [Clang] Fix createConstexprUnknownAPValues to use zero offset when ceating APValue (#124478)
Author: Shafik Yaghmour Date: 2025-01-26T15:06:26-08:00 New Revision: c9637afec7ed72904c74c2fc71e990d378f3d7a6 URL: https://github.com/llvm/llvm-project/commit/c9637afec7ed72904c74c2fc71e990d378f3d7a6 DIFF: https://github.com/llvm/llvm-project/commit/c9637afec7ed72904c74c2fc71e990d378f3d7a6.diff LOG: [Clang] Fix createConstexprUnknownAPValues to use zero offset when ceating APValue (#124478) When implmenting P2280R4 here: https://github.com/llvm/llvm-project/pull/95474 When creating the APValue to store and constexprUnknown value I used an offset of CharUnits::One() but it should have been CharUnits::Zero(). This change just adjusts that value. Added: Modified: clang/lib/AST/ExprConstant.cpp Removed: diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 3b5ab839c6cf79..be8f1fe02e7212 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -1961,7 +1961,7 @@ APValue & CallStackFrame::createConstexprUnknownAPValues(const VarDecl *Key, APValue::LValueBase Base) { APValue &Result = ConstexprUnknownAPValues[MapKeyTy(Key, Base.getVersion())]; - Result = APValue(Base, CharUnits::One(), APValue::ConstexprUnknown{}); + Result = APValue(Base, CharUnits::Zero(), APValue::ConstexprUnknown{}); return Result; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix createConstexprUnknownAPValues to use zero offset when ceating APValue (PR #124478)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `openmp-offload-libc-amdgpu-runtime` running on `omp-vega20-1` while building `clang` at step 7 "Add check check-offload". Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/12455 Here is the relevant piece of the build log for the reference ``` Step 7 (Add check check-offload) failure: test (failure) TEST 'libomptarget :: amdgcn-amd-amdhsa :: offloading/host_as_target.c' FAILED Exit Code: 2 Command Output (stdout): -- # RUN: at line 8 /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang -fopenmp-I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -nogpulib -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib -fopenmp-targets=amdgcn-amd-amdhsa /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/offloading/host_as_target.c -o /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/host_as_target.c.tmp -Xoffload-linker -lc -Xoffload-linker -lm /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a && /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/host_as_target.c.tmp | /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/FileCheck /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/offloading/host_as_target.c # executed command: /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang -fopenmp -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -nogpulib -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib -fopenmp-targets=amdgcn-amd-amdhsa /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/offloading/host_as_target.c -o /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/host_as_target.c.tmp -Xoffload-linker -lc -Xoffload-linker -lm /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a # executed command: /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/host_as_target.c.tmp # note: command had no output on stdout or stderr # error: command failed with exit status: -11 # executed command: /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/FileCheck /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/offloading/host_as_target.c # .---command stderr # | FileCheck error: '' is empty. # | FileCheck command line: /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/FileCheck /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/offloading/host_as_target.c # `- # error: command failed with exit status: 2 -- ``` https://github.com/llvm/llvm-project/pull/124478 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix createConstexprUnknownAPValues to use zero offset when ceating APValue (PR #124478)
shafik wrote: First failure looks like a flaky build issue: https://github.com/llvm/llvm-project/issues/124485 https://github.com/llvm/llvm-project/pull/124478 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)
@@ -649,15 +649,15 @@ namespace cwg241 { // cwg241: 9 A::g<3>(b); C::f<3>(b); // expected-error@-1 {{no matching function for call to 'f'}} -// expected-note@#cwg241-C-f {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T'}} +// expected-note@#cwg241-C-f {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T': could not convert '3' from 'int' to class 'T' (expected a class, but got '3')}} Endilll wrote: Parentheses can be omitted in my suggestion, but the intent is to hammer on type parameter vs value argument mismatch. https://github.com/llvm/llvm-project/pull/122754 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Plumb through -fsanitize-skip-hot-cutoff to LowerAllowCheckPass (PR #124211)
@@ -828,11 +828,34 @@ parseLowerAllowCheckPassOptions(StringRef Params) { StringRef ParamName; std::tie(ParamName, Params) = Params.split(';'); -return make_error( -formatv("invalid LowerAllowCheck pass parameter '{0}' ", ParamName) -.str(), -inconvertibleErrorCode()); +// cutoffs=99|99|0|...10 +if (ParamName.starts_with("cutoffs=")) { + StringRef CutoffsStr; + std::tie(ParamName, CutoffsStr) = ParamName.split('='); + + while (CutoffsStr != "") { +StringRef firstCutoffStr; +std::tie(firstCutoffStr, CutoffsStr) = CutoffsStr.split('|'); vitalybuka wrote: Can this be `,`? https://github.com/llvm/llvm-project/pull/124211 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)
https://github.com/Endilll edited https://github.com/llvm/llvm-project/pull/122754 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Plumb through -fsanitize-skip-hot-cutoff to LowerAllowCheckPass (PR #124211)
https://github.com/vitalybuka edited https://github.com/llvm/llvm-project/pull/124211 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Plumb through -fsanitize-skip-hot-cutoff to LowerAllowCheckPass (PR #124211)
@@ -71,7 +72,8 @@ static void emitRemark(IntrinsicInst *II, OptimizationRemarkEmitter &ORE, static bool removeUbsanTraps(Function &F, const BlockFrequencyInfo &BFI, const ProfileSummaryInfo *PSI, - OptimizationRemarkEmitter &ORE) { + OptimizationRemarkEmitter &ORE, + std::vector &cutoffs) { vitalybuka wrote: const& ? https://github.com/llvm/llvm-project/pull/124211 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Plumb through -fsanitize-skip-hot-cutoff to LowerAllowCheckPass (PR #124211)
@@ -108,14 +108,17 @@ static Value *getBoundsCheckCond(Value *Ptr, Value *InstVal, return Or; } -static CallInst *InsertTrap(BuilderTy &IRB, bool DebugTrapBB) { +static CallInst *InsertTrap(BuilderTy &IRB, bool DebugTrapBB, vitalybuka wrote: Changes in this file look unrelated, can you please extract into a separate PR? https://github.com/llvm/llvm-project/pull/124211 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Plumb through -fsanitize-skip-hot-cutoff to LowerAllowCheckPass (PR #124211)
https://github.com/vitalybuka edited https://github.com/llvm/llvm-project/pull/124211 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Plumb through -fsanitize-skip-hot-cutoff to LowerAllowCheckPass (PR #124211)
@@ -81,21 +83,20 @@ static bool removeUbsanTraps(Function &F, const BlockFrequencyInfo &BFI, return *Rng; }; - auto ShouldRemoveHot = [&](const BasicBlock &BB) { -return HotPercentileCutoff.getNumOccurrences() && PSI && - PSI->isHotCountNthPercentile( - HotPercentileCutoff, BFI.getBlockProfileCount(&BB).value_or(0)); + auto ShouldRemoveHot = [&](const BasicBlock &BB, const unsigned int &cutoff) { vitalybuka wrote: `unsigned int cutoff` https://github.com/llvm/llvm-project/pull/124211 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Plumb through -fsanitize-skip-hot-cutoff to LowerAllowCheckPass (PR #124211)
@@ -81,21 +83,20 @@ static bool removeUbsanTraps(Function &F, const BlockFrequencyInfo &BFI, return *Rng; }; - auto ShouldRemoveHot = [&](const BasicBlock &BB) { -return HotPercentileCutoff.getNumOccurrences() && PSI && - PSI->isHotCountNthPercentile( - HotPercentileCutoff, BFI.getBlockProfileCount(&BB).value_or(0)); + auto ShouldRemoveHot = [&](const BasicBlock &BB, const unsigned int &cutoff) { +return PSI && PSI->isHotCountNthPercentile( + cutoff, BFI.getBlockProfileCount(&BB).value_or(0)); }; auto ShouldRemoveRandom = [&]() { return RandomRate.getNumOccurrences() && !std::bernoulli_distribution(RandomRate)(GetRng()); }; - auto ShouldRemove = [&](const BasicBlock &BB) { -return ShouldRemoveRandom() || ShouldRemoveHot(BB); - }; - + // In some cases, EmitCheck was called with multiple checks (e.g., vitalybuka wrote: We know nothing about multiple Kind here. This comment is irrelevant. https://github.com/llvm/llvm-project/pull/124211 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libcxxabi] [llvm] [Clang] Mangling of pack indexing type and expression for itanium (PR #123513)
https://github.com/zyn0217 commented: Hmm, I'm unfamiliar with the libcxx/LLVM demangler part, but it does look like we're duplicating something. Can anyone explain why we have to do that? https://github.com/llvm/llvm-project/pull/123513 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libcxxabi] [llvm] [Clang] Mangling of pack indexing type and expression for itanium (PR #123513)
@@ -1003,6 +1003,7 @@ Bug Fixes to C++ Support lambda functions or inline friend functions defined inside templates (#GH122493). - Clang now rejects declaring an alias template with the same name as its template parameter. (#GH123423) - Correctly determine the implicit constexprness of lambdas in dependent contexts. (#GH97958) (#GH114234) +- Implement Itanium mangling for pack indexing. (#GH112003) zyn0217 wrote: I think it should live in `C++2c support` section, as this isn't strictly a bug. https://github.com/llvm/llvm-project/pull/123513 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libcxxabi] [llvm] [Clang] Mangling of pack indexing type and expression for itanium (PR #123513)
@@ -4787,6 +4788,7 @@ void CXXNameMangler::mangleRequirement(SourceLocation RequiresExprLoc, void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity, bool AsTemplateArg) { + // clang-format off zyn0217 wrote: nit: Why turning it off? https://github.com/llvm/llvm-project/pull/123513 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libcxxabi] [llvm] [Clang] Mangling of pack indexing type and expression for itanium (PR #123513)
@@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-linux-gnu -std=c++2a | FileCheck %s + +namespace spaceship { + struct X {}; + struct Y {}; + int operator<=>(X, Y); + + // CHECK-LABEL: define {{.*}} @_ZN9spaceship1fIiEEvDTcmltcvNS_1YE_EcvNS_1XE_EcvT__EE + template void f(decltype(Y() < X(), T()) x) {} + template void f(int); +} zyn0217 wrote: This isn't related to what this patch proposes or am I missing something? https://github.com/llvm/llvm-project/pull/123513 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libcxxabi] [llvm] [Clang] Mangling of pack indexing type and expression for itanium (PR #123513)
https://github.com/zyn0217 edited https://github.com/llvm/llvm-project/pull/123513 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Treat uppercase identifiers after struct as macros (PR #124397)
https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/124397 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Support BraceWrapping.AfterNamespace with AllowShortNamespacesOnASingleLine (PR #123010)
owenca wrote: Please fix the warning: ``` clang/lib/Format/UnwrappedLineFormatter.cpp:681:31: warning: comparison of integers of different signs: 'typename iterator_traits::difference_type' (aka 'long') and 'const size_t' (aka 'const unsigned long') [-Wsign-compare] 681 | if (std::distance(I, E) <= N) | ~~~ ^ ~ ``` https://github.com/llvm/llvm-project/pull/123010 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Support BraceWrapping.AfterNamespace with AllowShortNamespacesOnASingleLine (PR #123010)
@@ -628,28 +632,36 @@ class LineJoiner { unsigned tryMergeNamespace(ArrayRef::const_iterator I, ArrayRef::const_iterator E, - unsigned Limit) { + unsigned Limit, bool OpenBraceWrapped) { if (Limit == 0) return 0; -assert(I[1]); -const auto &L1 = *I[1]; +// The merging code is relative to the opening namespace brace, which could +// be either on the first or second line due to the brace wrapping rules. +const size_t OpeningBraceLineOffset = OpenBraceWrapped ? 1 : 0; owenca wrote: ```suggestion const auto OpeningBraceLineOffset = OpenBraceWrapped ? 1 : 0; ``` to fix the [warning](https://github.com/llvm/llvm-project/pull/123010#issuecomment-2614727042). https://github.com/llvm/llvm-project/pull/123010 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [experimental] Detect return-stack-addr using CFG (PR #124133)
https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/124133 >From 22990789b61e9f9d22e88a6b008eb3166fd1cb56 Mon Sep 17 00:00:00 2001 From: Utkarsh Saxena Date: Thu, 23 Jan 2025 15:47:39 + Subject: [PATCH 1/3] [experimental] Detect return-stack-addr using CFG --- .../Analysis/Analyses/DanglingReference.h | 14 + clang/include/clang/Basic/DiagnosticGroups.td | 3 + .../clang/Basic/DiagnosticSemaKinds.td| 8 + clang/lib/Analysis/CMakeLists.txt | 1 + clang/lib/Analysis/DanglingReference.cpp | 351 ++ clang/lib/Sema/AnalysisBasedWarnings.cpp | 8 + .../test/Sema/warn-lifetime-analysis-cfg.cpp | 136 +++ 7 files changed, 521 insertions(+) create mode 100644 clang/include/clang/Analysis/Analyses/DanglingReference.h create mode 100644 clang/lib/Analysis/DanglingReference.cpp create mode 100644 clang/test/Sema/warn-lifetime-analysis-cfg.cpp diff --git a/clang/include/clang/Analysis/Analyses/DanglingReference.h b/clang/include/clang/Analysis/Analyses/DanglingReference.h new file mode 100644 index 00..c9f5753eed070e --- /dev/null +++ b/clang/include/clang/Analysis/Analyses/DanglingReference.h @@ -0,0 +1,14 @@ +#ifndef LLVM_CLANG_ANALYSIS_ANALYSES_DANGLING_REFERENCE_H +#define LLVM_CLANG_ANALYSIS_ANALYSES_DANGLING_REFERENCE_H +#include "clang/AST/DeclBase.h" +#include "clang/Analysis/AnalysisDeclContext.h" +#include "clang/Analysis/CFG.h" +#include "clang/Sema/Sema.h" + +namespace clang { +void runDanglingReferenceAnalysis(const DeclContext &dc, const CFG &cfg, + AnalysisDeclContext &ac, Sema &S); + +} // namespace clang + +#endif // LLVM_CLANG_ANALYSIS_ANALYSES_DANGLING_REFERENCE_H diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 594e99a19b64d6..eeddd6eb82a301 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -472,6 +472,9 @@ def Dangling : DiagGroup<"dangling", [DanglingAssignment, DanglingInitializerList, DanglingGsl, ReturnStackAddress]>; +def ReturnStackAddressCFG : DiagGroup<"return-stack-address-cfg">; +def DanglingCFG : DiagGroup<"dangling-cfg", [ReturnStackAddressCFG]>; + def DistributedObjectModifiers : DiagGroup<"distributed-object-modifiers">; def DllexportExplicitInstantiationDecl : DiagGroup<"dllexport-explicit-instantiation-decl">; def ExcessInitializers : DiagGroup<"excess-initializers">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 8be4f946dce1cc..846cf6b3d45f8a 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10169,6 +10169,14 @@ def err_lifetimebound_implicit_object_parameter_void_return_type : Error< "parameter of a function that returns void; " "did you mean 'lifetime_capture_by(X)'">; +// CFG based lifetime analysis. +def warn_ret_stack_variable_ref_cfg : Warning< + "returning reference to a stack variable">, InGroup, DefaultIgnore; +def note_local_variable_declared_here : Note<"reference to this stack variable is returned">; + +def warn_ret_stack_temporary_ref_cfg : Warning< + "returning reference to a temporary object">, InGroup, DefaultIgnore; + // CHECK: returning address/reference of stack memory def warn_ret_stack_addr_ref : Warning< "%select{address of|reference to}0 stack memory associated with " diff --git a/clang/lib/Analysis/CMakeLists.txt b/clang/lib/Analysis/CMakeLists.txt index 7914c12d429ef9..d6ea1e907e7f09 100644 --- a/clang/lib/Analysis/CMakeLists.txt +++ b/clang/lib/Analysis/CMakeLists.txt @@ -16,6 +16,7 @@ add_clang_library(clangAnalysis ConstructionContext.cpp Consumed.cpp CodeInjector.cpp + DanglingReference.cpp Dominators.cpp ExprMutationAnalyzer.cpp IntervalPartition.cpp diff --git a/clang/lib/Analysis/DanglingReference.cpp b/clang/lib/Analysis/DanglingReference.cpp new file mode 100644 index 00..2602cc597a36b8 --- /dev/null +++ b/clang/lib/Analysis/DanglingReference.cpp @@ -0,0 +1,351 @@ +#include "clang/Analysis/Analyses/DanglingReference.h" +#include "clang/AST/Attrs.inc" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclVisitor.h" +#include "clang/AST/Expr.h" +#include "clang/AST/ExprCXX.h" +#include "clang/AST/Stmt.h" +#include "clang/AST/StmtVisitor.h" +#include "clang/AST/Type.h" +#include "clang/Analysis/CFG.h" +#include "clang/Basic/DiagnosticSema.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseSet.h" +#include "llvm/Support/raw_ostream.h" +#include + +namespace clang { +namespace { + +template static bool isRecordWithAttr(QualType Type) { + auto *RD = Type->getAsCXXRecordDecl(); + if (!RD) +return false; + bool Result = RD->hasAttr(); + + if (auto *CTSD =
[clang] [libcxxabi] [llvm] [Clang] Mangling of pack indexing type and expression for itanium (PR #123513)
https://github.com/cor3ntin edited https://github.com/llvm/llvm-project/pull/123513 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libcxxabi] [llvm] [WIP][Clang] Mangling of pack indexing type and expression for itanium (PR #123513)
https://github.com/cor3ntin edited https://github.com/llvm/llvm-project/pull/123513 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libcxxabi] [llvm] [Clang] Mangling of pack indexing type and expression for itanium (PR #123513)
https://github.com/cor3ntin updated https://github.com/llvm/llvm-project/pull/123513 >From 021dd65bb55249f49b80a005096a9baf08d64031 Mon Sep 17 00:00:00 2001 From: Corentin Jabot Date: Sun, 19 Jan 2025 15:08:52 +0100 Subject: [PATCH] [Clang] Mangling of pack indexing type and expression for itanium --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/AST/ItaniumMangle.cpp | 89 +--- clang/test/CodeGenCXX/mangle-cxx2c.cpp | 11 +++ libcxxabi/src/demangle/ItaniumDemangle.h | 43 ++ libcxxabi/src/demangle/ItaniumNodes.def | 2 +- libcxxabi/test/test_demangle.pass.cpp| 5 ++ llvm/include/llvm/Demangle/ItaniumDemangle.h | 43 ++ llvm/include/llvm/Demangle/ItaniumNodes.def | 2 +- 8 files changed, 163 insertions(+), 33 deletions(-) create mode 100644 clang/test/CodeGenCXX/mangle-cxx2c.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index b63bd366cfe884..e5946fc71c56a6 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -1003,6 +1003,7 @@ Bug Fixes to C++ Support lambda functions or inline friend functions defined inside templates (#GH122493). - Clang now rejects declaring an alias template with the same name as its template parameter. (#GH123423) - Correctly determine the implicit constexprness of lambdas in dependent contexts. (#GH97958) (#GH114234) +- Implement Itanium mangling for pack indexing. (#GH112003) Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index 1dd936cf4fb518..4b2cb630e16f87 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -603,6 +603,7 @@ class CXXNameMangler { void mangleInitListElements(const InitListExpr *InitList); void mangleRequirement(SourceLocation RequiresExprLoc, const concepts::Requirement *Req); + void mangleReferenceToPack(const NamedDecl *ND); void mangleExpression(const Expr *E, unsigned Arity = UnknownArity, bool AsTemplateArg = false); void mangleCXXCtorType(CXXCtorType T, const CXXRecordDecl *InheritedFrom); @@ -4348,10 +4349,10 @@ void CXXNameMangler::mangleType(const PackExpansionType *T) { } void CXXNameMangler::mangleType(const PackIndexingType *T) { - if (!T->hasSelectedType()) -mangleType(T->getPattern()); - else -mangleType(T->getSelectedType()); + // ::= Dy# pack indexing type (C++23) + Out << "Dy"; + mangleType(T->getPattern()); + mangleExpression(T->getIndexExpr()); } void CXXNameMangler::mangleType(const ObjCInterfaceType *T) { @@ -4785,35 +4786,63 @@ void CXXNameMangler::mangleRequirement(SourceLocation RequiresExprLoc, } } +void CXXNameMangler::mangleReferenceToPack(const NamedDecl *Pack) { + if (const auto *TTP = dyn_cast(Pack)) +mangleTemplateParameter(TTP->getDepth(), TTP->getIndex()); + else if (const auto *NTTP = dyn_cast(Pack)) +mangleTemplateParameter(NTTP->getDepth(), NTTP->getIndex()); + else if (const auto *TempTP = dyn_cast(Pack)) +mangleTemplateParameter(TempTP->getDepth(), TempTP->getIndex()); + else +mangleFunctionParam(cast(Pack)); +} + void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity, bool AsTemplateArg) { // ::= // ::= - // ::= - // ::= cv expression # conversion with one argument - // ::= cv _ * E # conversion with a different number of arguments - // ::= dc # dynamic_cast (expression) - // ::= sc # static_cast (expression) - // ::= cc # const_cast (expression) - // ::= rc # reinterpret_cast (expression) + // ::= + // + // ::= cv expression # conversion with one + // argument + // ::= cv _ * E # conversion with a different + // number of arguments + // ::= dc # dynamic_cast + // (expression) + // ::= sc # static_cast + // (expression) + // ::= cc # const_cast + // (expression) + // ::= rc # reinterpret_cast + // (expression) // ::= st # sizeof (a type) // ::= at # alignof (a type) // ::= // ::= - // ::= fpT# 'this' expression (part of ) - // ::= sr # dependent name - // ::= sr # dependent template-id - // ::= ds # expr.*expr - // ::= sZ # size of a parameter pack + // ::=
[clang] [experimental] Detect return-stack-addr using CFG (PR #124133)
https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/124133 >From 22990789b61e9f9d22e88a6b008eb3166fd1cb56 Mon Sep 17 00:00:00 2001 From: Utkarsh Saxena Date: Thu, 23 Jan 2025 15:47:39 + Subject: [PATCH 1/3] [experimental] Detect return-stack-addr using CFG --- .../Analysis/Analyses/DanglingReference.h | 14 + clang/include/clang/Basic/DiagnosticGroups.td | 3 + .../clang/Basic/DiagnosticSemaKinds.td| 8 + clang/lib/Analysis/CMakeLists.txt | 1 + clang/lib/Analysis/DanglingReference.cpp | 351 ++ clang/lib/Sema/AnalysisBasedWarnings.cpp | 8 + .../test/Sema/warn-lifetime-analysis-cfg.cpp | 136 +++ 7 files changed, 521 insertions(+) create mode 100644 clang/include/clang/Analysis/Analyses/DanglingReference.h create mode 100644 clang/lib/Analysis/DanglingReference.cpp create mode 100644 clang/test/Sema/warn-lifetime-analysis-cfg.cpp diff --git a/clang/include/clang/Analysis/Analyses/DanglingReference.h b/clang/include/clang/Analysis/Analyses/DanglingReference.h new file mode 100644 index 00..c9f5753eed070e --- /dev/null +++ b/clang/include/clang/Analysis/Analyses/DanglingReference.h @@ -0,0 +1,14 @@ +#ifndef LLVM_CLANG_ANALYSIS_ANALYSES_DANGLING_REFERENCE_H +#define LLVM_CLANG_ANALYSIS_ANALYSES_DANGLING_REFERENCE_H +#include "clang/AST/DeclBase.h" +#include "clang/Analysis/AnalysisDeclContext.h" +#include "clang/Analysis/CFG.h" +#include "clang/Sema/Sema.h" + +namespace clang { +void runDanglingReferenceAnalysis(const DeclContext &dc, const CFG &cfg, + AnalysisDeclContext &ac, Sema &S); + +} // namespace clang + +#endif // LLVM_CLANG_ANALYSIS_ANALYSES_DANGLING_REFERENCE_H diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 594e99a19b64d6..eeddd6eb82a301 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -472,6 +472,9 @@ def Dangling : DiagGroup<"dangling", [DanglingAssignment, DanglingInitializerList, DanglingGsl, ReturnStackAddress]>; +def ReturnStackAddressCFG : DiagGroup<"return-stack-address-cfg">; +def DanglingCFG : DiagGroup<"dangling-cfg", [ReturnStackAddressCFG]>; + def DistributedObjectModifiers : DiagGroup<"distributed-object-modifiers">; def DllexportExplicitInstantiationDecl : DiagGroup<"dllexport-explicit-instantiation-decl">; def ExcessInitializers : DiagGroup<"excess-initializers">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 8be4f946dce1cc..846cf6b3d45f8a 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10169,6 +10169,14 @@ def err_lifetimebound_implicit_object_parameter_void_return_type : Error< "parameter of a function that returns void; " "did you mean 'lifetime_capture_by(X)'">; +// CFG based lifetime analysis. +def warn_ret_stack_variable_ref_cfg : Warning< + "returning reference to a stack variable">, InGroup, DefaultIgnore; +def note_local_variable_declared_here : Note<"reference to this stack variable is returned">; + +def warn_ret_stack_temporary_ref_cfg : Warning< + "returning reference to a temporary object">, InGroup, DefaultIgnore; + // CHECK: returning address/reference of stack memory def warn_ret_stack_addr_ref : Warning< "%select{address of|reference to}0 stack memory associated with " diff --git a/clang/lib/Analysis/CMakeLists.txt b/clang/lib/Analysis/CMakeLists.txt index 7914c12d429ef9..d6ea1e907e7f09 100644 --- a/clang/lib/Analysis/CMakeLists.txt +++ b/clang/lib/Analysis/CMakeLists.txt @@ -16,6 +16,7 @@ add_clang_library(clangAnalysis ConstructionContext.cpp Consumed.cpp CodeInjector.cpp + DanglingReference.cpp Dominators.cpp ExprMutationAnalyzer.cpp IntervalPartition.cpp diff --git a/clang/lib/Analysis/DanglingReference.cpp b/clang/lib/Analysis/DanglingReference.cpp new file mode 100644 index 00..2602cc597a36b8 --- /dev/null +++ b/clang/lib/Analysis/DanglingReference.cpp @@ -0,0 +1,351 @@ +#include "clang/Analysis/Analyses/DanglingReference.h" +#include "clang/AST/Attrs.inc" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclVisitor.h" +#include "clang/AST/Expr.h" +#include "clang/AST/ExprCXX.h" +#include "clang/AST/Stmt.h" +#include "clang/AST/StmtVisitor.h" +#include "clang/AST/Type.h" +#include "clang/Analysis/CFG.h" +#include "clang/Basic/DiagnosticSema.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseSet.h" +#include "llvm/Support/raw_ostream.h" +#include + +namespace clang { +namespace { + +template static bool isRecordWithAttr(QualType Type) { + auto *RD = Type->getAsCXXRecordDecl(); + if (!RD) +return false; + bool Result = RD->hasAttr(); + + if (auto *CTSD =
[clang] [libcxxabi] [llvm] [Clang] Mangling of pack indexing type and expression for itanium (PR #123513)
llvmbot wrote: @llvm/pr-subscribers-clang Author: cor3ntin (cor3ntin) Changes See https://github.com/itanium-cxx-abi/cxx-abi/pull/198 and #112003 --- Full diff: https://github.com/llvm/llvm-project/pull/123513.diff 8 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+1) - (modified) clang/lib/AST/ItaniumMangle.cpp (+58-31) - (added) clang/test/CodeGenCXX/mangle-cxx2c.cpp (+11) - (modified) libcxxabi/src/demangle/ItaniumDemangle.h (+43) - (modified) libcxxabi/src/demangle/ItaniumNodes.def (+1-1) - (modified) libcxxabi/test/test_demangle.pass.cpp (+5) - (modified) llvm/include/llvm/Demangle/ItaniumDemangle.h (+43) - (modified) llvm/include/llvm/Demangle/ItaniumNodes.def (+1-1) ``diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index b63bd366cfe884..e5946fc71c56a6 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -1003,6 +1003,7 @@ Bug Fixes to C++ Support lambda functions or inline friend functions defined inside templates (#GH122493). - Clang now rejects declaring an alias template with the same name as its template parameter. (#GH123423) - Correctly determine the implicit constexprness of lambdas in dependent contexts. (#GH97958) (#GH114234) +- Implement Itanium mangling for pack indexing. (#GH112003) Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index 1dd936cf4fb518..4b2cb630e16f87 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -603,6 +603,7 @@ class CXXNameMangler { void mangleInitListElements(const InitListExpr *InitList); void mangleRequirement(SourceLocation RequiresExprLoc, const concepts::Requirement *Req); + void mangleReferenceToPack(const NamedDecl *ND); void mangleExpression(const Expr *E, unsigned Arity = UnknownArity, bool AsTemplateArg = false); void mangleCXXCtorType(CXXCtorType T, const CXXRecordDecl *InheritedFrom); @@ -4348,10 +4349,10 @@ void CXXNameMangler::mangleType(const PackExpansionType *T) { } void CXXNameMangler::mangleType(const PackIndexingType *T) { - if (!T->hasSelectedType()) -mangleType(T->getPattern()); - else -mangleType(T->getSelectedType()); + // ::= Dy# pack indexing type (C++23) + Out << "Dy"; + mangleType(T->getPattern()); + mangleExpression(T->getIndexExpr()); } void CXXNameMangler::mangleType(const ObjCInterfaceType *T) { @@ -4785,35 +4786,63 @@ void CXXNameMangler::mangleRequirement(SourceLocation RequiresExprLoc, } } +void CXXNameMangler::mangleReferenceToPack(const NamedDecl *Pack) { + if (const auto *TTP = dyn_cast(Pack)) +mangleTemplateParameter(TTP->getDepth(), TTP->getIndex()); + else if (const auto *NTTP = dyn_cast(Pack)) +mangleTemplateParameter(NTTP->getDepth(), NTTP->getIndex()); + else if (const auto *TempTP = dyn_cast(Pack)) +mangleTemplateParameter(TempTP->getDepth(), TempTP->getIndex()); + else +mangleFunctionParam(cast(Pack)); +} + void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity, bool AsTemplateArg) { // ::= // ::= - // ::= - // ::= cv expression # conversion with one argument - // ::= cv _ * E # conversion with a different number of arguments - // ::= dc # dynamic_cast (expression) - // ::= sc # static_cast (expression) - // ::= cc # const_cast (expression) - // ::= rc # reinterpret_cast (expression) + // ::= + // + // ::= cv expression # conversion with one + // argument + // ::= cv _ * E # conversion with a different + // number of arguments + // ::= dc # dynamic_cast + // (expression) + // ::= sc # static_cast + // (expression) + // ::= cc # const_cast + // (expression) + // ::= rc # reinterpret_cast + // (expression) // ::= st # sizeof (a type) // ::= at # alignof (a type) // ::= // ::= - // ::= fpT# 'this' expression (part of ) - // ::= sr # dependent name - // ::= sr # dependent template-id - // ::= ds # expr.*expr - // ::= sZ # size of a parameter pack + // ::= fpT# 'this' expression (part + // of ) + // ::= sr # dependent + //
[clang] [libcxxabi] [llvm] [Clang] Mangling of pack indexing type and expression for itanium (PR #123513)
https://github.com/cor3ntin ready_for_review https://github.com/llvm/llvm-project/pull/123513 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)
@@ -649,15 +649,15 @@ namespace cwg241 { // cwg241: 9 A::g<3>(b); C::f<3>(b); // expected-error@-1 {{no matching function for call to 'f'}} -// expected-note@#cwg241-C-f {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T'}} +// expected-note@#cwg241-C-f {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T': could not convert '3' from 'int' to class 'T' (expected a class, but got '3')}} Endilll wrote: The newly added diagnostic wording seems confusing to me, but the text in parentheses might be salvageable: ```suggestion // expected-note@#cwg241-C-f {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T': expected a type, but got value '3' (of type 'int'))}} ``` https://github.com/llvm/llvm-project/pull/122754 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)
https://github.com/Endilll commented: The way you applied changes to C++ DR tests is good, but I think the diagnostic message would benefit from further wordsmithing. https://github.com/llvm/llvm-project/pull/122754 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)
https://github.com/Endilll edited https://github.com/llvm/llvm-project/pull/122754 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)
https://github.com/Endilll edited https://github.com/llvm/llvm-project/pull/122754 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Plumb through -fsanitize-skip-hot-cutoff to LowerAllowCheckPass (PR #124211)
@@ -828,11 +828,34 @@ parseLowerAllowCheckPassOptions(StringRef Params) { StringRef ParamName; std::tie(ParamName, Params) = Params.split(';'); -return make_error( -formatv("invalid LowerAllowCheck pass parameter '{0}' ", ParamName) -.str(), -inconvertibleErrorCode()); +// cutoffs=99|99|0|...10 +if (ParamName.starts_with("cutoffs=")) { + StringRef CutoffsStr; + std::tie(ParamName, CutoffsStr) = ParamName.split('='); + + while (CutoffsStr != "") { +StringRef firstCutoffStr; +std::tie(firstCutoffStr, CutoffsStr) = CutoffsStr.split('|'); thurstond wrote: The problem is opt uses commas to separate passes, so `opt -passes=msan,someOtherPass` gets misparsed into something like `msan,`, `someOtherPass`. https://github.com/llvm/llvm-project/pull/124211 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Plumb through -fsanitize-skip-hot-cutoff to LowerAllowCheckPass (PR #124211)
@@ -107,7 +108,18 @@ static bool removeUbsanTraps(Function &F, const BlockFrequencyInfo &BFI, case Intrinsic::allow_runtime_check: { ++NumChecksTotal; -bool ToRemove = ShouldRemove(BB); +bool ToRemove = ShouldRemoveRandom(); + +unsigned int cutoff = 0; +if (ID == Intrinsic::allow_ubsan_check) { + auto *Kind = cast(II->getArgOperand(0)); + if (Kind->getZExtValue() < cutoffs.size()) +cutoff = cutoffs[Kind->getZExtValue()]; +} +if (HotPercentileCutoff.getNumOccurrences()) vitalybuka wrote: No need to lookup array if getNumOccurrences > 0 https://github.com/llvm/llvm-project/pull/124211 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Plumb through -fsanitize-skip-hot-cutoff to LowerAllowCheckPass (PR #124211)
@@ -107,7 +108,18 @@ static bool removeUbsanTraps(Function &F, const BlockFrequencyInfo &BFI, case Intrinsic::allow_runtime_check: { ++NumChecksTotal; -bool ToRemove = ShouldRemove(BB); +bool ToRemove = ShouldRemoveRandom(); + +unsigned int cutoff = 0; vitalybuka wrote: lambda for `GetCuttoff(II)` and please keep `ShouldRemove`, now as ShouldRemove(II) https://github.com/llvm/llvm-project/pull/124211 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Plumb through -fsanitize-skip-hot-cutoff to LowerAllowCheckPass (PR #124211)
@@ -2,6 +2,14 @@ ; RUN: opt < %s -passes='function(lower-allow-check)' -S | FileCheck %s --check-prefixes=NOPROFILE ; RUN: opt < %s -passes='function(lower-allow-check)' -lower-allow-check-random-rate=0 -S | FileCheck %s --check-prefixes=NONE ; RUN: opt < %s -passes='function(lower-allow-check)' -lower-allow-check-random-rate=1 -S | FileCheck %s --check-prefixes=ALL +; +; RUN: opt < %s -passes='require,function(lower-allow-check)' -S | FileCheck %s --check-prefixes=HOT99 +; RUN: opt < %s -passes='require,function(lower-allow-check)' -S | FileCheck %s --check-prefixes=HOT70 +; RUN: opt < %s -passes='require,function(lower-allow-check)' -lower-allow-check-random-rate=0 -S | FileCheck %s --check-prefixes=NONE99 +; RUN: opt < %s -passes='require,function(lower-allow-check)' -lower-allow-check-random-rate=1 -S | FileCheck %s --check-prefixes=ALL70 vitalybuka wrote: Maybe `https://github.com/llvm/llvm-project/pull/124211 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Plumb through -fsanitize-skip-hot-cutoff to LowerAllowCheckPass (PR #124211)
https://github.com/thurstond edited https://github.com/llvm/llvm-project/pull/124211 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Sema] Fix __array_rank queried type at template instantiation (PR #124491)
https://github.com/v01dXYZ created https://github.com/llvm/llvm-project/pull/124491 The type being queried was left as a template type parameter, making the whole expression as dependent and thus not eligible to static_assert. Fixes #123498 >From 8283e34bb0144604e52196e0a69a56355eb51e43 Mon Sep 17 00:00:00 2001 From: v01dxyz Date: Sun, 26 Jan 2025 23:07:13 +0100 Subject: [PATCH] [Sema] Fix __array_rank queried type at template instantiation The type being queried was left as a template type parameter, making the whole expression as dependent and thus not eligible to static_assert. --- clang/include/clang/AST/ExprCXX.h | 4 +- clang/lib/Sema/TreeTransform.h| 3 -- .../array-type-trait-with-template.cpp| 37 +++ 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 clang/test/SemaCXX/array-type-trait-with-template.cpp diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index aa10945addf78f..2a130bc6da79a0 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -2847,8 +2847,8 @@ class TypeTraitExpr final /// /// Example: /// \code -/// __array_rank(int[10][20]) == 2 -/// __array_extent(int, 1)== 20 +/// __array_rank(int[10][20]) == 2 +/// __array_extent(int[10][20], 1) == 20 /// \endcode class ArrayTypeTraitExpr : public Expr { /// The trait. An ArrayTypeTrait enum in MSVC compat unsigned. diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 12680843a434a0..f04adf7fdf8ad2 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -14947,9 +14947,6 @@ TreeTransform::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); if (SubExpr.isInvalid()) return ExprError(); - -if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) - return E; } return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T, diff --git a/clang/test/SemaCXX/array-type-trait-with-template.cpp b/clang/test/SemaCXX/array-type-trait-with-template.cpp new file mode 100644 index 00..b0cc9a12d6efb6 --- /dev/null +++ b/clang/test/SemaCXX/array-type-trait-with-template.cpp @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -fsyntax-only %s + +// When __array_rank is used with a template type parameter, this +// test ensures clang considers the final expression as having an +// integral type. +// +// Although array_extent was handled well, it is added here. +template +constexpr int array_rank(T (&lhs)[N]) { + return __array_rank(T[N]); +} + +template +constexpr int array_extent(T (&lhs)[N]) { + return __array_extent(T[N], I); +} + +int main() { + constexpr int vec[] = {0, 1, 2, 1}; + constexpr int mat[4][4] = { +{1, 0, 0, 0}, +{0, 1, 0, 0}, +{0, 0, 1, 0}, +{0, 0, 0, 1} + }; + + (void) (array_rank(vec) == 1); + (void) (array_rank(vec) == 2); + + static_assert(array_rank(vec) == 1); + static_assert(array_rank(mat) == 2); + + static_assert(array_extent<0>(vec) == 4); + static_assert(array_extent<0>(mat) == 4); + static_assert(array_extent<1>(mat) == 4); + static_assert(array_extent<1>(vec) == 0); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Plumb through -fsanitize-skip-hot-cutoff to LowerAllowCheckPass (PR #124211)
https://github.com/vitalybuka requested changes to this pull request. Lets move clang part into a new PR? https://github.com/llvm/llvm-project/pull/124211 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Plumb through -fsanitize-skip-hot-cutoff to LowerAllowCheckPass (PR #124211)
https://github.com/vitalybuka edited https://github.com/llvm/llvm-project/pull/124211 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Sema] Fix __array_rank queried type at template instantiation (PR #124491)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Robert Dazi (v01dXYZ) Changes The type being queried was left as a template type parameter, making the whole expression as dependent and thus not eligible to static_assert. Fixes #123498 --- Full diff: https://github.com/llvm/llvm-project/pull/124491.diff 3 Files Affected: - (modified) clang/include/clang/AST/ExprCXX.h (+2-2) - (modified) clang/lib/Sema/TreeTransform.h (-3) - (added) clang/test/SemaCXX/array-type-trait-with-template.cpp (+37) ``diff diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index aa10945addf78f..2a130bc6da79a0 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -2847,8 +2847,8 @@ class TypeTraitExpr final /// /// Example: /// \code -/// __array_rank(int[10][20]) == 2 -/// __array_extent(int, 1)== 20 +/// __array_rank(int[10][20]) == 2 +/// __array_extent(int[10][20], 1) == 20 /// \endcode class ArrayTypeTraitExpr : public Expr { /// The trait. An ArrayTypeTrait enum in MSVC compat unsigned. diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 12680843a434a0..f04adf7fdf8ad2 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -14947,9 +14947,6 @@ TreeTransform::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); if (SubExpr.isInvalid()) return ExprError(); - -if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) - return E; } return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T, diff --git a/clang/test/SemaCXX/array-type-trait-with-template.cpp b/clang/test/SemaCXX/array-type-trait-with-template.cpp new file mode 100644 index 00..b0cc9a12d6efb6 --- /dev/null +++ b/clang/test/SemaCXX/array-type-trait-with-template.cpp @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -fsyntax-only %s + +// When __array_rank is used with a template type parameter, this +// test ensures clang considers the final expression as having an +// integral type. +// +// Although array_extent was handled well, it is added here. +template +constexpr int array_rank(T (&lhs)[N]) { + return __array_rank(T[N]); +} + +template +constexpr int array_extent(T (&lhs)[N]) { + return __array_extent(T[N], I); +} + +int main() { + constexpr int vec[] = {0, 1, 2, 1}; + constexpr int mat[4][4] = { +{1, 0, 0, 0}, +{0, 1, 0, 0}, +{0, 0, 1, 0}, +{0, 0, 0, 1} + }; + + (void) (array_rank(vec) == 1); + (void) (array_rank(vec) == 2); + + static_assert(array_rank(vec) == 1); + static_assert(array_rank(mat) == 2); + + static_assert(array_extent<0>(vec) == 4); + static_assert(array_extent<0>(mat) == 4); + static_assert(array_extent<1>(mat) == 4); + static_assert(array_extent<1>(vec) == 0); +} `` https://github.com/llvm/llvm-project/pull/124491 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Plumb through -fsanitize-skip-hot-cutoff to LowerAllowCheckPass (PR #124211)
https://github.com/vitalybuka edited https://github.com/llvm/llvm-project/pull/124211 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)
@@ -1523,9 +1570,25 @@ void Sema::CheckCompleteDecompositionDeclaration(DecompositionDecl *DD) { // If the type of the decomposition is dependent, then so is the type of // each binding. if (DecompType->isDependentType()) { -for (auto *B : DD->bindings()) - B->setType(Context.DependentTy); +for (auto *B : DD->bindings()) { + // Do not overwrite any pack type. + if (B->getType().isNull()) +B->setType(Context.DependentTy); +} ricejasonf wrote: This was here before. After processing the intializer the BindingDecls should all have types set except in the case when the initializer is dependent. In that case all the types are still Null so here we set them to dependent. My change is just preventing it from overwriting the PackExpansionType if there is one. https://github.com/llvm/llvm-project/pull/121417 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Unwrap reference types in HeuristicResolverImpl::resolveTypeToRecordDecl() (PR #124451)
@@ -133,8 +133,8 @@ TemplateName getReferencedTemplateName(const Type *T) { CXXRecordDecl *HeuristicResolverImpl::resolveTypeToRecordDecl(const Type *T) { assert(T); - // Unwrap type sugar such as type aliases. - T = T->getCanonicalTypeInternal().getTypePtr(); + // Unwrap references and type sugar such as type aliases. + T = T->getCanonicalTypeInternal().getNonReferenceType().getTypePtr(); zyn0217 wrote: Does it work if `b` were a pointer? https://github.com/llvm/llvm-project/pull/124451 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TableGen] Avoid repeated map lookups (NFC) (PR #124448)
https://github.com/kazutakahirata updated https://github.com/llvm/llvm-project/pull/124448 >From 2273e9e518fa5625a40298a970dfd3ad1c3f27db Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sat, 25 Jan 2025 16:07:33 -0800 Subject: [PATCH 1/3] [TableGen] Avoid repeated map lookups (NFC) This patch avoids repeated map lookups and constructions of temporary std::string instances by switching to StringMap. --- clang/utils/TableGen/MveEmitter.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/utils/TableGen/MveEmitter.cpp b/clang/utils/TableGen/MveEmitter.cpp index 8ebd0bb800feff..7f298d1cbd4376 100644 --- a/clang/utils/TableGen/MveEmitter.cpp +++ b/clang/utils/TableGen/MveEmitter.cpp @@ -60,6 +60,7 @@ #include "llvm/ADT/APInt.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/StringSet.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/Casting.h" #include "llvm/Support/raw_ostream.h" @@ -1955,18 +1956,17 @@ void MveEmitter::EmitBuiltinDef(raw_ostream &OS) { << ", \"\", \"n\")\n"; } - std::set ShortNamesSeen; + StringSet<> ShortNamesSeen; for (const auto &kv : ACLEIntrinsics) { const ACLEIntrinsic &Int = *kv.second; if (Int.polymorphic()) { StringRef Name = Int.shortName(); - if (ShortNamesSeen.find(std::string(Name)) == ShortNamesSeen.end()) { + if (ShortNamesSeen.insert(Name).second) { OS << "BUILTIN(__builtin_arm_mve_" << Name << ", \"vi.\", \"nt"; if (Int.nonEvaluating()) OS << "u"; // indicate that this builtin doesn't evaluate its args OS << "\")\n"; -ShortNamesSeen.insert(std::string(Name)); } } } >From 8265a5f16881d6a06ad76686b86ad337ab628dde Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 26 Jan 2025 01:55:02 -0800 Subject: [PATCH 2/3] Address comments. --- clang/utils/TableGen/MveEmitter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/utils/TableGen/MveEmitter.cpp b/clang/utils/TableGen/MveEmitter.cpp index 7f298d1cbd4376..8173900f895e75 100644 --- a/clang/utils/TableGen/MveEmitter.cpp +++ b/clang/utils/TableGen/MveEmitter.cpp @@ -1956,7 +1956,7 @@ void MveEmitter::EmitBuiltinDef(raw_ostream &OS) { << ", \"\", \"n\")\n"; } - StringSet<> ShortNamesSeen; + DenseSet ShortNamesSeen; for (const auto &kv : ACLEIntrinsics) { const ACLEIntrinsic &Int = *kv.second; >From f6bd25bde203dd12d9cca5a615876d21331fd3c5 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 26 Jan 2025 01:56:17 -0800 Subject: [PATCH 3/3] Remove an unused include. --- clang/utils/TableGen/MveEmitter.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/utils/TableGen/MveEmitter.cpp b/clang/utils/TableGen/MveEmitter.cpp index 8173900f895e75..58a4d3c22ac366 100644 --- a/clang/utils/TableGen/MveEmitter.cpp +++ b/clang/utils/TableGen/MveEmitter.cpp @@ -60,7 +60,6 @@ #include "llvm/ADT/APInt.h" #include "llvm/ADT/StringRef.h" -#include "llvm/ADT/StringSet.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/Casting.h" #include "llvm/Support/raw_ostream.h" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TableGen] Avoid repeated map lookups (NFC) (PR #124448)
kazutakahirata wrote: > Can't this use DenseSet? It looks like the names here live for the lifetime > of the set. Good idea! Revised. https://github.com/llvm/llvm-project/pull/124448 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TableGen] Avoid repeated map lookups (NFC) (PR #124448)
https://github.com/kazutakahirata updated https://github.com/llvm/llvm-project/pull/124448 >From 2273e9e518fa5625a40298a970dfd3ad1c3f27db Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sat, 25 Jan 2025 16:07:33 -0800 Subject: [PATCH 1/2] [TableGen] Avoid repeated map lookups (NFC) This patch avoids repeated map lookups and constructions of temporary std::string instances by switching to StringMap. --- clang/utils/TableGen/MveEmitter.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/utils/TableGen/MveEmitter.cpp b/clang/utils/TableGen/MveEmitter.cpp index 8ebd0bb800feff..7f298d1cbd4376 100644 --- a/clang/utils/TableGen/MveEmitter.cpp +++ b/clang/utils/TableGen/MveEmitter.cpp @@ -60,6 +60,7 @@ #include "llvm/ADT/APInt.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/StringSet.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/Casting.h" #include "llvm/Support/raw_ostream.h" @@ -1955,18 +1956,17 @@ void MveEmitter::EmitBuiltinDef(raw_ostream &OS) { << ", \"\", \"n\")\n"; } - std::set ShortNamesSeen; + StringSet<> ShortNamesSeen; for (const auto &kv : ACLEIntrinsics) { const ACLEIntrinsic &Int = *kv.second; if (Int.polymorphic()) { StringRef Name = Int.shortName(); - if (ShortNamesSeen.find(std::string(Name)) == ShortNamesSeen.end()) { + if (ShortNamesSeen.insert(Name).second) { OS << "BUILTIN(__builtin_arm_mve_" << Name << ", \"vi.\", \"nt"; if (Int.nonEvaluating()) OS << "u"; // indicate that this builtin doesn't evaluate its args OS << "\")\n"; -ShortNamesSeen.insert(std::string(Name)); } } } >From 8265a5f16881d6a06ad76686b86ad337ab628dde Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 26 Jan 2025 01:55:02 -0800 Subject: [PATCH 2/2] Address comments. --- clang/utils/TableGen/MveEmitter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/utils/TableGen/MveEmitter.cpp b/clang/utils/TableGen/MveEmitter.cpp index 7f298d1cbd4376..8173900f895e75 100644 --- a/clang/utils/TableGen/MveEmitter.cpp +++ b/clang/utils/TableGen/MveEmitter.cpp @@ -1956,7 +1956,7 @@ void MveEmitter::EmitBuiltinDef(raw_ostream &OS) { << ", \"\", \"n\")\n"; } - StringSet<> ShortNamesSeen; + DenseSet ShortNamesSeen; for (const auto &kv : ACLEIntrinsics) { const ACLEIntrinsic &Int = *kv.second; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TableGen] Avoid repeated map lookups (NFC) (PR #124448)
https://github.com/kazutakahirata edited https://github.com/llvm/llvm-project/pull/124448 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add null-terminated path option (#123921) (PR #123926)
https://github.com/createyourpersonalaccount updated https://github.com/llvm/llvm-project/pull/123926 >From 9dfbb9a3cc7f6bc557bc1ccf25cc727a02c4274c Mon Sep 17 00:00:00 2001 From: Nikolaos Chatzikonstantinou Date: Wed, 22 Jan 2025 05:43:02 -0500 Subject: [PATCH 1/4] [clang-format] Add null-terminated path option (#123921) This makes the `git clang-format` tool compose nicely with other shell utilities in case of maliciously (or innocently) crafted filenames. --- clang/tools/clang-format/git-clang-format | 19 --- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/clang/tools/clang-format/git-clang-format b/clang/tools/clang-format/git-clang-format index da271bbe6e3a07..04c49e8910d0ac 100755 --- a/clang/tools/clang-format/git-clang-format +++ b/clang/tools/clang-format/git-clang-format @@ -205,6 +205,12 @@ def main(): "commits" ), ) +p.add_argument( +"-0", +"--null", +action="store_true", +help="print the affected paths with null-terminated characters", +) # We gather all the remaining positional arguments into 'args' since we need # to use some heuristics to determine whether or not was present. # However, to print pretty messages, we make use of metavar and help. @@ -261,11 +267,11 @@ def main(): "ignored by clang-format):" ) for filename in ignored_files: -print("%s" % filename) +print_filename(filename, opts.null) if changed_lines: print("Running clang-format on the following files:") for filename in changed_lines: -print("%s" % filename) +print_filename(filename, opts.null) if not changed_lines: if opts.verbose >= 0: @@ -304,7 +310,7 @@ def main(): if (opts.verbose >= 0 and not opts.patch) or opts.verbose >= 1: print("changed files:") for filename in changed_files: -print("%s" % filename) +print_filename(filename, opts.null) return 1 @@ -869,5 +875,12 @@ def convert_string(bytes_input): return str(bytes_input) +def print_filename(filename, null=False): +if null: +print(filename + "\0", end="") +else: +print("%s" % filename) + + if __name__ == "__main__": sys.exit(main()) >From 63424768ccd5cd2067448b7a86aeab16f01a0e78 Mon Sep 17 00:00:00 2001 From: Nikolaos Chatzikonstantinou Date: Fri, 24 Jan 2025 06:32:47 -0500 Subject: [PATCH 2/4] do not print anything but list of files when null is enabled --- clang/tools/clang-format/git-clang-format | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/clang/tools/clang-format/git-clang-format b/clang/tools/clang-format/git-clang-format index 04c49e8910d0ac..9a26ef7a96a386 100755 --- a/clang/tools/clang-format/git-clang-format +++ b/clang/tools/clang-format/git-clang-format @@ -274,7 +274,7 @@ def main(): print_filename(filename, opts.null) if not changed_lines: -if opts.verbose >= 0: +if opts.verbose >= 0 and not opts.null: print("no modified files to format") return 0 @@ -295,7 +295,7 @@ def main(): print("new tree: %s" % new_tree) if old_tree == new_tree: -if opts.verbose >= 0: +if opts.verbose >= 0 and not opts.null: print("clang-format did not modify any files") return 0 @@ -308,7 +308,8 @@ def main(): old_tree, new_tree, force=opts.force, patch_mode=opts.patch ) if (opts.verbose >= 0 and not opts.patch) or opts.verbose >= 1: -print("changed files:") +if not opts.null: +print("changed files:") for filename in changed_files: print_filename(filename, opts.null) >From 6b9460ab14abce7a3b2bda6851b920b64cfa9a67 Mon Sep 17 00:00:00 2001 From: Nikolaos Chatzikonstantinou Date: Sun, 26 Jan 2025 04:51:50 -0500 Subject: [PATCH 3/4] improve help string Co-authored-by: Owen Pan --- clang/tools/clang-format/git-clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/tools/clang-format/git-clang-format b/clang/tools/clang-format/git-clang-format index 9a26ef7a96a386..90917533cf3513 100755 --- a/clang/tools/clang-format/git-clang-format +++ b/clang/tools/clang-format/git-clang-format @@ -209,7 +209,7 @@ def main(): "-0", "--null", action="store_true", -help="print the affected paths with null-terminated characters", +help="end each printed filename with a null character", ) # We gather all the remaining positional arguments into 'args' since we need # to use some heuristics to determine whether or not was present. >From 343fa15be5246d429c22f611371ff8b678ff3355 Mon Sep 17 00:00:00 2001 From: Nikolaos Chatzikonstantinou Date: Sun, 26 Jan 2025 04:59:41 -0500 Subject: [PATCH 4/4] imp
[clang] [AArch64] Enable vscale_range with +sme (PR #124466)
https://github.com/davemgreen created https://github.com/llvm/llvm-project/pull/124466 If we have +sme but not +sve, we would not set vscale_range on functions. It should be valid to apply it with the same range with just +sme, which can help improve the performance of generated code. >From 7919c40e6e06d5a5adfbd418f275aad9852de274 Mon Sep 17 00:00:00 2001 From: David Green Date: Sun, 26 Jan 2025 13:47:58 + Subject: [PATCH] [AArch64] Enable vscale_range with +sme If we have +sme but not +sve, we would not set vscale_range on functions. It should be valid to apply it with the same range with just +sme, which can help improve the performance of generated code. --- clang/lib/Basic/Targets/AArch64.cpp | 2 +- .../AArch64/sme-intrinsics/aarch64-sme-attrs.cpp | 16 .../CodeGen/arm-sve-vector-bits-vscale-range.c | 1 + 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index 0b899137bbb5c7..e9afe0fb4ee456 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -708,7 +708,7 @@ AArch64TargetInfo::getVScaleRange(const LangOptions &LangOpts) const { return std::pair( LangOpts.VScaleMin ? LangOpts.VScaleMin : 1, LangOpts.VScaleMax); - if (hasFeature("sve")) + if (hasFeature("sve") || hasFeature("sme")) return std::pair(1, 16); return std::nullopt; diff --git a/clang/test/CodeGen/AArch64/sme-intrinsics/aarch64-sme-attrs.cpp b/clang/test/CodeGen/AArch64/sme-intrinsics/aarch64-sme-attrs.cpp index 54762c8b414124..cabd9d01e46652 100644 --- a/clang/test/CodeGen/AArch64/sme-intrinsics/aarch64-sme-attrs.cpp +++ b/clang/test/CodeGen/AArch64/sme-intrinsics/aarch64-sme-attrs.cpp @@ -300,19 +300,19 @@ int test_variadic_template() __arm_inout("za") { preserves_za_decl); } -// CHECK: attributes #[[SM_ENABLED]] = { mustprogress noinline nounwind "aarch64_pstate_sm_enabled" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } +// CHECK: attributes #[[SM_ENABLED]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_pstate_sm_enabled" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } // CHECK: attributes #[[NORMAL_DECL]] = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } // CHECK: attributes #[[SM_ENABLED_DECL]] = { "aarch64_pstate_sm_enabled" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } -// CHECK: attributes #[[SM_COMPATIBLE]] = { mustprogress noinline nounwind "aarch64_pstate_sm_compatible" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } +// CHECK: attributes #[[SM_COMPATIBLE]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_pstate_sm_compatible" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } // CHECK: attributes #[[SM_COMPATIBLE_DECL]] = { "aarch64_pstate_sm_compatible" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } -// CHECK: attributes #[[SM_BODY]] = { mustprogress noinline nounwind "aarch64_pstate_sm_body" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } -// CHECK: attributes #[[ZA_SHARED]] = { mustprogress noinline nounwind "aarch64_inout_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } +// CHECK: attributes #[[SM_BODY]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_pstate_sm_body" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } +// CHECK: attributes #[[ZA_SHARED]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_inout_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } // CHECK: attributes #[[ZA_SHARED_DECL]] = { "aarch64_inout_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } -// CHECK: attributes #[[ZA_PRESERVED]] = { mustprogress noinline nounwind "aarch64_preserves_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } +// CHECK: attributes #[[ZA_PRESERVED]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_preserves_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } // CHECK: attributes #[[ZA_PRESERVED_DECL]] = { "aarch64_preserves_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } -// CHECK: attributes #[[ZA_NEW]] = { mustprogress noinline nounwind "aarch64_new_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } -// CHECK: attributes #[[ZA_AGNOSTIC]] = { mustprogress noinline nounwind "aarch6
[clang] [AArch64] Enable vscale_range with +sme (PR #124466)
llvmbot wrote: @llvm/pr-subscribers-backend-aarch64 Author: David Green (davemgreen) Changes If we have +sme but not +sve, we would not set vscale_range on functions. It should be valid to apply it with the same range with just +sme, which can help improve the performance of generated code. --- Full diff: https://github.com/llvm/llvm-project/pull/124466.diff 3 Files Affected: - (modified) clang/lib/Basic/Targets/AArch64.cpp (+1-1) - (modified) clang/test/CodeGen/AArch64/sme-intrinsics/aarch64-sme-attrs.cpp (+8-8) - (modified) clang/test/CodeGen/arm-sve-vector-bits-vscale-range.c (+1) ``diff diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index 0b899137bbb5c7..e9afe0fb4ee456 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -708,7 +708,7 @@ AArch64TargetInfo::getVScaleRange(const LangOptions &LangOpts) const { return std::pair( LangOpts.VScaleMin ? LangOpts.VScaleMin : 1, LangOpts.VScaleMax); - if (hasFeature("sve")) + if (hasFeature("sve") || hasFeature("sme")) return std::pair(1, 16); return std::nullopt; diff --git a/clang/test/CodeGen/AArch64/sme-intrinsics/aarch64-sme-attrs.cpp b/clang/test/CodeGen/AArch64/sme-intrinsics/aarch64-sme-attrs.cpp index 54762c8b414124..cabd9d01e46652 100644 --- a/clang/test/CodeGen/AArch64/sme-intrinsics/aarch64-sme-attrs.cpp +++ b/clang/test/CodeGen/AArch64/sme-intrinsics/aarch64-sme-attrs.cpp @@ -300,19 +300,19 @@ int test_variadic_template() __arm_inout("za") { preserves_za_decl); } -// CHECK: attributes #[[SM_ENABLED]] = { mustprogress noinline nounwind "aarch64_pstate_sm_enabled" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } +// CHECK: attributes #[[SM_ENABLED]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_pstate_sm_enabled" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } // CHECK: attributes #[[NORMAL_DECL]] = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } // CHECK: attributes #[[SM_ENABLED_DECL]] = { "aarch64_pstate_sm_enabled" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } -// CHECK: attributes #[[SM_COMPATIBLE]] = { mustprogress noinline nounwind "aarch64_pstate_sm_compatible" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } +// CHECK: attributes #[[SM_COMPATIBLE]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_pstate_sm_compatible" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } // CHECK: attributes #[[SM_COMPATIBLE_DECL]] = { "aarch64_pstate_sm_compatible" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } -// CHECK: attributes #[[SM_BODY]] = { mustprogress noinline nounwind "aarch64_pstate_sm_body" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } -// CHECK: attributes #[[ZA_SHARED]] = { mustprogress noinline nounwind "aarch64_inout_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } +// CHECK: attributes #[[SM_BODY]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_pstate_sm_body" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } +// CHECK: attributes #[[ZA_SHARED]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_inout_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } // CHECK: attributes #[[ZA_SHARED_DECL]] = { "aarch64_inout_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } -// CHECK: attributes #[[ZA_PRESERVED]] = { mustprogress noinline nounwind "aarch64_preserves_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } +// CHECK: attributes #[[ZA_PRESERVED]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_preserves_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } // CHECK: attributes #[[ZA_PRESERVED_DECL]] = { "aarch64_preserves_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } -// CHECK: attributes #[[ZA_NEW]] = { mustprogress noinline nounwind "aarch64_new_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } -// CHECK: attributes #[[ZA_AGNOSTIC]] = { mustprogress noinline nounwind "aarch64_za_state_agnostic" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } -// CHECK: attributes #[[NORMAL_DEF]] = { mustprogress noinline nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } +// CHECK:
[clang] [cindex] Add API to query the class methods of a type (PR #123539)
https://github.com/trelau updated https://github.com/llvm/llvm-project/pull/123539 >From bb0542e8f2ad50892ee9d2c1f76ec1def85c3e56 Mon Sep 17 00:00:00 2001 From: Trevor Laughlin Date: Sun, 19 Jan 2025 19:21:10 -0500 Subject: [PATCH] [cindex] Add API to query the class methods of a type --- clang/bindings/python/clang/cindex.py | 16 +++ .../bindings/python/tests/cindex/test_type.py | 18 + clang/docs/ReleaseNotes.rst | 4 +++ clang/include/clang-c/Index.h | 23 clang/tools/libclang/CIndexCXX.cpp| 27 +++ clang/tools/libclang/libclang.map | 1 + 6 files changed, 89 insertions(+) diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index 806e1b40f3c9e1..9e65ea2942d163 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -2710,6 +2710,21 @@ def visitor(base, children): conf.lib.clang_visitCXXBaseClasses(self, fields_visit_callback(visitor), bases) return iter(bases) +def get_methods(self): +"""Return an iterator for accessing the methods of this type.""" + +def visitor(method, children): +assert method != conf.lib.clang_getNullCursor() + +# Create reference to TU so it isn't GC'd before Cursor. +method._tu = self._tu +methods.append(method) +return 1 # continue + +methods: list[Cursor] = [] +conf.lib.clang_visitCXXMethods(self, fields_visit_callback(visitor), methods) +return iter(methods) + def get_exception_specification_kind(self): """ Return the kind of the exception specification; a value from @@ -4017,6 +4032,7 @@ def set_property(self, property, value): ), ("clang_visitChildren", [Cursor, cursor_visit_callback, py_object], c_uint), ("clang_visitCXXBaseClasses", [Type, fields_visit_callback, py_object], c_uint), +("clang_visitCXXMethods", [Type, fields_visit_callback, py_object], c_uint), ("clang_Cursor_getNumArguments", [Cursor], c_int), ("clang_Cursor_getArgument", [Cursor, c_uint], Cursor), ("clang_Cursor_getNumTemplateArguments", [Cursor], c_int), diff --git a/clang/bindings/python/tests/cindex/test_type.py b/clang/bindings/python/tests/cindex/test_type.py index 9bac33f3041f40..bc893d509524e0 100644 --- a/clang/bindings/python/tests/cindex/test_type.py +++ b/clang/bindings/python/tests/cindex/test_type.py @@ -559,3 +559,21 @@ class Template : public A, public B, virtual C { self.assertEqual(bases[1].get_base_offsetof(cursor_type_decl), 96) self.assertTrue(bases[2].is_virtual_base()) self.assertEqual(bases[2].get_base_offsetof(cursor_type_decl), 128) + +def test_class_methods(self): +source = """ +template +class Template { void Foo(); }; +typedef Template instance; +instance bar; +""" +tu = get_tu(source, lang="cpp", flags=["--target=x86_64-linux-gnu"]) +cursor = get_cursor(tu, "instance") +cursor_type = cursor.underlying_typedef_type +self.assertEqual(cursor.kind, CursorKind.TYPEDEF_DECL) +methods = list(cursor_type.get_methods()) +self.assertEqual(len(methods), 4) +self.assertEqual(methods[0].kind, CursorKind.CXX_METHOD) +self.assertEqual(methods[1].kind, CursorKind.CONSTRUCTOR) +self.assertEqual(methods[2].kind, CursorKind.CONSTRUCTOR) +self.assertEqual(methods[3].kind, CursorKind.CONSTRUCTOR) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index b02ac467cd3a22..dd9f722a6a08cb 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -1241,6 +1241,8 @@ libclang of a class. - Added ``clang_getOffsetOfBase``, which allows computing the offset of a base class in a class's layout. +- Added ``clang_visitCXXMethods``, which allows visiting the methods + of a class. Static Analyzer --- @@ -1394,6 +1396,8 @@ Python Binding Changes allows visiting the base classes of a class. - Added ``Cursor.get_base_offsetof``, a binding for ``clang_getOffsetOfBase``, which allows computing the offset of a base class in a class's layout. +- Added ``Type.get_methods``, a binding for ``clang_visitCXXMethods``, which + allows visiting the methods of a class. OpenMP Support -- diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index aac5d1fa8aa2e0..5d961ca0cdd7fc 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -6680,6 +6680,29 @@ CINDEX_LINKAGE unsigned clang_visitCXXBaseClasses(CXType T, CXFieldVisitor visitor, CXClientData client_data); +/** + * Visit the class methods of a type. + * + * This function visits all the methods
[clang] [AArch64] Enable vscale_range with +sme (PR #124466)
llvmbot wrote: @llvm/pr-subscribers-clang Author: David Green (davemgreen) Changes If we have +sme but not +sve, we would not set vscale_range on functions. It should be valid to apply it with the same range with just +sme, which can help improve the performance of generated code. --- Full diff: https://github.com/llvm/llvm-project/pull/124466.diff 3 Files Affected: - (modified) clang/lib/Basic/Targets/AArch64.cpp (+1-1) - (modified) clang/test/CodeGen/AArch64/sme-intrinsics/aarch64-sme-attrs.cpp (+8-8) - (modified) clang/test/CodeGen/arm-sve-vector-bits-vscale-range.c (+1) ``diff diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index 0b899137bbb5c7..e9afe0fb4ee456 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -708,7 +708,7 @@ AArch64TargetInfo::getVScaleRange(const LangOptions &LangOpts) const { return std::pair( LangOpts.VScaleMin ? LangOpts.VScaleMin : 1, LangOpts.VScaleMax); - if (hasFeature("sve")) + if (hasFeature("sve") || hasFeature("sme")) return std::pair(1, 16); return std::nullopt; diff --git a/clang/test/CodeGen/AArch64/sme-intrinsics/aarch64-sme-attrs.cpp b/clang/test/CodeGen/AArch64/sme-intrinsics/aarch64-sme-attrs.cpp index 54762c8b414124..cabd9d01e46652 100644 --- a/clang/test/CodeGen/AArch64/sme-intrinsics/aarch64-sme-attrs.cpp +++ b/clang/test/CodeGen/AArch64/sme-intrinsics/aarch64-sme-attrs.cpp @@ -300,19 +300,19 @@ int test_variadic_template() __arm_inout("za") { preserves_za_decl); } -// CHECK: attributes #[[SM_ENABLED]] = { mustprogress noinline nounwind "aarch64_pstate_sm_enabled" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } +// CHECK: attributes #[[SM_ENABLED]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_pstate_sm_enabled" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } // CHECK: attributes #[[NORMAL_DECL]] = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } // CHECK: attributes #[[SM_ENABLED_DECL]] = { "aarch64_pstate_sm_enabled" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } -// CHECK: attributes #[[SM_COMPATIBLE]] = { mustprogress noinline nounwind "aarch64_pstate_sm_compatible" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } +// CHECK: attributes #[[SM_COMPATIBLE]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_pstate_sm_compatible" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } // CHECK: attributes #[[SM_COMPATIBLE_DECL]] = { "aarch64_pstate_sm_compatible" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } -// CHECK: attributes #[[SM_BODY]] = { mustprogress noinline nounwind "aarch64_pstate_sm_body" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } -// CHECK: attributes #[[ZA_SHARED]] = { mustprogress noinline nounwind "aarch64_inout_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } +// CHECK: attributes #[[SM_BODY]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_pstate_sm_body" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } +// CHECK: attributes #[[ZA_SHARED]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_inout_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } // CHECK: attributes #[[ZA_SHARED_DECL]] = { "aarch64_inout_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } -// CHECK: attributes #[[ZA_PRESERVED]] = { mustprogress noinline nounwind "aarch64_preserves_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } +// CHECK: attributes #[[ZA_PRESERVED]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_preserves_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } // CHECK: attributes #[[ZA_PRESERVED_DECL]] = { "aarch64_preserves_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } -// CHECK: attributes #[[ZA_NEW]] = { mustprogress noinline nounwind "aarch64_new_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } -// CHECK: attributes #[[ZA_AGNOSTIC]] = { mustprogress noinline nounwind "aarch64_za_state_agnostic" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } -// CHECK: attributes #[[NORMAL_DEF]] = { mustprogress noinline nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" } +// CHECK: attributes
[clang] [PGO] Add a clang option -fprofile-continuous that enables PGO continuous mode (PR #124353)
@@ -1886,6 +1886,11 @@ def fprofile_update_EQ : Joined<["-"], "fprofile-update=">, Values<"atomic,prefer-atomic,single">, MetaVarName<"">, HelpText<"Set update method of profile counters">, MarshallingInfoFlag>; +def fprofile_continuous : Flag<["-"], "fprofile-continuous">, carlocab wrote: Mild suggestion: `-fprofile-continuously` reads a little better. But happy with the existing flag if you feel strongly about it. https://github.com/llvm/llvm-project/pull/124353 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
@@ -0,0 +1,626 @@ +#!/usr/bin/env python3 + +""" generate_unsupported_in_drivermode.py + +usage: python generate_unsupported_in_drivermode.py /Options.td [/llvm-tblgen] + +This script generates a Lit regression test file that validates that options +are only exposed to intended driver modes. + +The options and driver modes are parsed from Options.td, whose path should be +provided on the command line. See clang/include/clang/Driver/Options.td + +The path to the TableGen executable can optionally be provided. Otherwise, the +script will search for it. + +The primary maintenance task for this script would be updating the expected return message for a driver mode if +there are changes over time. See the instantiations of DriverController, specifically the check_string. + +Logic: +1) For each option, (records of class "Option"), and for each driver, (records of class "OptionVisibility") +a. if the option's "Visibility" field includes the driver flavour, skip processing this option for this driver +b. if the option is part of an option group, (the record has the "Group" property), + and the group's "Visibility" field includes the driver flavour, skip processing this option for this driver +c. otherwise this option is not supported by this driver flavour, and this pairing is saved for testing +2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to parse for expected output. Ex: "error: unknown argument" +""" + +import sys +import shutil +import os +import json +import subprocess +import math +from pathlib import Path + +LLVM_TABLEGEN = "llvm-tblgen" +LIT_TEST_PATH = "../test/Driver/unsupported_in_drivermode.c" +LIT_TEST_PATH_FLANG = "../test/Driver/flang/unsupported_in_flang.f90" +INCLUDE_PATH = "../../llvm/include" + +# Strings defined in Options.td for the various driver flavours. See "OptionVisibility" +VISIBILITY_CC1AS = "CC1AsOption" +VISIBILITY_CC1 = "CC1Option" +VISIBILITY_CL = "CLOption" +VISIBILITY_DXC = "DXCOption" +VISIBILITY_DEFAULT = "DefaultVis" +VISIBILITY_FC1 = "FC1Option" +VISIBILITY_FLANG = "FlangOption" + +# Strings used in the commands to be tested +CLANG = "clang" +CLANG_CL = f"{CLANG} --driver-mode=cl" +CLANG_DXC = f"{CLANG} --driver-mode=dxc" +FLANG = f"{CLANG} --driver-mode=flang" +CLANG_LIT = "%clang" +CLANG_CL_LIT = "%clang_cl" +CLANG_DXC_LIT = "%clang_dxc" +FLANG_LIT = f"%{FLANG}" +OPTION_HASH = "-###" +OPTION_X = "-x" +OPTION_WX = "/WX" +OPTION_CPP = "c++" +OPTION_C = "-c" +OPTION_CC1 = "-cc1" +OPTION_CC1AS = "-cc1as" +OPTION_FC1 = "-fc1" +OPTION_SLASH_C = "/c" +OPTION_T = "/T lib_6_7" +SLASH_SLASH = "// " +EXCLAMATION = "! " + +# Invalid usage of the driver options below causes unique output, so skip testing +exceptions_sequence = [ +"cc1", +"cc1as", +] + + +class DriverController: +"""Controller for data specific to each driver +shell_cmd_prefix: The beginning string of the command to be tested +lit_cmd_prefix: The beginning string of the Lit command +visibility_str: The corresponding visibility string from OptionVisibility in Options.td +shell_cmd_suffix: Strings near the end of the command to be tested +check_string: The string or regex to be sent to FileCheck +lit_cmd_end: String at the end of the Lit command + +supported_sequence: List of UnsupportedDriverOption objects for supported options +that are Kind KIND_JOINED*, as defined in Options.td +""" + +def __init__( +self, +shell_cmd_prefix="", +lit_cmd_prefix="", +visibility_str="", +shell_cmd_suffix="", +check_string="{{(unknown argument|n?N?o such file or directory)}}", +lit_cmd_end=" - < /dev/null 2>&1 | FileCheck -check-prefix=", +): +self.shell_cmd_prefix = shell_cmd_prefix +self.lit_cmd_prefix = lit_cmd_prefix +self.visibility_str = visibility_str +self.shell_cmd_suffix = shell_cmd_suffix +self.supported_sequence = [] +self.check_string = check_string +self.lit_cmd_end = lit_cmd_end + + +class UnsupportedDriverOption: +"""Defines an unsupported driver-option combination +driver: The driver string as defined by OptionVisibility in Options.td +option: The option object from Options.td +option_name: Corresponding string for an option. See "Name" for a given option in Options.td +prefix: String that precedes the option. Ex. "-" +is_error: Boolean indicating whether the corresponding command generates an error +""" + +def __init__(self, driver, option, option_name, prefix): +self.driver = driver +self.option = option +self.option_name = option_name +self.prefix = prefix +self.is_error = True + +# For sorting +def __len__(self): +return len(self.option_name) + + +def print_usage(): +"""Print valid usage of this script""" +sys.exit("usage: python " + sys.argv[0] + " /Options.td
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
@@ -0,0 +1,626 @@ +#!/usr/bin/env python3 + +""" generate_unsupported_in_drivermode.py + +usage: python generate_unsupported_in_drivermode.py /Options.td [/llvm-tblgen] + +This script generates a Lit regression test file that validates that options +are only exposed to intended driver modes. + +The options and driver modes are parsed from Options.td, whose path should be +provided on the command line. See clang/include/clang/Driver/Options.td + +The path to the TableGen executable can optionally be provided. Otherwise, the +script will search for it. + +The primary maintenance task for this script would be updating the expected return message for a driver mode if +there are changes over time. See the instantiations of DriverController, specifically the check_string. + +Logic: +1) For each option, (records of class "Option"), and for each driver, (records of class "OptionVisibility") +a. if the option's "Visibility" field includes the driver flavour, skip processing this option for this driver +b. if the option is part of an option group, (the record has the "Group" property), + and the group's "Visibility" field includes the driver flavour, skip processing this option for this driver +c. otherwise this option is not supported by this driver flavour, and this pairing is saved for testing +2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to parse for expected output. Ex: "error: unknown argument" +""" + +import sys +import shutil +import os +import json +import subprocess +import math +from pathlib import Path + +LLVM_TABLEGEN = "llvm-tblgen" +LIT_TEST_PATH = "../test/Driver/unsupported_in_drivermode.c" +LIT_TEST_PATH_FLANG = "../test/Driver/flang/unsupported_in_flang.f90" +INCLUDE_PATH = "../../llvm/include" + +# Strings defined in Options.td for the various driver flavours. See "OptionVisibility" +VISIBILITY_CC1AS = "CC1AsOption" +VISIBILITY_CC1 = "CC1Option" +VISIBILITY_CL = "CLOption" +VISIBILITY_DXC = "DXCOption" +VISIBILITY_DEFAULT = "DefaultVis" +VISIBILITY_FC1 = "FC1Option" +VISIBILITY_FLANG = "FlangOption" + +# Strings used in the commands to be tested +CLANG = "clang" +CLANG_CL = f"{CLANG} --driver-mode=cl" +CLANG_DXC = f"{CLANG} --driver-mode=dxc" +FLANG = f"{CLANG} --driver-mode=flang" +CLANG_LIT = "%clang" +CLANG_CL_LIT = "%clang_cl" +CLANG_DXC_LIT = "%clang_dxc" +FLANG_LIT = f"%{FLANG}" +OPTION_HASH = "-###" +OPTION_X = "-x" +OPTION_WX = "/WX" +OPTION_CPP = "c++" +OPTION_C = "-c" +OPTION_CC1 = "-cc1" +OPTION_CC1AS = "-cc1as" +OPTION_FC1 = "-fc1" +OPTION_SLASH_C = "/c" +OPTION_T = "/T lib_6_7" +SLASH_SLASH = "// " +EXCLAMATION = "! " + +# Invalid usage of the driver options below causes unique output, so skip testing +exceptions_sequence = [ +"cc1", +"cc1as", +] + + +class DriverController: +"""Controller for data specific to each driver +shell_cmd_prefix: The beginning string of the command to be tested +lit_cmd_prefix: The beginning string of the Lit command +visibility_str: The corresponding visibility string from OptionVisibility in Options.td +shell_cmd_suffix: Strings near the end of the command to be tested +check_string: The string or regex to be sent to FileCheck +lit_cmd_end: String at the end of the Lit command + +supported_sequence: List of UnsupportedDriverOption objects for supported options +that are Kind KIND_JOINED*, as defined in Options.td +""" + +def __init__( +self, +shell_cmd_prefix="", +lit_cmd_prefix="", +visibility_str="", +shell_cmd_suffix="", +check_string="{{(unknown argument|n?N?o such file or directory)}}", +lit_cmd_end=" - < /dev/null 2>&1 | FileCheck -check-prefix=", +): +self.shell_cmd_prefix = shell_cmd_prefix +self.lit_cmd_prefix = lit_cmd_prefix +self.visibility_str = visibility_str +self.shell_cmd_suffix = shell_cmd_suffix +self.supported_sequence = [] +self.check_string = check_string +self.lit_cmd_end = lit_cmd_end + + +class UnsupportedDriverOption: +"""Defines an unsupported driver-option combination +driver: The driver string as defined by OptionVisibility in Options.td +option: The option object from Options.td +option_name: Corresponding string for an option. See "Name" for a given option in Options.td +prefix: String that precedes the option. Ex. "-" +is_error: Boolean indicating whether the corresponding command generates an error +""" + +def __init__(self, driver, option, option_name, prefix): +self.driver = driver +self.option = option +self.option_name = option_name +self.prefix = prefix +self.is_error = True + +# For sorting +def __len__(self): +return len(self.option_name) + + +def print_usage(): +"""Print valid usage of this script""" +sys.exit("usage: python " + sys.argv[0] + " /Options.td
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
@@ -0,0 +1,626 @@ +#!/usr/bin/env python3 + +""" generate_unsupported_in_drivermode.py + +usage: python generate_unsupported_in_drivermode.py /Options.td [/llvm-tblgen] + +This script generates a Lit regression test file that validates that options +are only exposed to intended driver modes. + +The options and driver modes are parsed from Options.td, whose path should be +provided on the command line. See clang/include/clang/Driver/Options.td + +The path to the TableGen executable can optionally be provided. Otherwise, the +script will search for it. + +The primary maintenance task for this script would be updating the expected return message for a driver mode if +there are changes over time. See the instantiations of DriverController, specifically the check_string. + +Logic: +1) For each option, (records of class "Option"), and for each driver, (records of class "OptionVisibility") +a. if the option's "Visibility" field includes the driver flavour, skip processing this option for this driver +b. if the option is part of an option group, (the record has the "Group" property), + and the group's "Visibility" field includes the driver flavour, skip processing this option for this driver +c. otherwise this option is not supported by this driver flavour, and this pairing is saved for testing +2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to parse for expected output. Ex: "error: unknown argument" +""" + +import sys +import shutil +import os +import json +import subprocess +import math +from pathlib import Path + +LLVM_TABLEGEN = "llvm-tblgen" +LIT_TEST_PATH = "../test/Driver/unsupported_in_drivermode.c" +LIT_TEST_PATH_FLANG = "../test/Driver/flang/unsupported_in_flang.f90" +INCLUDE_PATH = "../../llvm/include" + +# Strings defined in Options.td for the various driver flavours. See "OptionVisibility" +VISIBILITY_CC1AS = "CC1AsOption" +VISIBILITY_CC1 = "CC1Option" +VISIBILITY_CL = "CLOption" +VISIBILITY_DXC = "DXCOption" +VISIBILITY_DEFAULT = "DefaultVis" +VISIBILITY_FC1 = "FC1Option" +VISIBILITY_FLANG = "FlangOption" + +# Strings used in the commands to be tested +CLANG = "clang" +CLANG_CL = f"{CLANG} --driver-mode=cl" +CLANG_DXC = f"{CLANG} --driver-mode=dxc" +FLANG = f"{CLANG} --driver-mode=flang" +CLANG_LIT = "%clang" +CLANG_CL_LIT = "%clang_cl" +CLANG_DXC_LIT = "%clang_dxc" +FLANG_LIT = f"%{FLANG}" +OPTION_HASH = "-###" +OPTION_X = "-x" +OPTION_WX = "/WX" +OPTION_CPP = "c++" +OPTION_C = "-c" +OPTION_CC1 = "-cc1" +OPTION_CC1AS = "-cc1as" +OPTION_FC1 = "-fc1" +OPTION_SLASH_C = "/c" +OPTION_T = "/T lib_6_7" +SLASH_SLASH = "// " +EXCLAMATION = "! " + +# Invalid usage of the driver options below causes unique output, so skip testing +exceptions_sequence = [ +"cc1", +"cc1as", +] + + +class DriverController: +"""Controller for data specific to each driver +shell_cmd_prefix: The beginning string of the command to be tested +lit_cmd_prefix: The beginning string of the Lit command +visibility_str: The corresponding visibility string from OptionVisibility in Options.td +shell_cmd_suffix: Strings near the end of the command to be tested +check_string: The string or regex to be sent to FileCheck +lit_cmd_end: String at the end of the Lit command + +supported_sequence: List of UnsupportedDriverOption objects for supported options +that are Kind KIND_JOINED*, as defined in Options.td +""" + +def __init__( +self, +shell_cmd_prefix="", +lit_cmd_prefix="", +visibility_str="", +shell_cmd_suffix="", +check_string="{{(unknown argument|n?N?o such file or directory)}}", +lit_cmd_end=" - < /dev/null 2>&1 | FileCheck -check-prefix=", +): +self.shell_cmd_prefix = shell_cmd_prefix +self.lit_cmd_prefix = lit_cmd_prefix +self.visibility_str = visibility_str +self.shell_cmd_suffix = shell_cmd_suffix +self.supported_sequence = [] +self.check_string = check_string +self.lit_cmd_end = lit_cmd_end + + +class UnsupportedDriverOption: +"""Defines an unsupported driver-option combination +driver: The driver string as defined by OptionVisibility in Options.td +option: The option object from Options.td +option_name: Corresponding string for an option. See "Name" for a given option in Options.td +prefix: String that precedes the option. Ex. "-" +is_error: Boolean indicating whether the corresponding command generates an error +""" + +def __init__(self, driver, option, option_name, prefix): +self.driver = driver +self.option = option +self.option_name = option_name +self.prefix = prefix +self.is_error = True + +# For sorting +def __len__(self): +return len(self.option_name) + + +def print_usage(): +"""Print valid usage of this script""" +sys.exit("usage: python " + sys.argv[0] + " /Options.td
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
@@ -0,0 +1,626 @@ +#!/usr/bin/env python3 + +""" generate_unsupported_in_drivermode.py + +usage: python generate_unsupported_in_drivermode.py /Options.td [/llvm-tblgen] + +This script generates a Lit regression test file that validates that options +are only exposed to intended driver modes. + +The options and driver modes are parsed from Options.td, whose path should be +provided on the command line. See clang/include/clang/Driver/Options.td + +The path to the TableGen executable can optionally be provided. Otherwise, the +script will search for it. + +The primary maintenance task for this script would be updating the expected return message for a driver mode if +there are changes over time. See the instantiations of DriverController, specifically the check_string. + +Logic: +1) For each option, (records of class "Option"), and for each driver, (records of class "OptionVisibility") +a. if the option's "Visibility" field includes the driver flavour, skip processing this option for this driver +b. if the option is part of an option group, (the record has the "Group" property), + and the group's "Visibility" field includes the driver flavour, skip processing this option for this driver +c. otherwise this option is not supported by this driver flavour, and this pairing is saved for testing +2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to parse for expected output. Ex: "error: unknown argument" +""" + +import sys +import shutil +import os +import json +import subprocess +import math +from pathlib import Path + +LLVM_TABLEGEN = "llvm-tblgen" +LIT_TEST_PATH = "../test/Driver/unsupported_in_drivermode.c" +LIT_TEST_PATH_FLANG = "../test/Driver/flang/unsupported_in_flang.f90" +INCLUDE_PATH = "../../llvm/include" + +# Strings defined in Options.td for the various driver flavours. See "OptionVisibility" +VISIBILITY_CC1AS = "CC1AsOption" +VISIBILITY_CC1 = "CC1Option" +VISIBILITY_CL = "CLOption" +VISIBILITY_DXC = "DXCOption" +VISIBILITY_DEFAULT = "DefaultVis" +VISIBILITY_FC1 = "FC1Option" +VISIBILITY_FLANG = "FlangOption" + +# Strings used in the commands to be tested +CLANG = "clang" +CLANG_CL = f"{CLANG} --driver-mode=cl" +CLANG_DXC = f"{CLANG} --driver-mode=dxc" +FLANG = f"{CLANG} --driver-mode=flang" +CLANG_LIT = "%clang" +CLANG_CL_LIT = "%clang_cl" +CLANG_DXC_LIT = "%clang_dxc" +FLANG_LIT = f"%{FLANG}" +OPTION_HASH = "-###" +OPTION_X = "-x" +OPTION_WX = "/WX" +OPTION_CPP = "c++" +OPTION_C = "-c" +OPTION_CC1 = "-cc1" +OPTION_CC1AS = "-cc1as" +OPTION_FC1 = "-fc1" +OPTION_SLASH_C = "/c" +OPTION_T = "/T lib_6_7" +SLASH_SLASH = "// " +EXCLAMATION = "! " + +# Invalid usage of the driver options below causes unique output, so skip testing +exceptions_sequence = [ +"cc1", +"cc1as", +] + + +class DriverController: +"""Controller for data specific to each driver +shell_cmd_prefix: The beginning string of the command to be tested +lit_cmd_prefix: The beginning string of the Lit command +visibility_str: The corresponding visibility string from OptionVisibility in Options.td +shell_cmd_suffix: Strings near the end of the command to be tested +check_string: The string or regex to be sent to FileCheck +lit_cmd_end: String at the end of the Lit command + +supported_sequence: List of UnsupportedDriverOption objects for supported options +that are Kind KIND_JOINED*, as defined in Options.td +""" + +def __init__( +self, +shell_cmd_prefix="", +lit_cmd_prefix="", +visibility_str="", +shell_cmd_suffix="", +check_string="{{(unknown argument|n?N?o such file or directory)}}", +lit_cmd_end=" - < /dev/null 2>&1 | FileCheck -check-prefix=", +): +self.shell_cmd_prefix = shell_cmd_prefix +self.lit_cmd_prefix = lit_cmd_prefix +self.visibility_str = visibility_str +self.shell_cmd_suffix = shell_cmd_suffix +self.supported_sequence = [] +self.check_string = check_string +self.lit_cmd_end = lit_cmd_end + + +class UnsupportedDriverOption: +"""Defines an unsupported driver-option combination +driver: The driver string as defined by OptionVisibility in Options.td +option: The option object from Options.td +option_name: Corresponding string for an option. See "Name" for a given option in Options.td +prefix: String that precedes the option. Ex. "-" +is_error: Boolean indicating whether the corresponding command generates an error +""" + +def __init__(self, driver, option, option_name, prefix): +self.driver = driver +self.option = option +self.option_name = option_name +self.prefix = prefix +self.is_error = True + +# For sorting +def __len__(self): +return len(self.option_name) + + +def print_usage(): +"""Print valid usage of this script""" +sys.exit("usage: python " + sys.argv[0] + " /Options.td